357 points · by ingve · 10y ago · 204 comments
Then someone handed me a docker image saying, "I got this working on my laptop, deploy this. Isn't this great!". I had no idea how they arrived at that configuration. If something happened to them or that image, I wouldn't have known how to reproduce that "working state".
So I am happy to see Nix / Guix become popular. It is what I imagined package management to be.
Before that we just used rpm and deb packages. For all the hate they get, they are actually well thought out, tested, stable format. With {pre/post}-{install/uninstall} script support, dependency resolution and so on.
But Nix / Guix is a qualitatively different things. Hope it becomes popular.
None of which is to detract from Nix. Nix+Docker is a powerful combination. It takes Docker's declarative nature all the way down to the compiler used to build the bits placed in the container.
Finally someone understands what really annoys me when I say that docker isn't 100% reproducible if you aren't using version pinning or something similar.
If you have 2 developers, and one of them does a build the next day, you could have them with two different versions of a package when the version went up.
Ideally, I want _both_ of them: tagged Docker images being sent between environments (with `docker run -e SOME_ENV=testing imagename` for changing the internal config), but reproducible builds in my Dockerfile. I wonder if Nix can be used to achieve that last part?
Copying a comment I left on that blog post:
---
Q: "What does building a a Docker image using Nix give you over creating a regular Dockerfile to build a Docker image?"
A:
* Better abstraction (e.g. the example of a function that produces docker images)
* The Hydra build/CI server obviates the need for paying for (or administering a self hosted) docker registry, and avoids the imperative push and pull model. Because a docker image is just another Nix package, you get distributed building, caching and signing for free.
* Because Nix caches intermediate packages builds, building a Docker image via Nix will likely be faster than letting Docker do it.
* Determinism. With Docker, you're not guaranteed that you'll build the same image across two machines (imagine the state of package repositories changing -- it's trivial to find different versions of packages across two builds of the same Dockerfile). With Nix, you're guaranteed that you have the same determinism that any other Nix package has (e.g. everything builds in a chroot without network access (unless you provide a hash of the result, for e.g. tarball downloads))
---
IMO, NixOS almost subsumes Docker. Where Docker gives you a way to guarantee that the contents of an image will be the same across two machines, it does little to ensure that building that image from a given Dockerfile is a deterministic. One of Docker's neat tricks is using layers to try to save on disk util -- but even then, Nix beats Docker; if you start two different containers using Nix packages, the common packages are shared across both containers, whereas two different Docker images with an uncommon base would not share the common files.
Docker mostly looks like someone set out to answer two questions:
1. How can we work around all of the problems inherent in conventional package management so we can have a smidgen of determinism?
2. How can we have a relatively nice/cohesive UI around launching/inspecting containers and managing networking/bind-mounts?
#1 can be side-stepped entirely with a package manager that doesn't cause all of those problems in the first place (Nix/Guix).
#2 is still quite useful, but would have been better served as layering on top of something like Nix or Guix (not that I really approve of the "wannabe systemd" daemon approach that Docker employs (all while being, ironically, rather difficult to use with systemd: https://lwn.net/Articles/676831/ )).
Edit: grammar
Are you screwed if you lose a working .git project, or its maintainer? Well, yeah. But we don't actively worry about that happening all that much because we routinely take precautions like distributing it across developer's machines and servers.
Maybe a commit does break, but that's why we didn't just overwrite the previous image.
But also:
> I only know of a single time when it's valuable to
> "commit" a new image (recovering logs from a stopped
> container)
Not everything's open source.>Not everything's open source.
I don't know what that means. Whether the source is closed or not has zero impact on the use-cases I'm discussing for Docker. Even if the source of the base layer isn't available, it doesn't stop you from using that base layer in a new Dockerfile, at all.
From what I can see, there are two philosophically pure approaches to software packaging. Either we can build everything from source, so that we have reproducibility (see e.g. emerge for a practical system, although it is still not bit-for-bit reproducible) or else we can ship everything as a blob so we have total consistency (e.g. Docker, Go).
The other approaches, apt and nix, seem to me to be compromise positions. They may even be practical or useful compromises. But they are ultimately about the degree to which we allow binary blobs, not whether we do.
But it seems to me that once you have accepted installing binaries via apt then installing them from Docker is a question of degree, not of kind. It seems very hard to me to argue that distributing binaries via Docker is really worse than via nix.
Nix is really both of these combined, and is not like apt/dpkg in how it separates source and binary packages.
A Nix package is really instructions (including all compiler flags) of how to build something from source [1] and nothing more. Due to being pure functions, given the binary inputs (e.g. a zlib dependency previously built) and the instructions, any two people will always get the same binary output upon executing those instructions [2].
Furthermore, without executing the instructions, I can generate the unique identifier of the resulting binary package by hashing the inputs and the instructions. This unique identifier can be used to determine if the package already exists locally in /nix/store, and optionally be used to check if some trusted binary cache (such as Nix's binary cache) already has the binary package.
There is no binary package in the sense that apt/dpkg have source packages and many derived binary packages which are installed without need of the source package.
For example (contrived and simplified):
gcc-uniqueGccHash = bootstrappingProblem()
libc-uniqueLibcHash = buildLibc(gcc-uniqueGccHash)
zlib-uniqueZlibHash = buildZlib(gcc..., libc...)
myprog-uniqueMyProgHash = buildMyProg(gcc..., libc..., zlib...)
To download "myprog" from a binary cache, I can't calculate uniqueMyProgHash using any old versions of libc and zlib; I must have exactly the same hashes that were used by the system that built "myprog", all the way up the dependency chain. And I'll only ever have that if the builds are reproducible and/or I downloaded them all from the same binary cache.[1] In practice, there's nothing stopping the instructions from saying "download this binary blob" instead of "download this source tarball".
[2] The problem of build reproduciblity is not solved, but many outside of Nix also see this as important, see https://wiki.debian.org/ReproducibleBuilds
>But they are ultimately about the degree to which we allow binary blobs, not whether we do.
I don't agree with this assesment of Nix and Nix packages at all. My local system evaluates the package definition (a description of how to build it from source) and merely is smart enough to retrieve a prebuilt binary with the exact same source inputs and configuration. Sure, I'm still trusting the remote party to have built it as described, but that's true of any system where pre-built binaries are distributed.
For another explanation, I could disable the NixOS Hydra Cache and could theoretically rebuild my current system state without their binary cache and still wind up with the exact same bits. At least, that's the idea behind Nix.
So what?
You don't need to reproduce that working state: The work has already been done!
Think about how the interactive approach Lisp and Smalltalk programmers use is superior to the compile/run/rerun approach used by C++ and Java programmers -- by exploring the problem in a nonlinear way, you can find your way to a solution more quickly.
Docker package management is like that: You make some changes, you commit often, fork your instance and try lots of different things. Eventually you find something that works and you tag it. You share your tags with other people. This is an extremely productive way to get work done.
My background is physics, and the philosophy there is "If you can't reproduce it, it doesn't exist."
In my experience with software, sharing opaque binary blobs is a Bad Thing. It doesn't matter if the blob is a proprietary firmware image, or a "open source" docker image. It's a magic unreproducible image. And (to me, at least) therefore suspect.
> Docker package management is like that: You make some changes, you commit often, fork your instance and try lots of different things. Eventually you find something that works and you tag it.
Again, the physics philosophy is "If you don't know what you did, you didn't do it".
For software, programming by randomly trying things is one of the worst methods available. You should understand what you're doing, and understand the system you're building.
> You share your tags with other people. This is an extremely productive way to get work done.
Sure. It's a way to quickly create, test, roll back, and share opaque binary blobs. It's "productive" in that you get things done. But you have no real idea what you got done. You just have a magic image that "works".
I would not hire a programmer with that kind of attitude. I've been burnt by that method, and those kind of programmers, too many times.
I can't reproduce me, so do I not exist?
And yet you don't know why.
This is called dogma, and dogma is bad: It leads people to make stupid decisions over and over, all the while repeating that the alternative is worse.
That's exactly how I recommend applying patches.
If it breaks things you can fix it.
You don't do this on a live system: If you're smart and your live systems are ephemeral you can copy your image, get it working, verify it interactively, and once you have a working image, you spin up new instances using the new system, and start shutting down the old systems.
We've been down this road before. Hacking something until it works, then imaging it and passing it on to your coworkers is a maintenance nightmare.
For example, did you read that article?
You know Docker has none of those problems
> The first problem with a snowflake server is that it's difficult to reproduce. Should your hardware start having problems, this means that it's difficult to fire up another server to support the same functions.
docker tag/push/pull
> If you need to run a cluster, you get difficulties keeping all of the instances of the cluster in sync. docker start tag
> You can't easily mirror your production environment for testing. docker commit/export/import
> When you get production faults, you can't investigate them by reproducing the transaction execution in a development environment. docker push/pull
> The true fragility of snowflakes, however, comes when you need to change them. Snowflakes soon become hard to understand and modify. Upgrades of one bit software cause unpredictable knock-on effects. docker history/diff
The issue that Martin is describing is one where people work on the server - update it in place, and do not have any change management process besides "do stuff" and any quality checking process besides "check stuff".He spent over 500 words to say that's probably not a good idea.
No kidding.
Now.
What I'm actually advocating is interactive development: The exact same way we develop our APL workspaces and our Smalltalk images, can be used to design and build server infrastructure.
Instead of a development cycle that goes:
* Edit nixfile/dockerfile/vagrantfile
* Wait (sometimes hours)
* Test things
* Repeat
You get a very short:
* Do stuff
* Get happy
* Tag the results
Then when you want to run "in production", you publish your tags/image, review the history with your team, not dissimilar to how Smalltalk people will clean up their changes file, and then introduce the new version into the cluster. Once you're satisfied the world hasn't ended, you can decommission the old images.
You can even make scripts that do these many of these steps automatically (divert x% of traffic to new instances, collect results, and so on). If you have a well-designed infrastructure, you can have junior developers use those scripts to make changes on their first day.
Now.
I get it, you have realised that if you start over often enough you get good at it.
I get that you've seen people who treat systems development as a completely linear descent into unmaintainable bat barf that can only be recovered by a bad day reinstalling everything and "starting over",
I also get that you think amortising that cost by taking those hours to rebuild your entire system when glibc changes is necessary to avoid that bad day.
I also get you like static external configuration like Dockerfiles or Vagrantfiles, and view them as instrumental in the audit of that process.
However while you understood that I disagree with that, you didn't understand why: If you had a decade or so of Smalltalk or Lisp experience instead of just ruby experience, you might have known exactly what I meant, but instead of asking, you just ignored the part you didn't understand, making a straw man argument that you did understand.
After all, what's more likely, someone knows something important that you don't? Or someone knows something unimportant and just isn't as smart as you?
Is a Telegram bot that queries the RAE dictionary (Spanish). It doesn't have any documentation yet, though :S
You can look for the project deps code here: https://git.hso.rocks/hso
Do you write default.nix files by hand, or there are some tools to automate the process?
I suppose for a project with a lot of dependencies (one of my current requirements.txt is over 100 SLOC long - almost all deps are on PyPI; haven't checked nixpkgs as I'm stuck with Debian at the moment) it would be somewhat tiresome to check every package and for every missing one list all the dependencies.
The nixos.org website is a bit sparse on the Nix project's history, and same with wikipedia (though separately mentions that NixOS was a research project started by Eelco Dolstra in 2003).
http://nixos.org/~eelco/pubs/phd-thesis.pdf
He also wrote this InfoQ article on the subject of Nix and NixOS which may have some useful information (2014):
https://www.infoq.com/articles/configuration-management-with...
The Wikipedia pages for Nix and NixOS also have some interesting references.
https://en.wikipedia.org/wiki/NixOS
https://en.wikipedia.org/wiki/Nix_package_manager
Edit: I have been playing with NixOS at home for a few months and I think it's very interesting, but I'm a bit surprised I haven't heard more about it over the past decade or so. I'm thinking that the recent industry focus on deployments and provisioning has caused more people to come across it.
* 2007 NixOS Linux distribution
* 2009 Hydra Continuous Integration
* 2011 NixOps Cloud deployer
* 2013 First stable NixOS branch
(from http://wmertens.github.io/nixos-cfgmgmtcamp-slides/#/1/1 - non-authorative source :))
- There is a version history in the release notes appendix of the manual. [0]
- As others have posted here, the project is currently hosted on github [1], though it was originally in a svn repo. [0]
- Eelco Dolstra is the active project maintainer. [2]
- First checkin for Nix was ~March 12, 2003 (in the file nix.c/nix.cc). [1]
- Version 1.0 release on May 11, 2012 (also first release from github). [0]
[0] Release Notes: http://nixos.org/nix/manual/#sec-relnotes
[1] https://github.com/NixOS/nix
[2] https://github.com/edolstra
Edit: Thanks to sibling posts for the other info they were able to dig up for us.
I'm looking forward to future posts that show how Nix is better than Homebrew or MacPorts, because that hasn't been demonstrated so far.
And as a bikeshed nitpick, I was always unhappy with the meaningless rpm options, preferring apt's clearer options (rpm -qa vs aptitude search). I'm a bit disappointed that nix chose to mimic rpm's style. Oh well, tomayto/tomahto.
Homebrew is downright dangerous (I've written about why: http://inthebox.webmin.com/homebrew-package-installation-for... ).
MacPorts is fine. Not wonderful, but OK. Not reproducible in the way Nix is.
PkgSrc is also pretty good. Also not reproducible the way Nix is. But, the packaging policies are good, the packages tend to be well-thought out, and the technical solution to stuff like dependency resolution is pretty OK. The people building and maintaining PkgSrc know what they're doing.
Nix is clearly superior to all of them, however, in being reproducible, easy to roll-back in a predictable way (try going backward with almost any other package manager, even RPM/yum and dpkg/apt can't do that...I love'em both, but recognize that we now have better solutions to package management). Nix is just a fundamentally better tool.
Flatpak is another really promising packaging technology with some of the same benefits (but it's tackling things in a different way; I think I still have to consider Nix a better overall solution; it is certainly simpler in both implementation and usage, for packagers/developers and end users).
But, don't use Homebrew. For now, PkgSrc is probably the best method of getting a lot of reasonably good packages for Mac OS X. Nix will be the better option eventually, once there's a lot of people packaging for it (assuming people get over their bizarre love affair with Homebrew and start working with Nix, instead).
Your link specifically covers the case of Homebrew on the server. But Homebrew isn't meant to be a server package manager. It's an OS X package manager, and OS X is a desktop operating system, not something that most people choose to use as a server (OS X Server exists but is primarily used for intranet stuff rather than as a production server). The complaints that your link has are only problems for an external-facing server. They're not problems for desktop use. And the simple answer to that is: don't use a desktop package manager on your server.
The wording dangerous was poorly used, inappropriate for server package management would have been better.
So, yes, to be clear: The dangers of Homebrew are primarily when considering it for use in a server context. I personally wouldn't use it anywhere. But, it has many good qualities that many people value highly.
Install emacs with brew Install spacemacs on top of emacs It works!
To pull users from brew it needs to work at least as well, especially for common tools like emacs. Go check out the number of issues related just to emacs installs, it is kind of amazing.
Just about everything else I'd like to use is packaged, so Id like to think we're over the adoption-pkg-count chicken egg problem.
apt-cache search
aptitude isn't necessarily installed.The new apt, if you have it, now combines apt-get with apt-cache plus a bunch of UI improvements.
apt search ...
apt install ...
If you've got it, it's well worth a look.Using nixops to push a closure from your local system up to ec2 is very pleasing. It feels like the future.
For a toy project this is not a problem of course. But before I'd use nixos in production, it needs a better story for security patches. If you try to look up the word 'security' you get viagra spam on their wiki. and there is no security mailinglist whatsoever iirc.
I'm sure this will improve over time though. And for development, nix is still a saviour.
Rather than rebuild everything that depends on the fixed glibc, we build the fixed glibc, then rewrite all references to the old glibc to refer to the new one. That rewriting happens in new copies of the referring packages, of course, since the "store" is immutable.
https://www.gnu.org/software/guix/manual/html_node/Security-... https://savannah.gnu.org/forum/forum.php?forum_id=8470
A big help is IMO to get a solid understanding about how nix itself works[1]. Also check out some existing `configuration.nix` files on GitHub. Just google for "github configuration.nix". This might give you some inspiration what you can do with the `configuration.nix`.
If you have some trouble with customizing vim on NixOS/via nix, checkout this[2] blog post I wrote a month ago. Hope it helps :)
[0] http://blog.tinco.nl/2016/02/05/nixos-on-digital-ocean.html [1] https://nixos.org/nix/about.html [2] https://www.mpscholten.de/nixos/2016/04/11/setting-up-vim-on...
http://zef.me/blog/5981/deploying-a-simple-node-js-applicati...
Step 1: I have to download a gig of stuff before I can install any packages? Even though my drive is big nowadays, that still seems like a bit of a waste...
Step 2: Let's try building a package, the last thing I installed with homebrew.
> cd math/minisat
> make install clean
Makefile:27: *** missing separator. Stop.
> make
Makefile:27: *** missing separator. Stop.
Hmm.. this isn't the most user-friendly system...UPDATE: I have to use the bmake I bootstrapped, didn't realise (and the quick-start docs didn't mention it). Now building begins, but the executable doesn't link.
[1]: https://robots.thoughtbot.com/brewfile-a-gemfile-but-for-hom...
From my few days of trying to replace Homebrew with Nix, being able to rollback the environment to last known good state (`nix-env --rollback`), ability to keep track of package changes (`nix-env --list-generations`), ability to try a package without installing it (`nix-shell`, well, technically it's installed on the machine, but nothing is linked in the profile, and you can nuke them with `nix-collect-garbage`) are very nice additions.
Apart from these features, the fact that it doesn't chown `/usr/local/` to my user is a big plus. Nix will also not linking anything not explicitly installed by user to their profile (e.g. if package A has B as dependency, B won't be linked until user actually choose to install it, which is then managed separately from B that were explicitly installed as A's dependency).
That said, I've since revert back to Homebrew because there are few packages broken that are crucial to what I'm working on. Creating and fixing package is not too hard (I did with aria2c), although time didn't allow me to do it back then. I would love to try to switch to Nix again sometimes.
People in ##nix-darwin are super-nice, also! :-)
[1]: https://github.com/NixOS/nixpkgs/pull/15029
[2]: https://nixos.org/nixpkgs/manual/#users-guide-to-the-haskell...
I can setup scripts that install and configure things for emacs to make sure it always runs in an environment that has all it needs. But with the benefit of not having to have everything installed globally.
I can have multiple versions of whatever installed into /nix at once. But still not have to worry about breaking things that need both versions.
As for package availability, I've not hit any issues. It has most of what I personally need.
What I hit more often is random breakage or having to update derivations that only ever got created or maintained from a linux perspective.
I'd say its in the "developer not afraid to fix broken build problems" category as a package manager. Its not bad, but it is really annoying when you have to revert back to a prior generation because some package you use got updated and now won't build because of its test suite failing.
Random stuff like that happens a few times a month, nothing huge though honestly.
How does it handle OS-specific dependencies/distinctions? Or if e.g. a package requires ruby or python to be installed?
With Nix you just declare postgresql as your package inputs and you are done. All needed parts to build and install psycopg2 are there.
Your package/project is completely isolated from your OS libs.
https://github.com/NixOS/nixpkgs/tree/master/pkgs
...and search here if you're looking for something in particular:
https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/...
Stop doing this.
Look, even if you are rolling your eyes and thinking, "it's https and I'm not Ed Snowden, I think I can afford the risk for the benefit of an easy install process", what happens if curl is interrupted? Are you excited at the prospect of a half-ran install script that you didn't even look at?
If you are installing software from scratch, you must trust the https server that serves it to you.
They could publish sha256 check sums to https://nixos.org/hashes, but you would have to trust the https server.
They could publish their gpg key to https://nixos.org/gpg, but you would have to trust the https server.
Things would be better if we had a reasonable certificate system for verifying open source software, but we don't. There is no gpg web of trust. There is no hierarchical CA system for code signing that open source authors can easily plug into, and expect their users to verify.
If you care this much, stop astroturfing and go build a system that does better. It will be very hard work, and you will have to distribute the first version of your solution with an https server that your users will have to trust.
[1]: Ok, so maybe the instructions could be "curl <url> -o install.sh && sh install.sh".
This is incorrect - you are forced by `curl | sh` to trust all of the 1000+ CAs in your OS' keystore. And if you can't trust all of them (since some have given out Google certs before, you can't), how can you trust what you're getting over HTTPS?
With hashes, they are not typically served from the same domain. That's the minimum level of protection for the user.
Signing with a key is another level of protection; it lets the user (not the OS) decide the level of trust, and even verify the key with the author of the package via a completely separate channel.
Now the question really becomes, why doesn't the provider use the existing (secure) channels of software distribution? RPMs, DEBs, installer packages for Macs, MSAs for Windows?
If you don't trust them, they should not be in your certificate store. That's not a problem with using `curl | sh`, it's a problem with the certificate store and what the user is trusting.
http://ariya.ofilabs.com/2016/05/nix-as-os-x-package-manager... is served over HTTP. Saying "Copy and paste this `curl | sh` command" allows this attack: http://thejh.net/misc/website-terminal-copy-paste
If this were software that I had to install multiple times (say there are several updates a year), it might make sense to implement TOFU with a published GPG key -- each successive update would use the same key I imported the first time. However, the nix installer installs a package manager which is self updating, and therefore implements TOFU itself.
What attack vector would you actually be protecting against if you downloaded a .tar.gz full of binaries and extracted it to /, then started installing things with it?
Kind of a funny situation. If you look at the script first, you'll notice that it would have been okay for the download to be interrupted and so, assuming everything else is kosher with you, the '| sh' would have been "safe".
And if you don't look at the script first, you'd never know that what you just did was "safe."
Schroedinger's-pipe-to-sh.
I understand this path is configurable, but you'll be compiling everything yourself, unable to use Nix's binary cache. You also risk running into unique problems since everyone else is using /nix
Absolutely nothing. The script is written intelligently, so an interrupted download just results in a syntax error. Specifically, the entire file is wrapped in {}, and if the terminating } is missing, sh will throw an "unexpected end of file" error instead of executing anything.
Though I do agree wholeheartedly that piping scripts to shell, sight unseen, is a remarkably awful idea.
Because it goes further than just downloading a .tar.gz. It checks your OS and its dependencies; download the right tarball; check it has an install script; run the install script.
――――――
¹ — https://derflounder.wordpress.com/2015/10/01/system-integrit...
It's only when you try to delete something like /Library, that it then complains.
This is one reason why I strongly believe SIP is blown out of proportion. I've used El Capitan since the betas and created root directories, deleted them, added to existing root directories without having to disable SIP.
Again, it's only when you try to modify the built in directories inside / does it then complain, and frankly, I am more than happy with that, even with sudo privileges.
SIP only prevents users from modifying system level files. It does not prevent you from adding to, or deleting your own files within the `/` directory.
like i needed another folder in root, as if `/opt/`, `/usr/local/` or `~/.local/share` weren't good enough and this is somehow a feature. another package manager that has less features than homebrew? oh, like fink and macports - no thanks.
With /usr/local/{bin,lib,include}, how would you install multiple versions of openssl? Would you violate convention and do something like /usr/local/openssl-x.x.x/{bin,lib,include}? How do you avoid file path conflicts? When a package is built against a particular version of openssl, how do you ensure that version of openssl sticks around, and that that, upon execution of said program, the dynamic linker loads specifically that version of openssl and not one of the others?
While I encourage you to consider those questions, the short answer is "you can't". At least, not with conventional package managers like Homebrew.
Because Nix builds each package in a unique prefix (governed by the hash of all of the build inputs, recursively), the Nix package manager can use chroots (and Sandboxes on OSX) to ensure that packages are deterministic, and that each package refers specifically to the versions of the dependencies they need (dynamic libraries are fixed via rpaths and we apply patches for references to executables -- so "python -m foo" becomes e.g. "/nix/store/<HASH>-python-2.7/bin/python -m foo").
If you don't use a unique prefix per package, the problem of "how do I install stuff without worrying about path collisions amongst the multiple versions of requisites" becomes intractable. Ditto for build determinism, binary caches, lightweight environments a la nix-shell, etc.
I suppose we could shoehorn each package into /usr/local/<HASH>-<NAME>-<VERSION>/{lib,bin,include}, and then we could tick the "use an existing directory under /" box, but is that really better? I don't see what we gain from that, since that's already an abuse of /usr/local.
I guess my main issue with the original article was that if you don't already know what nix is, the benefit is not at all obvious, especially for the (above?) average joe for whom homebrew works fine. For a sysadmin who is sick of dependencies breaking, even when using something like aptitude, it sounds perfect though.
Although after skimming the nix docs [1] and reading your reply, I'm still not sure why e.g. `/opt/nix/` wouldn't work. Maybe it would, except for the fact that `/nix` was decided on and if you now change that, the prebuilt packages break (see [1])? Obviously, it isn't a deal-breaker, but e.g. consider an existing backup solution which might have been configured inclusive, not exclusive.
Also, I get that as a package manager, nix is in a different position than most programs, but putting stuff in `/` isn't a great precedent, and other package managers don't AFAIK.
For example, installing Datomic via Brew will result in databases being stored in:
/usr/local/Cellar/datomic/0.9.5206/libexec/data
How would that work with Nix? Would the data live under /nix?
And most importantly, would that data get squashed because of some kind of idempotency assumptions that Nix might make?
Yes.
>Would the data live under /nix?
No, Datomic will be built with another default data directory.
>would that data get squashed because of some kind of idempotency assumptions that Nix might make?
No, since data is stored separately.
The reason is because when the software is compiled, it's stashed in the /nix directory, and might refer to other artifacts in /nix. For example, zlib.so exists in /nix/store/zlib-.../lib/zlib.so, and links to glibc.so, which exists in /nix/store/glibc-.../lib/libc.so.6. So if you want to install zlib and get binary packages, you need to first install glibc. And you need to put glibc in the place that zlib will expect it.
But being able to have multiple / separated environments on my machine would be hugely beneficial.
Working for a full-time software consulting agency, I'm normally actively working on many projects at the same time, each of which have their own nuances of packages that are required (e.g. different versions of PHP, different sets of dependencies, etc.) So if nix truly offers seamless switching between environments (and if it can do it quickly and efficiently), it would definitely be worth it for me to look into it further.
> Working for a full-time software consulting agency, I'm normally actively working on many projects at the same time, each of which have their own nuances of packages that are required (e.g. different versions of PHP, different sets of dependencies, etc.)
I don't think this is what Nix offers. This is more like a homebrew competitor (I assume you don't use homebrew to install php...).
Nope. They both do package management, but that's where the similarities end.
Homebrew packages are not patched to point at precisely the version of the stuff they were built against. For example, if you have program that dynamically links to openssl, that program is built with the expectation that the dynamic linker will be able to find e.g. libssl.dylib in either /usr/lib or /usr/local/lib (the specifics are harrier, but that's a decent approximation). If you later upgrade openssl and the ABI changes, you've now silently broken everything that uses it -- you'll now get a segfault at runtime (I've had this happen with openssl and many other libs on Homebrew, and is part of why I was (and still am) very excited about Nix).
When you compile a package with Homebrew, you're not guaranteed to end up with the same result as someone else, even if they have the same checkout of the formulae. Why? Well, each project's Makefile (or what have you) will try to run whatever's on $PATH, and poke around elsewhere on your system to e.g. automatically enable build flags (oh, luajit is installed? I guess I'll just go ahead and enable Lua scripting and link to it).
How does that compare with Nix?
Nix packages are patched so that their runtime dependencies (dynamic libraries, programs to be execed, shebang lines, etc) are locked down to the precise build that was specified as part of the package. The obvious implication here is that Nix packages can be trivially installed with differing versions of dependencies as necessary (back in the day, I wanted to play with both the Elixir langauge and the Riak DB, but they required two different major versions of Erlang. Unfortunately, I could only install one version, as the packages for both versions wanted to be placed in the exact same prefix and the filenames would overlap. This was on Ubuntu, but it applies equally to Homebrew).
When compiling a Nix package, I can rest assured that the build artifacts will be equivalent between two different machines (not bit-for-bit, but at least functionally equivalent -- excepting compiler bugs). Why? Because the build happens in an isolated environment where, as far as the build process is concerned (we take advantage of a number of kernel features on Linux (chroot) and OSX (Sandboxes)), the system only consists of the packages explicitly listed as build inputs -- nothing else. Excepting esoteric stuff like someone intentionally trying to subvert chroots and such, if you were to put a gun to my head and tell me that you were going to shoot me if you could find a case of non-determism, I'd shrug. We're serious about that whole determinism thing -- it's a core selling point of Nix, and the reason for Nix's "quirks" (the per package prefixes, hashing of build inputs, chroots, lack of network access, etc).
If the above doesn't make the differences obvious, I'll challenge you to answer some questions (the socratic method):
1. How does Homebrew support having two versions of openssl installed concurrently? Describe the paths involved, how the dynamic linker would be guaranteed to load the respective version of libssl, etc.
2. How does Homebrew ensure packages are built exactly the same way across two different machines (e.g. using the same version of autotools, clang, make, etc)? Be sure to explain how the build is guaranteed to not auto detect/enable stuff because of things present on my system that may not be present on your system. Note that Nix will deterministically fail if you fail to explicitly list all of its dependencies (rather than working because, say, cmake just so happened to be installed on the formula author's machine) -- so you'll need to describe how Homebrew achieves this when running a formula.
For example, when building postgresql on OSX, it always links against libpq.dylib in /usr/lib, not against the one it just built. In theory, it could be possible to exclude /usr/lib from the -L path, but then I would lose other libraries, that ship with the system (i.e. libz, libxml2, libxslt, libpam, libSystem). The other possibility is to build all these dependencies too - except libSystem...
Right now I'm using install_name_tool to fix the binary, but that is an ugly hack. (The other problem in this case is, that system libpq is x64-only. It means that i386 build would fail).
I was pleasantly surprised, as I could rollback the entire state of my system from GRUB itself if anything went screwy.
http://chem.tufts.edu/answersinscience/relativityofwrong.htm