7 ms·
Building with Nix on Replit
- deleted 5y ago[deleted]
- johnnylambada 5y agoI tried to like nix. I spent many hours tweaking my macOS setup but now I’m back to brew. The nix language is just too foreign to my way of thinking. I love the concept behind it but the language is a huge barrier to entry to many people and I believe it will not gain nearly as much traction as it deserves until this is addressed.
- domenkozar 5y agoCould you say more what's foreign?
- johnnylambada 5y agoIts probably that I grew up with c like languages. When I try to read something like { pkgs }: { deps = [ pkgs.cowsay ]; } It’s meaningless to my brain.
- wereHamster 5y agoTranslating to modern JavaScript in three easy steps: { pkgs }: { deps = [ pkgs.cowsay ]; } ({ pkgs }): { deps = [ pkgs.cowsay ]; } ({ pkgs }) => { deps = [ pkgs.cowsay ]; } ({ pkgs }) => ({ deps = [ pkgs.cowsay ]; })
- johnnylambada 5y agoHelpful. There once was a command line tool that would turn a C declaration into english (like cdecl.org) I’d love to see something like that for the nix language (and kotlin too since I’m dreaming)
- TheDong 5y agoYour translation is incomplete. You're ending with: > ({ pkgs }) => ({ deps = [ pkgs.cowsay ]; }) But the syntax for declaring objects in javascript differs. It would be: ({ pkgs }) => ({ deps: pkgs.cowsay }) The fact that '{ x = 1; }' is declaring an object, identical to '{x: 1}' in javascript, is important. It's also worth pointing out that, while '{ pkgs }:' is idiomatic nix, idiomatically in javascript you'd probably just take multiple arguments (so '(pkgs) =>', not '({ pkgs }) =>' in js). The reason nix uses an object there is because a nix function only takes one argument, so there's a fairly common convention to make that argument an attr in order to simulate multiple arguments. That convention doesn't exist in quite the same way in js.
- ronenlh 5y agoYou forgot the array ({ pkgs }) => ({ deps: [pkgs.cowsay] }) I also translate all nix to JavaScript in my brain
- bspammer 5y agoTo put it in a C context: it’s a function with a single argument ‘pkgs’, which returns a struct with one field ‘deps’, which is an array of package structs.
- IshKebab 5y agoSo why did they chose such unconventional syntax? Just for the hell of it? There doesn't seem to be any advantage and it definitely puts a lot of people off.
- bspammer 5y agoThe syntax is not so unconventional compared to, say, modern javascript: ({ pkgs }) => { deps: [ pkgs.cowsay ] } or python: lambda pkgs: { deps: [pkgs.cowsay] } I guess really the question is why create a new language rather than using an existing one? The language needed to be functional, lazy, and good at managing packages, and not much else. I guess they felt that no existing language fits the bill (Haskell does I guess but it's got a lot of baggage). I can't claim to know much about its history.
- month13 5y agoYeah, it’s not as nice as macOS. There’s a ton of magic happening too, so I found it easy to get lost and not fully understand what was happening. I had tried to compile some software that linked against macOS SDKs, and did not realise that Nix essentially maintains it’s own version, and it was quite tricky to adapt to it or get back to using Xcode’s toolchain.
- amasad 5y agoWe’re trying to make it more accessible. Making a GUI or a no code interface is also on the table. But nonetheless we are seeing kids build nix environments. See this hashtag: https://replit.com/apps/nix https://replit.com/apps/nix
- MaxGabriel 5y agoAre there any good initiatives you think companies should fund to improve the accessibility?
- amasad 5y agoI think donating to the Nix foundation would be as good as any.
- rgoulter 5y agoI'm currently using NixOS. I jumped in some time after using Nix with macOS. I think following simple examples is straightforward. I think anyone who can install python and ruby with brew would be able to look at a replit.nix which uses python, and figure out how to change it to also install ruby. Even for just simple cases, I think Nix is compelling and worth looking into. "Nix is weird" becomes more of an issue for a long tail of edge cases, where a developer is likely to bump into one of these, and it won't be clear where in the documentation to go. -- With Nix being so weird, it both requires a familiarity with what you're doing in a standard-linux way, as well as familiarity with how things need to be done with Nix. e.g. the nginxModified in the OP makes use of overrideAttrs. (You'd need to know both that nginx can be configured like that, as well as how to configure with nix).
- ghuntley 5y agoSee https://nix.dev https://nix.dev for the best education resource. ps. to run nix on gitpod use https://github.com/gitpod-io/template-nix https://github.com/gitpod-io/template-nix pps. i'm doing a talk on the 6th on nix. Cya there? https://twitter.com/GeoffreyHuntley/status/1442475105427152899 https://twitter.com/GeoffreyHuntley/status/14424751054271528...
- amasad 5y agoAdded nix.dev to the list of resources in the post. Thanks.
- exdsq 5y agoI want to love Nix but I just can't get it. Worked with it for 14 months and found I struggled to make small changes meaning we had to depend on DevOps for things I could whip up in Docker and bash in minutes. I don't even really know why I struggle with it so much, but the startup I'm working for mentioned using it and I just shuddered thinking about it.
- bspammer 5y agoUnfortunately there’s no shortcut other than investing several hours reading tutorials and then repeatedly breaking stuff on your own machine until you start to understand. It’s worth it though. There’s something magical about having an entire machine configured declaratively.
- rgoulter 5y agoI think it's comparable to using Terraform. If you're only setting up one server in some cloud, then probably it's easier to just set that up through the admin dashboard compared to setting up Terraform. For such a limited usecase, the benefit of "infrastructure as code" is that at least what you've got is documented. But with using Terraform, all sorts of use cases are then enabled beyond what you'd want to manage manually. Using Nix instead of manually installing a bunch of stuff seems fine either way. But stuff like nix-shell paired with direnv seems pretty neat.
- bspammer 5y agoI actually really agree that Terraform is a good analogy - you're frontloading the effort in a way that hopefully will make things easier in the future. I use Terraform to manage my own personal AWS account. Recently I needed a Windows VM to run some random exe file. I could have created an EC2 instance adhoc through the web console but I did it through terraform instead. It probably took me about 30 minutes longer than it would have otherwise, but now I've got that terraform module ready to go if I ever need a windows instance again in the future. It's got a properly configured security group that only allows access from my VPN, and it outputs the IP and admin password automatically. I'll never have to solve that problem again (well, for a few years if we're being realistic).
- amasad 5y agoTo see and play with what people are building with Nix on Replit check out the #nix hashtag here: https://replit.com/apps/nix https://replit.com/apps/nix Users vary from teachers building environments for their classrooms, to hackers tinkering with emulators, to kids making old games like run online. We think we’re just scratching the surface with what we can do with Nix. It’s an outrageously underrated technology.
- ghuntley 5y ago> We think we’re just scratching the surface with what we can do with Nix. It’s an outrageously underrated technology. Super agree and watching from afar. Would love to see a blog post from replit "why not docker" (which is likely to go into how docker is the wrong sort of encapsulation, caching, source/binary substitution?)
- otabdeveloper4 5y agoDocker and Nix are orthogonal; Docker is mostly a tool for packaging things in a standard way, Nix is a way of specifying build instructions. But many people (ab)use Docker to solve the kinds of problems that Nix would have been better suited to solve.
- garethrowlands 5y agoSome people use Nix to build Docker images. They say it's very good for that.
- wlib 5y agoIt is, nix is more declarative than a dockerfile and can even optimize the layers based on the dependency graph. See https://grahamc.com/blog/nix-and-layered-docker-images https://grahamc.com/blog/nix-and-layered-docker-images for a good explanation and https://nixos.org/manual/nixpkgs/stable/#sec-pkgs-dockerTools https://nixos.org/manual/nixpkgs/stable/#sec-pkgs-dockerTool... for all of nix’s container related documentation.
- yjftsjthsd-h 5y ago> For reasons of security, this user does not have root privileges, and therefore cannot install packages using a traditional package manager like APT. Okay, I'm going to nitpick: Termux proves this isn't a requirement of apt, just most distros using it, and in any event fakeroot/proot would solve it if that was the goal. Of course, nix is a mostly good system with loads of other benefits; it's only that specific reason that feels weak.
- xcambar 5y agoKudos to the author(s), this article really is a nice written technical introduction, it has all the bases covered for such writing: * it explains in plain English what Nix is. * it provides additional resources * it has hands-on, guided, deliverable, tutorial.
- IshKebab 5y agoThis is a better introduction to Nix than the official one. One minor nit: > Functional languages are composed of functions that take some input and produce some output. Every time a function is executed with a given input, it will return the same output. Surely that is a property of pure languages, not functional ones. Maybe there are no pure imperative languages but I don't see why you couldn't have one. In fact it would probably make way more sense for Nix given how much easier imperative languages are to understand.
- avgcorrection 5y agoPure+imperative sounds useless. The imperative steps wouldn’t buy you anything. If you already can do let-bindings then you get nothing extra from imperative statements. Something more useful is an imperative language which only uses immutable values (strings, lists and so on).
- JonathanBeuys 5y ago> Functional languages are composed of functions that take some input and produce some output. Every time a function is executed with a given input, it will return the same output. I think this is not true. If it was this way, there would be no way to read data from an API. read('https://news.ycombinator.com https://news.ycombinator.com') will not return the same output everytime. And it would not be possible to keep track of anything. No counting, no transformation of data, nothing. Googling a bit indicates that people use a mental trick and define the state part of the input of the function. So in terms of getUrl() the current state of the internet is part of the input of the function. And when counting something, the function gets the old sum as the input and outputs the new sum which gets stored in a different place than the old sum so the old sum "did not change". I see a lot of overhead coming from these mental gymnastics with no benefit. Any short example that shows a benefit?
- piperswe 5y agoWith Nix, any network I/O is done through "fixed-output derivations." Fixed-output derivations define the expected hash of their outputs, so if they don't produce the expected output they throw an error.
- JonathanBeuys 5y agoThis seems like another mental trick to me. "Yeah, the function did not produce a different output. It just behaved different by throwing an exception." Still, some other code will read (or "interpret") this behavior and then behave accordingly etc. So what is won here?
- ghostwriter 5y agoNix doesn't allow for recovering from errors
- garethrowlands 5y agoIt's a good trick. The function didn't return a value, so its caller cannot interpret that value and cannot change it behaviour.
- tsuru 5y agoWas guix considered at all? If so, what were the negatives? I'm personally getting more enjoyment learning this style of environment and OS management with a more established language for the configuration.
- paulcarroty 5y agoIt sounds well but working crappy. Tried to install several nix packages using their tutorials - all failed.
- thrwwy389489 5y agoRemember that time Replit and amasad bullied their intern? I would never use nor recommend Replit as a result.