167 points · by Arkh4m · 5y ago · 153 comments
Second, to use this package manager, you first need to install direnv. How do you install it? with brew, a different package manager.
Third, you have to learn a new functional programming language. Right. Because normally to put together a toolbox, I often learn to speak a few phrases in Swahili first.
Fourth, finally, we get to install a simple Unix program, that any package manager could have provided.
For the fifth trick, freezing dependencies, you first have to have all the correct versions of all the dependencies to do what you want. How do you establish the right ones? Manually. Just like with any other package manager that builds apps against a specific tree of build deps. "Reproducibility!" Because no other package manager could possibly download the same tarballs and run the same commands. Must be all that functional programming magic.
And sixth, the idea that this will work forever. Right. Because any other distro and package manager could not possibly work again in the future, with a mirror of all the packages in a release. That's only for super cool futuristic package managers. No way to reproduce the same packages in the future with old package managers.
Look, Nixians, this is all old hat. Every decent package manager can do all these things, just in a less complicated way. Modern systems use containers, and they don't need Nix for that. Nix is basically just the new Gentoo: a distro for hobbyists who tell themselves they're advanced while all the professionals use something else.
Second. The reason I recommend direnv is because of ergonomics, so you don't have to remember to reload your shell. Most current version managers either do it themselves through shell hooks or ask you to install direnv. Point taken on using brew: I've changed it to use nix-env.
Third. Yep. Sort of like having to learn English before you can learn programming.
Fourth. As they say: start with the basics.
Fifth. No other package manager can freeze the complete dependency set you are using AND allow you to revert it exactly when things don't work. That's the power of declarative, reproducible builds: you try to update and it doesn't work? No problem, revert to the last working version and things are all good again.
Sixth. Ever tried updating a project using a Dockerfile that uses an old version of ubuntu? Then you can't find the packages anymore or no is building them anymore for the new version of Ubuntu and you have to pull random PPAs from the Internet to get things to work? In Nix, you can keep two pinned nixpkgs versions at the same time. In this way you can keep working on upgrading your project one working step at the time.
So yeah, it's not just cHeCKmATe FP-atheists sort of stuff.
Version-pinning in general is to prevent silent upgrades that break your builds. But you also don't want to version-pin everything, as you want security patches to get automatically applied with regularly-recurring builds. So in practice, you stick with a major branch of something, silently accept upgraded packages or minor version bumps, and have an automated system flag if you aren't running the latest security packages.
All of that works fine with Docker and Apt. More often than breakage due to silent upgrade is the security patch problem, where somebody pinned to a version 4 years ago and has never patched, and it's been so long that all the downstream effects of patching force you to do an entire lift-and-shift to new everything. Gradual continuous updates (stick to a major version, run tests) is the best middle ground. Modern projects with Docker containers have standardized their tagging around this.
I don't know if you realise that your post makes a poor case for that, and for imagined reproducibility of nix builds?
1. Direct quote from your post: "if you tried to follow this article step by step, you’ll have noticed that the versions of ruby and node you installed are probably slightly different from the ones above".
The "solution" for that is to dig through some commit hashes, and use those.
Commit hashes are not versions.
2. Your example points to a completely random version of a package
The previous issue already points to a random version, apparently, but this is further compounded by the fact that "ruby_2_6" and "nodejs-10_x" point to a random version that is available at the time.
To truly make the claim that nix allows reproducible builds, it needs to provide:
- a way to specify versions that don't depend on the commit hash of a "nixpck channel" whatever that is
- a way to actually properly pin package versions. Something that all package/dependency managers allow you to. If I want to pin ruby to exactly 2.6.7, for an actual reproducible build, what is nix' solution for that?
I don't see why a commit hash in insufficient to declare a package reproducible. For my system, I just use channels, but for anything mission critical, I think most people pin their commit hash of nixpkgs [0]. A pinned commit of nixpkgs will produce the exact same set of packages, forever.
> a way to actually properly pin package versions
The way you do this is to pull in a specific commit of nixpkgs (you can install packages from many versions of it at the same time, if you want). Alternatively, you can manually vendor the package file, which is what I usually do for one or two packages.
I found the nixpkgs version using this tool: https://lazamar.co.uk/nix-versions/?channel=nixpkgs-unstable...
Note that Ruby 2.6.8 fixes three severe vulnerabilities present in Ruby 2.6.7, while being backward compatible, so I don't see why you'd want that.
As a Gentoo user and someone who has tried and grokked Nix/Guix, this is not true at all. Gentoo is essentially a system for creating distributions, a meta-distro if you like. It just so happens to be something that appeals to someone like me to run at home because, well, why not? I know exactly what I need/want on my computer and this lets me build my own custom distro tailored for me.
Nix/Guix is something completely different. It addresses real problems that arise in a variety of places in an elegant way. Containers are another solution to some of these problems, but come with their own tradeoffs.
Your blanket statement about "professionals" makes no sense. I don't use Gentoo at work because it's not my job to maintain custom Linux systems or create distros. But guess what? Not everyone has the same job. You don't speak for all "professionals". I can distinctly remember around 2007 people saying this exact thing about git. I was told geeks were only learning it to make themselves feel clever and that SVN was fine. Well look how that turned out. I'm glad I ignored those people.
And if you want to do anything complicated, it's all get this hash, use this trick, this extra tool etc etc.
At which point, it's just easier to stick with what you have.
>> a distro for hobbyists who tell themselves they're advanced while all the professionals use something else.
yeah, getting the same vibe. Lots of hype not backed by any evidence.
For me, to start off, I'd like to see a real example, not some made up simple use case
How do I pin ruby version to 2.6.3 in Nix? This is given to me for free in other tools. As are reproducible builds because all modern package/dependency managers lock versions.
See that `rev` line in the sources.json? The whole build system is pinned by on git commit. If it builds today, it will build tomorrow. No matter what. That alone resolves a huge category of potential problems.
There's much, much more to it. Nix stores each package in its own path. [2] This makes it possible to install multiple versions of one application or library next to each other. With the power of direnv only the versions one needs are included.
[1] https://github.com/tikitu/jsmin/issues/33
[2] > ls /nix/store/ |head 000dm655691b5zis34klvhlil3hrv7j5-fftw-3.3.9.tar.gz.drv 005m4pqd29k976if66fpbggjsdxhchdg-python3.8-astroid-2.5.1.drv 007hqps3i495yjk223vhckin27vggk81-recode-3.7.8.tar.gz.drv 009815w1n26nl10rgffgahk7aka80p1m-nodejs-14.17.0 00a9nyyhwxisv4vc4rvwzp71nfip53x9-user-environment.drv 00m5h0pfzw2182qmyganlkaa9j4l2hps-vector-th-unbox-0.2.1.9.drv 010v6j5jjk2wpniznas31hbwvz1p1f5d-zapfding.r31835.tar.xz.drv 013sdi43bca33mnc3gn0v5r8lifrgcdj-hwdata-0.347.drv 01c3690lhmk0za0hnnh23n6mfgmiijpf-libdv-1.0.0.drv 01kc15hni6gff4z1p3y14v9f1395x2pf-python3.8-tap.py-3.0.drv
You can pin ruby to exact version you want with https://nixos.wiki/wiki/Overlays
I found the nixpkgs version using this tool: https://lazamar.co.uk/nix-versions/?channel=nixpkgs-unstable...
This is not true. The defining point about Nix is that it allows to define all dependencies explicitly. Every derivation in it is built inside of a sandbox with no access to network and restricted filesystem. This ensures that nothing is accidentally missed. Package management is just one of features.
> Second, to use this package manager, you first need to install direnv. How do you install it? with brew, a different package manager.
direnv is not needed to use Nix, it's just a nice add-on. It's like you don't need Ranger to navigate in a file system, but it is nice. Besides, you can install direnv through nix, I use it this way. Even nix is installed by itself as well.
> Third, you have to learn a new functional programming language. Right. Because normally to put together a toolbox, I often learn to speak a few phrases in Swahili first.
Well, yes you do, but language is actually quite simple it's the nixpkgs (repo containing all packages) that's quite complex. Nix's purely functional, lazily evaluated properties exactly fit as a language describing dependencies.
> Fourth, finally, we get to install a simple Unix program, that any package manager could have provided.
If you were trying to install a package, you don't need to learn anything, you just install it (for example to install ranger you just run nix-env -iA nixpkgs.ranger). Nix language is only needed if you want to create a new package.
> For the fifth trick, freezing dependencies, you first have to have all the correct versions of all the dependencies to do what you want. How do you establish the right ones? Manually. Just like with any other package manager that builds apps against a specific tree of build deps. "Reproducibility!" Because no other package manager could possibly download the same tarballs and run the same commands. Must be all that functional programming magic.
> And sixth, the idea that this will work forever. Right. Because any other distro and package manager could not possibly work again in the future, with a mirror of all the packages in a release. That's only for super cool futuristic package managers. No way to reproduce the same packages in the future with old package managers.
> Look, Nixians, this is all old hat. Every decent package manager can do all these things, just in a less complicated way. Modern systems use containers, and they don't need Nix for that. Nix is basically just the new Gentoo: a distro for hobbyists who tell themselves they're advanced while all the professionals use something else.
Nix delivers what docker promised and ultimately failed to deliver. Docker promised to reproduce developer's environment to production. What it did was to zip developer's computer and deploy it. When docker got adopted, relying on images was impractical, so for deployment Dockerfile was used, but that file is not much different than a shell script.
Nix instead describes the entire dependency tree down to libc. Because the starting state and all dependencies are known it can always create the same result, that's the biggest selling point of Nix to me.
Yeah, well, that does reproduce the developer's environment, doesn't it?
And you can do that with the package manager of any Linux distro today. It sounds like Nix's biggest selling point is it does something we can already do.
Other package managers typically handle the last one and completely ignore implicit dependencies.
To me it feels like what's left out here is the fact that you need the amount of dependencies that you have to be reasonable in the first place, otherwise no single piece of software is going to help you all that much.
For example, a new project that was created with "create-react-app" takes 181 MB of space on disk and has 35'894 files in it. That includes about 1467 modules, all for a relatively simple web application. It doesn't matter if you're using package.json/package.lock, or any other tool or solution out there - with that amount of dependencies you're simply not doing dependency "management" of any kind.
I'd argue that if you have >100 dependencies in your project, it's probably too big, unless you have a team that's dedicated to managing and auditing all of them. Of course, no one actually audits their dependencies when faced with such large numbers, and so what's left for most developers is to just trust what's out there.
Now auditing dependencies, knowing that the packages you depend on aren't malicious and have no known vulnerabilities... well, that's a whole separate problem. And yeah, we don't really have a solution to that right now. The best we can do, as you say, is keep the attack surface small.
But if we did try to solve the auditing problem, the solution would have to sit on top of nix or something like it. If you can't precisely specify a dependency graph and reliably install from that specification, it doesn't matter how good your auditing is or what sort of system of trust you can create. You don't know what you're getting anyway.
It's your job when downloading a package to use or when adding a dependency to make sure you trust the source - this is not a dependency management problem.
A good dependency manager should help you better filter trusted sources or at least have a good build file layout to make it obvious what the sources are but that's it.
I'm fine to depend on, say, JVM or Qt - large projects. Not with thousands of small packages developed by thousands of independent developers.
But here we are, some projects only give development instructions based on containers, others support only container based deployment. You need to go out of the way trying to convert dockerfiles into regular install/setup instructions.
Containers are great and all, they solve many problems but they're not the only solution and theyre definitely not the best solution to every problem.
There a large number of developers around now who've never done traditional (RPM, DEB, SysV) packaging and don't understand it. So while the large distros like Redhat and Debian push on with it, the development community only sees Dockerfiles, Snaps, Flatpaks etc.
I'm one of these developers (at least as far as my day job is concerned) and the only methods of delivery in a professional context that i've seen have been:
- delivering .jar or .war application files (Java), mostly through FTP or even e-mail
- delivering other files, like documentation etc., mostly through FTP or even e-mail
- using containers and pushing images to registries (mostly due to my initiative)
This is across ~5 years of software development and while looking at projects from multiple companies in my country - not once have i seen a DEB or RPM package repository be used. To me, it seems like previously people opted for the simplest solution in their eyes, which was just shuffling a bunch of files around through FTP, i guess since that doesn't lock you down to using a particular distro or even OS.However, streamlining that process on our end and eventually migrating over to containers, to where both the CI and CD are automated (or at least based on a manually invoked pipeline, when we're sure about making a release) seemed to be a no-brainer. Suddenly delivering software isn't something that takes an hour - even if needless cruft (making Jira issues manually etc.) is still there, any automation and getting rid of the human factor makes things safer and easier.
That said, it surprises me that previously no one bothered to set up their own DEB or RPM repositories, since then the clients could use the package management solutions that they're already familiar with. Any idea what are some of the reasons for it? Why doesn't everyone just make it so that their software can be installed and updated through apt/yum/...?
A reflexive, nearly irrational fear of ever, ever installing software outside of the official repositories. Search around for "Frankendebian" and you'll find a lot of people who simply refuse to discuss, let alone support, any individual who has the temerity to actually want to use their computer to run software instead of to simply maintain a pristine operating system.
In other words, the culture treats third party repositories as a pejorative.
I've been writing normal Dockerfiles at work recently and the whole toolchain is annoying on multiple fronts; I'd love to jump to Nix instead, except it's really hard to convince other people to learn non-trivial technology that's off the beaten path :(.
Using nix for building docker images [1] is brilliant, especially when combined with flakes. You don't need messy shell scripts to set up the environment and can get 100% reproducibility.
You just build a regular Nix derivation (aka package) with the software you need and then just specify that in your image.
It does take some work to get the image size down though.
I'll also mention Nixery [2], which is a Docker registry that automatically builds images based on Nix.
[1] https://nix.dev/tutorials/building-and-running-docker-images
Don't get me wrong, I do like nix ;-)
I doubt anyone behind Nix is writing patches for every single application that exists, and every version of every application, in order to achieve this. The only other way to do it is by re-building all of the deps and installing them in an environment specific to an application (what containers do), and then having an interface to be able to choose what versions of what environments to combine with which applications in what ways. You can't even create a Bash one-liner using two different apps/environments and ensure it'll work, unless you explicitly define what versions of the shell commands you're going to use together. It's impossible to automate. Hence "regular" distros with specific package trees, and containers to provide the interface to mix application/environment pairs.
There is no better solution, because all software development itself is inherently flawed. It's all 1970s programming: a single system with a single set of dependencies per application (both build-time & run-time). There is no solution to that problem other than to reinvent how software works so that versions are explicit in all code execution on a system. An application would have to request code execution with a specific version, and the system would have to figure out how to provide that version of that code at run time.
Nix installs everything that it manages (libraries, applications, even managed conf files) under a path that is derived from its exact build description (it's a hash plus some extra stuff to help humans identify what the component is by inspection). This allows, e.g., two different versions of Firefox or two different versions of zlib to exist on the system at the same time. Because the exact build description for the application refers to the exact build description for its dependences, there's a certain Merkle Tree like sense to it where if you were to e.g. rebuild Firefox against a different version of zlib, your resulting Firefox build would have a new build description hash and thus a new path.
An example of what an executable path might look like is: /nix/store/v5sv61sszx301i0x6xysaqzla09nksnd-hello-2.10/bin/hello
Stuff like autotools can actually generally support all of this without patching. In the case that the user wants to run a binary built for a non-nix system outside of a container on a nix system, binary patching does become necessary, in the form of appending to the RPATH of the executable. Nix does provide tools to eliminate as much pain as possible from this process.
It is worth noting that you can still only have one version of a program on your PATH with the canonical name at once.
As far as programs invoking each other with exec: that establishes no requirement at all that the invoked program be using the same versions of libraries as the invoking program. Programs packaged with nix sometimes "purely" refer to each other by their full paths. Other times, they discover each other "impurely" by just searching the PATH.
Sure you can. It's what version numbers in library file names are for. Works for executable names, too. Until Python 2.7 died, you commonly had 2.7 and 3.x installed at the same time.
But maybe you meant something different?
First, install python 2 and python 3. Next, install a script that calls "#!/usr/bin/python". How do you make the script work, without modifying the script, so that it will work with the specific version of Python it was designed against? You can't. You have to either modify the script to point at the specific executable it was designed for, or you have to modify the environment to point "/usr/bin/python" at either python2 or python3.
The former, "modifying the script", is recompiling all applications to point all of the executables they run at a custom executable, like "/run/app/v2/bin/app".
The latter, "changing the environment", requires that you specify the environment before you run the script (". /etc/python2.env ; /some/script.py"). But then you have to know that, right now, you want to run the script against Python 2. What if you install an upgraded version of the script that's built against Python 3? How do you know which script to run when? You have to have an interface and pick which one to use each time you run it. And every application that runs that script.
You can, of course, install two versions of your script, and rename the scripts, so that you know script2.py runs against python2 and script3.py runs against python3. But what if you have another program that needs to call the script? How does it know which of these 2 custom names to run? Now you'll have to compile a new custom package for this new program, and rename it too, and hard-code that one to call the specific new custom script name that targets the specific Python version.
And on, and on, and on, you will need to have duplicate packages for every possible dependency graph that could possibly exist of different versions of different programs. You would end up with 16,000 packages of this python script, each with a custom name and custom paths. Because some combination of dependent packages could lead to a recursive bug where the wrong app eventually calls the wrong script.
And it also requires patching literally every single application that is ever packaged by Nix to be able to rename applications and libraries. Every C program that ever calls "wc" needs to be patched to run "wc" version 2.0.0, "wc" version 2.0.1, "wc" version 3.0.0, etc, for every version of wc that may exist, and for every version of wc that may call a different program which also has multiple versions.
This is why the problem is unsolvable with any tooling whatsoever. There is no way to automatically determine the correct dependencies without modifying and packaging every application for every dependency tree that could possibly exist. The only solution is what containers give you: an interface that forces you to pick a version of an application with one dependency tree, and lets you figure out how to combine them (how to run containers together).
The only way to solve it without either 16,000 variants of one package, or an interface to pick environments at exec time, is to fundamentally change how software is designed and run today.
Interesting viewpoint! What are your arguments for this being a better solution than containerization?
- Nix packages can compose in arbitrary ways, containers can't
- Nix can get much more consistent and granular caching
- once an image is built it's reproducible, but the Dockerfile to run it probably isn't—unless it was written very, very carefully to pin everything—so what happens if you need to update one or two packages in an image?
- not 100% sure here, but it seems that lightweight sandboxing like Nix shells or virtualenvs are a lot more convenient for local development and tooling integration
That said, containers might make more sense for, say, deploying and sandboxing services—that's just a different problem from reproducibly managing dependencies and development environments. Nix can build container images, which lets you get the best of both worlds.
But gradually over time as its usage increase and it's extended by more and more even larger applications -- your app will turn into part of the OS. Containerizing your app doesn't help in this case.
Imagine how many services from the OS you are using. Next imagine each one running in a different container and you have to build your app using 100s such containers.
If we question our assumptions, the first question is: Why do we need multiple Ruby versions at all? Why isn't the latest version of Ruby sufficient? Well, obviously, Ruby's behavior has changed over time. But why isn't it backward-compatible? Why can't I just run Ruby 3.0 with a flag that tells it to emulate Ruby 2.6? Or 1.8 for that matter?
Okay another one. "Nokogiri" is the Ruby gem (library) for parsing XML (including HTML). You always need to remember to install libxml when you install it. Why? Why doesn't Nokogiri include an XML parser? Because it would be slow? You can include a native binary in the gem which does the hard computations. Will that work on random new architectures like M1? No? But you can fall back to a Ruby implementation and show a warning message. Also, what if I just need some quick XML parsing and don't care if the parsing is 1000x slower? Can I just get Nokogiri with the Ruby-implemented parser? No? Why not?
Then every single Ruby gem out there starts using newer Ruby features and thus, you must update your Ruby version. Why can't library authors gracefully handle older versions of Ruby?
I imagine variations of the above apply to nokogiri and some amount of Ruby core developers.
Python was saved, basically, by it becoming _the_ language for data science in the same time frame. But, this could have very well turned into a Perl 6-style fiasco.
From https://nokogiri.org
> These dependencies are met by default by Nokogiri's packaged versions of the libxml2 and libxslt source code, but a configuration option --use-system-libraries is provided to allow specification of alternative library locations.
Some authors work hard to have their tools do the right thing and consistently.
I suspect it would be a nightmare - it's not just small parts of the code, it would be other parts of the code that depend on it.
Take for instance Python 2 & Python 3's approach to if ("hello" > "goodbye") - in Python 2 that would be False and in Python 3 that would be TypeError. So if you are running Python 3 with a Python 2.7 flag, how should Python's internal modules that are written in Python 3 handle this? Do all Python's internal modules need to work on every legacy version of Python and load the correct version, or does the interpreter need to somehow load up instructions for both and parse them together? Then there is the whole problem about libraries - are these allowed to selectively choose which version of python they run on?
This is of course only one small example of the complexity - If it was easy to make these things backwards compatible it would be great, but I would expect the cost for implementing full backwards compatibility to be high and the language authors are probably motivated to make people move towards the latest versions.
If the software has been changed so much you cannot be backwards compatible anymore, name it something else and avoid the conflict and confusion.
Promptly ignored by most people, all while doubling maintenance efforts.
It's a trade-off without an easy answer.
Yeah, a ruby -2.4 switch would be nice but then every gem should pick its dependencies from back at the 2.4 time. Some could be dead by now. Actually those old projects usually get updated when the OS reaches end of life and they can't install the software on the new OS.
So economical and people reasons, not technical ones.
It is, mostly. 1.8->1.9 was famously a big change, but breaking changes since have been comparatively minor.
IMX the most common cause for gem breakage is simply rot - old gem, maintainer lost interest, a tiny change required (often due to an open-ended dependency on another gem) but there's no one to do it. Unfortunately, adopting an abandoned gem is non-trivial if the original maintainer doesn't respond, and a lot of gems were written in the Rails goldrush but have fallen into abeyance since.
My understanding is that Perl 5 supports this, for any version of Perl released in the 1994-2021 range, but in large part because it hasn't had drastic changes in that time period.
From what I understand this would require an update to the Nix version that supports it... but that also potentially means bumping other environmental versions as well, which might not be desired. But I suppose this would amount to the user arranging the structure of their filesystem correctly so its one "system" per dir/folder... Or is there a better way to cater to this? And I suppose this still means that the node modules, gems, etc that are being used then anyway also need to be updated after this accordingly.
From my limited understanding of Nix, it seems interesting, and the article was actually useful to me. But I cant seem to shake the feeling that this is another packaging abstraction like others before it, and while it seems like a better variant, its not much different to having X, Y and Z listed as requirements and then letting the dev go off and install such dependencies on their system, in the way that they best know how. Juniors or those new to a specific environment might not know the ecosystem so well so as to know to use rbenv or nvm or whatever, but I'm not sure how Nix solves this issue differently than one of the specific tools its replacing.
Theres clearly more to Nix than just setting up language environments, which I'm guessing is where its usefuleness really kicks in. But purely for lang env set up, I'm not sure I see a point over other tooling...
Nix supports building packages from multiple package sources. e.g. maybe you want an old version of some package which is only available in an older release of nixpkgs. It would be possible to use the older nixpkgs release to install that old package, and a newer nixpkgs release for the others. -- You even don't have to use the main nixpkgs repository.
> But I suppose this would amount to the user arranging the structure of their filesystem correctly so its one "system" per dir/folder.
Nix handles its filesystem arrangement for all of the "multiple different versions of some package" already. That's part of Nix's value proposition.
This also allows being able have packages available in your shell without having to 'pollute' the rest of the system is a neat dynamic, particularly with direnv.
> Theres clearly more to Nix than just setting up language environments, which I'm guessing is where its usefuleness really kicks in.
Depends how often you (want to) jump into fresh environments, but e.g. Nix allows being able to have a consistent set of programs installed quite easily.
Second way is to override[1], in documentation they are showing how to change compilation parameters, but you can also use this to change version of dependencies or source tarball for the package. As you use Nix you will eventually need to do it as sometimes package was not updated, or perhaps you need to use older version, or enable compilation option.
Third way is to use overlay[2]. In previous way an existing package was modified. Overlay allows to completely replace or add a new one.
For example there is a tool called poetry2nix[3], which on the fly translates python poetry lock file to Nix so nix can build them. Nixpkgs includes it and generally is frequently updated, but maybe there was a fix yesterday that hadn't made it there yet and it fixes an important bug. You can fetch that repo independently and attach it to nixpkgs (or you can use it directly).
Nix also has upcoming feature flakes which to my understanding takes this to a new level. So you can easily compose multiple repos like this in your application.
> Theres clearly more to Nix than just setting up language environments, which I'm guessing is where its usefuleness really kicks in. But purely for lang env set up, I'm not sure I see a point over other tooling...
I use it this way and the killer feature for myself is that for a project all I need to have installed is Nix and I can have exact environment the dev used.
It's not mentioned often, but I think a demo of it would be the repo for Nix program[4]. Typically when you want to compile some open source program, after you check out the repo, a hunt starts for the building tools and libraries needed. With nix you just issue build command or enter build shell[5] and things just work with no errors (or at least I did not get them when trying it a while ago. Everything worked on first try).
[1] https://nixos.org/manual/nixpkgs/stable/#chap-overrides
[2] https://nixos.org/manual/nixpkgs/stable/#chap-overlays
[3] https://github.com/nix-community/poetry2nix
[4] https://github.com/nixos/nix
[5] https://hydra.nixos.org/build/153568733/download/1/manual/co...
Nix is the basis of an OS distro: NixOS.
This article is just re-articulating the idea that {the/an} OS distro should be managing this stuff, and not some fledgling language-specific programs (that go behind its back, and do a half-baked job by not controlling the packages external to their language ghetto).
For me, the version manager that provides the nicest experience cross-platform is Cargo from Rust.
It can specify and pin specific versions. It is super easy to give to a fellow developer and have them reproduce the build. In addition, because Rust is suitable for low-level, high performance work, many times all the libraries you actually need are written in Rust and everything works very seemlessly (for example, there is no need to have libxml like the Ruby xml library needed, because you can probably write an XML parser in Rust that will be on par or better performance wise with libxml).
Yes, if all of your dependencies are written in a single language, you can use the language-specific version manager. TFA was pointing out a solution that work across different languages.
Most single language package managers are cross platform, and many single platform managers are cross language.
In conda, packages are installed into “environments” which are just folders like Python’s venv except language agnostic so you can install specific OpenSSL/Clang/GCC/libWhatever versions and have one environment per project you work on. It’s also the only package manager I’m aware of that can provide a good experience across Windows/Linux/macOS for x86_64/arm64/ppc64le.
One issue with conda is that the ecosystem of tooling is a little fragmented. The classic “conda” package has performance issues but there is a second implementation “mamba” which fixes this at the cost of minor changes in behaviour and attempts to merge mamba into conda seem to have stalled.
If you want to try it out Id recommend using the “Mambaforge” distribution and using “mamba” for everything except “conda activate” (which is actually a shell function).
In this post:
--- start quote ---
How about a different version of Ruby or Node? Let’s say that our project depends on Ruby 2.6 and Node 10. We can go and search for those specific versions
--- end quote ---
So, to begin with, we still need a "version manager", because we want specific package versions. But look at how this is implemented in nix:
let
pkgs = import <nixpkgs> { };
in
pkgs.mkShell {
buildInputs = [
pkgs.hello
pkgs.ruby_2_6
pkgs.nodejs-10_x
];
}
Why? Because unlike every sane package/dependency manager where you specify a package and a version, nix pretends each version is a separate package.And these packages aren't even correct. If you do go and search for ruby, for example [1], you get the following:
ruby Version: 2.7.4
ruby_3_0 Version: 3.0.2
ruby_2_6 Version: 2.6.8
This... This is laughable. How do I install ruby 2.6.8? Oh, there's no ruby_2_6_8, because of course there isn't. And this could be difference between a secure system and all your base are belong to us.And they call this reproducible builds?
And that's before getting into the ridiculous
--- start quote ---
All the software that we installed depends on the specific version of the nixpkgs channel that we installed on our system [whose only version is a commit hash in a git repo]
--- end quote ---
So you need an extra tool [2] for, quote, "painless dependencies for Nix projects."
Yes, sure. I'm definitely ditching my version managers in favor of this tool, that hasn't solved these issues in 18 years of its existence.
[1] https://search.nixos.org/packages?channel=21.05&from=0&size=...
re: ruby version In ubuntu I can only install ruby2.7 and I don't which minor version. [1] I would need to use rvm anyway. It's the same with nix. What is possible is to pin the version you need by specifying the commit. [2] shows the diff of the commit that moved ruby_2_7 from 2.7.3 to 2.7.4.
Say for example ruby 2.7.4 has a regression and the project needs to stay on 2.7.3. The revision has for 2.7.3 is used.
[1] > apt search ruby |egrep "^ruby2|^ruby3"
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
ruby2.7/hirsute-updates,hirsute-security 2.7.2-4ubuntu1.2 amd64 ruby2.7-dev/hirsute-updates,hirsute-security 2.7.2-4ubuntu1.2 amd64 ruby2.7-doc/hirsute-updates,hirsute-updates,hirsute-security,hirsute-security 2.7.2-4ubuntu1.2 all
[2] https://github.com/NixOS/nixpkgs/commit/5f9f17cc11caa07e4a9f...
I hoped you would tell me how to pin a specific version in nix, and you didn't. So far, I've asked this question at least three times. This question is either avoided or ignored. Ah yes. There's one "solution" with overlays which is neither maintainable nor scalable.
> ruby version In ubuntu
Is nix ubuntu?
> What is possible is to pin the version you need by specifying the commit.
Commit hashes are not versions
> I would need to use rvm anyway. It's the same with nix
We keep hearing the claim that nix is about builds. Builds often need their dependencies pinned to specific versions. If I still need to use rvm with nix, what's the point?
This is especially funny in the context: we're in the comment section to a post claiming that we should ditch our "version managers" while providing an alternative that, so far, looks to be significantly worse at what it claims to do.
Though there is a wealth of plugins, what's nice is that it's trivial to write your plugin. So if something doesn't exist yet, or you have some internal tool you need to version, it takes less than an hour to write a plugin.
Is there really a difference from the Docker example given (“your Ubuntu version is EOL”) though? Any of your language or tools can be EOL’ed even if installed via nix, and you have the exact same problem in your hands.
When that wasn't doable, I could google the name of the .tgz file, download a couple and find the one with the matching hash, drop the .tgz inside the directory and change the source to a relative path. Actually I do this even in the "release -> archive" case because "Move a URL once, shame on you. Move it twice, shame on me."
[edit]
If you really don't want to change the .nix expression, you can manually add the file to the cache, and things will Just Work.
According to Repology[1], it's got more packaged projects than any other package repository, and more packages that are up to date than any other repository. It's also pretty on top of CVEs, with only 0.38% of packages having potential vulnerabilities.
Also check out Repology's size/freshness graph[2]
[1] https://repology.org [2] https://repology.org/repositories/graphs
It gets really complicated really fast, and things that "just work" with other packages managers and projects, because they are opinionated and linux-y, most of the time don't work well with Nix or have to be shoehorned into it.
It always feels like you're fighting against everything to get things into Nix that just weren't meant to be.
Well, you can disable sandboxing if you want, although it's not recommended. This lets you run a package manager that requires networking in a derivation.
Don't you do that in Docker? I've read the sentence about Ubuntu EOL but don't really understand.
[1] https://nixos.wiki/wiki/Flakes [2] https://nixos.org/manual/nix/unstable/command-ref/new-cli/ni...
But the difference is, as you mentioned, flakes are integrated within Nix, and provide better ergonomics.
But what do they mean with “works forever”? What if the Git repo or Web server of the project is gone in several years? How do you reproduce it? Does niv include a local source code mirror?
For Docker, you just call a Nix function and specify what programs to include (both implicitly and explicitly via use) and Nix automatically includes the transitive closure of what you need
This is one of the main goals behind https://wapm.io :)
Very highly recommended. It's fast, safe, and effective. Much, much better than the various nvm/rvm/rbenv/etc that came before it, and it takes no effort to integrate.