23 ms·
Nix as OS X Package Manager
- justacodefan 11y agoGreat cliffhanger for the next article at the end.
- hso1 11y agoSince I discovered Nix, I've been using it as a package manager for OS X and Linux. Every project my team is working on now has a default.nix file. Getting started on a project is so easy for a new hire now: just one `nix-env` away from a fully working dev environment! :D
- drdaeman 11y agoBy chance, do you have some public/sample projects that use this approach?
- hso1 11y agoYes! Look here: https://git.hso.rocks/hso/def https://git.hso.rocks/hso/def 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 https://git.hso.rocks/hso
- drdaeman 10y agoLooks great, thanks for sharing! I'd definitely try this approach. 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.
- rokgarbas 10y agogive pypi2nix a try and ping me on irc if it fails (nick: garbas) https://github.com/garbas/pypi2nix https://github.com/garbas/pypi2nix
- schneidmaster 11y agoAnyone who's used Nix for a while -- how does package availability compare to Homebrew or Macports? Other than the default.nix thing (which Homebrew also has a version of [1]) are there any other clear benefits to switching from Homebrew? [1]: https://robots.thoughtbot.com/brewfile-a-gemfile-but-for-homebrew https://robots.thoughtbot.com/brewfile-a-gemfile-but-for-hom...
- hso1 11y agoFor me the biggest benefit is reproducibility. I can get a package to build on any machine exactly the same and with no hidden dependencies.
- schneidmaster 11y agoThat does seem pretty cool, and I also see it works out-of-the-box on Linux machines. It doesn't seem to have a homebrew-cask equivalent though, which is a bit of a bummer. (Makes sense though since GUI applications aren't really cross-platform.) How does it handle OS-specific dependencies/distinctions? Or if e.g. a package requires ruby or python to be installed?
- hso1 11y agoWe use it on Python projects instead of virtualenv. A problem that you sometimes have with virtualenv is that you must install libpq-dev and python headers and what not to install from pip if the package has native extensions. 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.
- sirn 11y agoThe last time I tried (a month ago), I could reproduce most of my current Homebrew packages. There are few that are broken (e.g. rust, which has since been fixed), or do not have Darwin support (aria2c, which I have a PR open[1]). There are also packages that are a little bit hard to discover, e.g. those that are imported from Haskell's Hackage where it is not listed by default[2] when you do `nix-env -i <packageName>` (e.g. shellcheck). 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 https://github.com/NixOS/nixpkgs/pull/15029 [2]: https://nixos.org/nixpkgs/manual/#users-guide-to-the-haskell-infrastructure https://nixos.org/nixpkgs/manual/#users-guide-to-the-haskell...
- nickysielicki 11y ago> curl https://nixos.org/nix/install https://nixos.org/nix/install | sh 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?
- hso1 11y agoYes. I'm unconfortable doing this as well. Not only with Nix, I really think you shouldn't do it, ever. On Ubuntu/Debian, at least, I'm installing the .deb package.
- bydo 11y agoThe install script (for Nix, at least) is written such that it will not execute if partially downloaded, so that is less of an issue. Though I do agree wholeheartedly that piping scripts to shell, sight unseen, is a remarkably awful idea.
- vertex-four 11y agoThe script doesn't run if it downloads. Go read it yourself. 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?
- bydo 11y agoOn that note, is there some valid reason Nix absolutely needs access to / to create /nix? Why can't it live somewhere else? I believe some parts can go anywhere, but /nix is hard coded for the rest, which I'm not entirely comfortable with.
- hso1 11y agoI don't know for sure, but I think it's installed under /nix thinking of multi-user Nix installs. With Nix any system user can install its own set of packages and on NixOS there are build users that install packages on behalf of normal users.
- AceJohnny2 11y agoI was forcefully relocated from my comfortable decade-old Debian home into OS X, and the package management here in unsatisfying. 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.
- mhd 11y agoTo continue picking nits, that's apples/apple pie, not tomatoes. rpm's equivalent is dpkg, not aptitude (whose match would be yum/dnf/zypper).
- brobinson 11y agoapt-cache search aptitude isn't necessarily installed.
- david-given 11y ago<even more tangential> 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.
- deleted 11y ago[deleted]
- benley 11y agoThere's a new commandline tool in the works that will improve all those interfaces; I'm not sure how far along it is, though. Here's the discussion: https://github.com/NixOS/nix/issues/779 https://github.com/NixOS/nix/issues/779
- doublerebel 11y agoTry pkgsrc. It's much more like apt than nix, macports, or homebrew.
- JonnieCache 11y agoI recently set up a new server for a toy project with nixos and it was a pleasurable experience, even if I did have to pull together several sources of somewhat thin documentation. Recommended. Next time I set up a new dev machine I'm going to give nix a try for dev environment management. Using nixops to push a closure from your local system up to ec2 is very pleasing. It feels like the future.
- arianvanp 11y agoI did this too until there was a glibc vulnerability. and it took ages for a 'patch' to come out that had to be installed in an obscure way. 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.
- lfam 11y agoIn Guix, we address this problem with grafting. 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-Updates.html https://www.gnu.org/software/guix/manual/html_node/Security-... https://savannah.gnu.org/forum/forum.php?forum_id=8470 https://savannah.gnu.org/forum/forum.php?forum_id=8470
- jb55 11y agoNix has a way of doing this as well, just needs a better UX (like most of nix).
- technomancy 11y ago> just needs a better UX Luckily guix is a better UX for nix. =)
- rdtsc 11y agoWhen I first heard about Docker, I thought it did what Nix does. 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.
- colemickens 11y agoI mean, that's exactly what a Dockerfile is for. I don't know of anyone seriously using Docker that isn't using Dockerfiles exclusively. I only know of a single time when it's valuable to "commit" a new image (recovering logs from a stopped container). 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.
- hso1 11y agoThere's a post on building Docker images with Nix: https://news.ycombinator.com/item?id=11502989 https://news.ycombinator.com/item?id=11502989
- OJFord 11y agoI sort of agree, but I also think there's no reason to view Docker commits any differently to Git commits. 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.
- philipsunrise 11y agoSee you all in five years when Nix is shit and we're all switching to Flurp as our package manager.
- fucking_tragedy 11y agoI ended up searching "Flurp" because with the current state of things, there was a chance that this was real.
- geggam 11y agoAdd javascript to the search. Sometimes I do that with random searches just to see the crazy things people are doing with Javascript
- AndyKelley 11y ago"when people thought the earth was flat, they were wrong. When people thought the earth was spherical, they were wrong. But if you think that thinking the earth is spherical is just as wrong as thinking the earth is flat, then your view is wronger than both of them put together." -Asimov http://chem.tufts.edu/answersinscience/relativityofwrong.htm http://chem.tufts.edu/answersinscience/relativityofwrong.htm
- cel1ne 11y agoIs there any reason to switch if homebrew worked perfectly for me in the last couple of years?
- mapcars 11y agoAbility to install several versions of any package and guarantee that nothing can break installed packages are two main points of Nix.
- guitarbill 11y agonone, which is why this article is so vague. 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.
- cstrahan 11y agoIt would appear that your primary takeaway is that we put stuff in a different directory, for an apparently arbitrary reason. I agree, that would be silly -- if it were the case. 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.
- j1vms 11y agoCould someone post (or link to) the history of Nix, the package manager? Who developed it, key project milestones, etc.? I understand it comes from, or led to, NixOS Linux distribution which uses Nix of course. 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).
- tvon 11y agoI don't know if it's useful to you, but I can link you to Eelco Dolstra’s PhD Thesis (2006): http://nixos.org/~eelco/pubs/phd-thesis.pdf 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-nix 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/NixOS https://en.wikipedia.org/wiki/Nix_package_manager 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.
- jf 10y agoThanks for posting these links. I didn't know about the PhD thesis and the InfoQ article is the best introduction to Nix that I've read yet!
- deleted 11y ago[deleted]
- wmertens 10y ago* 2003 Nix & nixpkgs Language and packages * 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 http://wmertens.github.io/nixos-cfgmgmtcamp-slides/#/1/1 - non-authorative source :))
- xaduha 11y agoNix is impressive, NixOS is more impressive still.
- jd3 11y agoWhy use nix when pkg-src has been available on Darwin for over 15 years, boasts more packages, and has decades of support (plus Jonathan Perkin and the guys over at Joyent)? Why people assume the gross project known as homebrew (and the better macports, where homebrew gets all of their real package patches) are the only two package managers on OS X/Darwin is perplexing to me... Not to say nix is not interesting, but still. The OS X open source/package community would be insanely better if it was solely centralized around pkg-src. https://pkgsrc.joyent.com/install-on-osx/ https://pkgsrc.joyent.com/install-on-osx/ http://github.com/cmacrae/saveosx http://github.com/cmacrae/saveosx
- dmd 11y agoBoth of your links are broken.
- jd3 11y agooops, copied it over from my comment on the article itself. fixed now
- CJefferson 11y agoHmm.. I've never tried pkg-src before. I'll give it a try. 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.
- jd3 11y agouse the `pkgin` binary to install binaries built from joyent... (https://pkgsrc.joyent.com/packages/Darwin/ https://pkgsrc.joyent.com/packages/Darwin/) No need to clone the package tree. This fixes step 1. `sudo bmake install clean` fixes step two.... (opt needs superuser permissions). see the joyent link in particular to see how easy it is to install pre-compiled binary packages with pkgin
- sdegutis 11y agoWhat happens when packages need to store data? 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?
- JonnieCache 11y ago/nix is mounted readonly, only the special nix user can write to it. Data goes in /var or similar.
- mapcars 11y ago>would that work with Nix? 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.
- educar 11y agoThis sounds exactly like what homebrew does. It also installs under /usr/local and does not touch anything else. What does nix package manager provide that homebrew does not? (from a user point of view)
- zachrose 11y agoNix groups all of your installed packages in one environment. When you install a new package, it creates a new environment with the new package added to it. This alone may sound insignificant, but it enables having multiple nix environments (e.g. one per project) and switching between them very quickly and easily.
- educar 11y agoCan you give me an example of projects which require this setup? (Even a personal anecdote will do)
- mikeho1999 11y agoI've never heard of nix, so I can't comment to that specifically. 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.
- Ericson2314 11y agoIt utterly does!
- educar 11y agoCan't reply to sibling post for whatever reason. > 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...).
- all_usernames 11y agoWait... binaries inside a ~homedir/.dotfile/? Why on earth?
- chris_st 11y agoI believe they're just soft links to the latest/appropriate version of the executable under the /nix/... directory.
- ricardobeat 11y agoI believe those are just symlinks to the binaries in /nix/xxxx, so that $HOME/.nix/bin can be added to PATH.
- Watabou 11y agoJust curious, why would a package manager using a folder under the home directory be weird?
- didip 11y agoIs there a way to install packages on user space without proot? Why does it need /nix?
- aseipp 11y agoYou can install packages by installing nix into your homedir. But you will never get binary packages this way. 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.
- arm 11y agoIt seems like when installing Nix, it needs to create a 'nix' directory in your root directory. While I haven’t tried installing Nix yet myself, I’m guessing this probably won’t work on OS X v10.11 El Capitan due to System Integrity Protection¹. You’ll have to temporarily turn it off² first before attempting to install Nix (and then optionally turn it back on after). ―――――― ¹ — https://derflounder.wordpress.com/2015/10/01/system-integrity-protection-adding-another-layer-to-apples-security-model/ https://derflounder.wordpress.com/2015/10/01/system-integrit... ² — http://www.madrau.com/support/support/srx_1011.html http://www.madrau.com/support/support/srx_1011.html
- cstrahan 11y agoOoh, that's an excellent point -- thanks for bringing it up. I've had Nix installed since early 2014, so I haven't run into any trouble with SIP yet. Looks like we might need to update our docs, and maybe have the installer give a helpful tip.
- Razengan 11y agoNo need, `sudo mkdir /nix` works even with SIP enabled.
- Watabou 11y agoUnless /nix modifies files/folders, then no, you don't need to modify your install instructions. 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.
- Razengan 11y agoI have SIP enabled and I was able to install nix just by `sudo mkdir \nix` before installation. No problems.
- Watabou 11y agoNope, System Integrity Protection only affects you if you delete/modify system level files. It does not prevent you from creating a `/nix` directory with regular root privileges, nor does it prevent you deleting it with root privileges. 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.
- yarou 11y agoI demoed NixOS a few years back when I was wrangling with the Haskell ecosystem. I was pleasantly surprised, as I could rollback the entire state of my system from GRUB itself if anything went screwy.
- Razengan 11y agoThis is amazing. As someone who hates clutter and having to use sudo for anything, Nix is just what I needed!
- agumonkey 10y agoOnly two results about nix on windows, and not very enthusiastic ones. Too bad.
- ris 10y agoHaving set up my last company doing all development and deployment using nix, moving to a new team which just uses pip/virtualenv and a "bootstrapping script" feels a little unnerving to start with.
- cttet 10y agoIs there any good guides to get started on nix with python?
- ris 10y agoThe nixpkgs manual has a section on it https://nixos.org/nixpkgs/manual/#sec-python https://nixos.org/nixpkgs/manual/#sec-python but the key to it is that it's really mostly about managing your PYTHONPATH. You wouldn't typically be installing a python package and just expecting it to be available to a session-launched python invocation (because PYTHONPATH is not exported to the user env of a profile), instead you would probably use nix-shell or a custom-built python environment with the exact package setup you desire...