12 ms·
Using Nix on macOS
- omginternets 4y agoChrist that's a lot of work, just to start working on work. I really want to like Nix, but the UX is frankly offputting. I really hope it improves to the point that it can be mindlessly installed.
- ratorx 4y agoI wouldn’t take this one blog post as gospel about how to use Nix. I’m not denying that it’s complicated, but doing declarative package management is not the only way to dip your toes into Nix. You can use it pretty much as a conventional package manager with none of the upsides of declarative package management (but none of the complexity either). On the surface level for people migrating from existing package managers, nix-env is approximately as complicated as something like pacman. You just need the command for installing, removing and updating (well, the 2 commands for updating, but that’s the only extra complexity).
- baby 4y agoPeople say that but yet nobody linked to a post explaining the “right way” of using nix on macOS
- ratorx 4y agoHere is the official manual page for Basic Package Management. No blog post necessary. This covers the majority of it, but I’d say if you read the entire section on Package Management, then you’ll get an idea of how it works and be able to install, update and uninstall things (as well as a bit more). https://nixos.org/manual/nix/stable/package-management/basic-package-mgmt.html https://nixos.org/manual/nix/stable/package-management/basic... Also, there is no “right way”. What I suggested was the way to get parity with standard package managers. There are many different ways to use it, because it is a very flexible tool. There’s no reason to learn every single one to get started with it.
- omginternets 4y agoThis doesn’t tell us how to install it, which is what we’re griping about.
- ratorx 4y agohttps://nixos.org/manual/nix/stable/installation/installing-binary.html https://nixos.org/manual/nix/stable/installation/installing-... This worked for me. I think MacOS installation was a bit hands on due to Mac weirdness (when I did it ~2 years ago), but I think it is better now.
- omginternets 4y agoYes, this is what I tried too. What you describe as “hands on” is precisely what my original complaint is about. It was even more difficult (impossible?) for me due to the case-sensitive FS setting being enabled on my Mac. Everything about first contact with Nix is off putting. I really wish it weren’t so :/
- omginternets 4y agoSo what’s the simplest way to start using nix on macOS? Again, I am convinced Nix is a superior way to write software, and I would love nothing more than to have a working installation in a few minutes.
- ParetoOptimal 4y ago> Christ that's a lot of work, just to start working on work. If you already have a Nix based development environment, it's much less work and more reliable than patching something worse up with homebrew.
- colordrops 4y agoTotally, this post is doing a disservice to Nix.
- pxc 4y agoI think that's a bit unfair to the author, whose goal is clearly to document their own setup on a didactic way rather than to say > here, paste this into your terminal for the easiest way to get up and running with Nix in a fashion that's representative of community common practices I think it's a good blog post which, carefully read, teaches lots of useful things about Nix in a pretty concise way. It's totally fair to point out that this doesn't represent a path of least resistance to enjoying the benefits of Nix. But I don't love the way your short comment kinda frames the blog post's job as doing something for Nix, either, you know? I don't like the idea of this guy or anyone else feeling punished or chastised when their Nix-related blog posts become visible because those posts don't function as good marketing for Nix. Having a post about your Nix journey blow up should yield encouraging responses from fellow Nix users, right?
- colordrops 4y agoThe post directly says that the easy path is more complicated, which just isn't true. It will dissuade new users from even trying Nix. That is a disservice.
- xyzzy_plugh 4y agoI don't know if it should. Like this is neat and all but it's incredibly overcomplicated and for any readers unfamiliar with the tooling (which is most) it's off-putting. If the audience was Nix users, then it would be different. It's kinda like if you bought a fancy new camera and demonstrated your process but all your photos were out of focus, framed badly and lit poorly because you're into that for some reason. Would fellow fancy new camera enthusiasts cheer? Would folks who don't know about your fancy new camera think it's a good camera?
- SAI_Peregrinus 4y agoThat seems like a hell of a lot more work than just using Home-Manager and flakes. Flakes add a lot of boilerplate, but this seems excessive in comparison. And Home-Manager is quite easy.
- qbasic_forever 4y agoYeah this post is basically how to build your own wrapper around nix to manage your Mac user environment because you didn't like some of the decisions the nix maintainers made. It's easier to just install nix following its directions and then exclusively use nix-shell or nix develop (with flakes) to activate development environments with specific tools. Kind of like a python virtual environment on steroids. Forget entirely about managing your user's global tools and packages unless or until you want to do that, you could just keep using homebrew!
- ratorx 4y agoEven managing global/user packages is fine, if you want parity with a normal package manager. nix-env is pretty simple to get started with. Managing that declaratively is slightly more challenging. That’s when you need to understand the Nix language and use something like home-manager or the file approach in the blog post. But at this point, Nix is competing against something like Ansible/Puppet and not a standard package manager.
- pxc 4y agoThis blog post follows IanTheHenry's method for declarative environments via nix-env, which was produced when Ian was following a methodology for learning Nix that deliberately eschewed engagement with the Nix community in favor of relying only on the official documentation. So it doesn't use flakes or any unofficial community tools that could make setup 'easier' in the sense of being a bit more ready-made. Anyway I don't think there's anything really wrong with it. There are also other options for people who are hesitant to try flakes or home-manager if they don't like this one for some reason, though. The most common one is a named package based on buildEnv in your packageOverrides or in an overlay. (There's an example of this on the unofficial NixOS wiki, in the FAQ.) And of course home-manager is usable without flakes.
- dcchambers 4y agoThis post focused solely on the Nix package manager and Nix packages - for anyone that uses MacOS but is interesting in trying NixOS (or using it within a VM in MacOS), I definitely recommend Mitchell Hashimoto's NixOS repo: https://github.com/mitchellh/nixos-config https://github.com/mitchellh/nixos-config Honestly, doing that may be easier and a better option than using Nix packages in MacOS.
- gurjeet 4y ago> Honestly, doing that may be easier and a better option than using Nix packages in MacOS. Respectfully, I disagree. I’ve been using Nix on a couple of my Macs, including on an M1, and I’ve cutdown my dependence on homebrew almost to the point of its absence; I rely more on Nix packages, than on Homebrew packages. Having said that, I still wouldn’t recommend anyone using Nix; steep learning curve, and too many rough edges.
- smoldesu 4y agoNix is one of those rocket-powered chainsaw tools that you run into, and while it still scares me (and I often worry about accidentally cutting off a limb), it's much nicer to use than Homebrew. The only caviat is that your Nix store can get enormously huge, which is a big problem on Apple devices where storage comes at a premium.
- yjftsjthsd-h 4y agoI would naively expect that if you run garbage collection on a regular basis that it should take no more space. Is that not true, or is running it on a regular basis the sticking bit?
- smoldesu 4y agoI suppose you could, but Nix (and NixOS) defaults to keeping packages for an insane amount of time. 3 months of regular Nix use can accrue ~300gb of packages, which is definitely not what you'd have on something like Homebrew.
- frogperson 4y agoThere is absolutely no way I can recommend using this at work. Nix is way too complicated. Its already bad enough being the git goto person. Nix is so complicated it somehow makes git look simple.
- colordrops 4y agoI completely disagree. It took me a while to work through the peculiarities of NixOS and get my OS setup, but the benefits are immense now that I'm using it. And I'm using it as a daily driver at a large tech company developing and maintaining mission critical systems. It's really no different from Vim in this respect. Most people will bounce off due to the learning curve, but once you get past it, the benefits are too great to go back to a more crude system. In fact it was easier to learn and setup than Vim for me.
- mistahchris 4y agoThis has been my experience as well. I was nervous to start depending on NixOs for my work, but when I started at a new company ~2 years ago, I decided that was a good time to dive in. I have absolutely not regretted it. My setup is far less troublesome than any of my coworkers managing a bunch of different python versions for various python applications on macos.
- baby 4y agoSays the only person using vim
- revscat 4y ago> benefits are immense Such as?
- colordrops 4y agoRolling release; entire config stored in git, allowing for reproduceable setup - I can get a new machine the exact same state in 30 minutes with a few KB in config. Super easy rollback if I break something. Never wondering if something is gonna break with an update. Never wasting time trying to figure out how I set something up before, because it's explicitly declared in config. Standard config language for everything across the system. Ability to roll your own OS in any shape you like. Much easier package creation than RPM or debs. Decentralized composable config - you can pull from many git repos to build your system. Ability to have multiple versions of packages and libs installed at once. Immutable file system except for home folder and a few other paths. Ability to set up temporary dev environments and package installs. With every change I make, the system only gets more stable, predictable, and reliable, which is the exact opposite of every Linux distribution I've ever user before, which had to be wiped and reinstalled every couple years, after which I'd have endless struggle sessions getting everything set up. I'll never go back.
- ParetoOptimal 4y agoThe best way to use Nix in MacOS is through qemu and utm in my opinion. Then again, I don't like much about macs except the touchpad and macOS annoys me. So this advice might not hold as true if you actually like OSX. Maybe checkout: https://github.com/LnL7/nix-darwin https://github.com/LnL7/nix-darwin I'd also advice using flakes to simplify a lot of this.
- mistahchris 4y agoI agree. I've mentioned this elsewhere in this thread, but I just wanted to second that I've found running nixos as a vm through UTM has been a flawless experience for me. I have a fairly complicated setup for a bunch of different machines that I am able to manage through one flake. I have no desire to ever go back to a not-fully-declarative setup again.
- tambourine_man 4y agoI hope Docker is not the final answer to reproducible and isolated processes because it’s a bit too complex and slow on anything other than Linux, IMO. Linux virtualization almost became a mandatory feature of a modern OS because of it. I wish there was something that would run on any POSIX, but that’s probably not enough ground to cover complete reproduction.
- armchairhacker 4y agoMy hope is that a lot of the difficulty in getting reproducible builds is caused by outdated libraries and techniques. For example, assuming that your code is in /usr/bin or /usr/lib, so any package manager has to emulate that. My hope is that eventually, you can just run `cargo build --reproducible` or `meson build --reproducible` or `make --reproducible`, and if your architecture is the same, the dependencies will be the same and the output will run exactly the same. Even going as far as to install an older cargo or meson or CMake if that's what's needed for backwards compatibility. And if you want to be safe, you can create a sandbox or "jail" and libraries will know how to deal with it instead of just crashing when they try to access something outside.
- 3836293648 4y agocargo build --locked There is a lockfile, even if it's not respected by default. Doesn't help with build.rs being able to do whatever it wants but it's better than default
- IshKebab 4y agoI don't think that will ever really work reliably for something like cargo or meson. They don't really go to any effort to ensure clean build environments, enforce dependencies, sandbox builds etc. You need something like Bazel for that really.
- jitl 4y ago“Docker but it’s just a chroot”?
- 4y ago
- pxc 4y ago> Usually, your terminal emulator will create a login shell by default when you open a new terminal window. (Apple Terminal and iTerm2 both do.) And that’s generally the only time you create a login shell. On a Linux system, login shells are only invoked when you actually create a new session which doesn't come from an existing session belonging to the same user. In other words, you get the when - you switch to a 'real' TTY and log in manually - you log in via your GUI session manager (GDM, SDDM, etc.) - you log in remotely, e.g., via SSH But not when you open a new terminal emulator window. You can't just run `login` as your normal user inside a terminal emulator and get a new session either. You can check this with `finger` or `loginctl list-sessions`. On macOS, those things do get you new sessions which are shown by `finger`. I wonder whether the difference reveals a macOS quirk or a Linux quirk.
- lgas 4y agoWow I don't know what's crazier... that OS X still has finger or that it's had it this whole time and I never noticed. I remember fondly the early days of the internet when "finger `cat /etc/passwd`@remotehost" and other similar types of exploits had ridiculously high hit rates. And of course no shadowed password files yet.
- pram 4y agoI think this is because launchd+getty and systemd+agetty are doing something similar in those circumstances? They're both opening pseudo-terminals with the login command. That is to say, opening Terminal.app connects to a 'network' PTS much like SSH does, afaict.
- pxc 4y agoYeah but I wonder why. (Invoking `login` at the CLI in Terminal.app yields the same result as opening a new tab on macOS.) Trying the same on Linux says you have to be root, and does not log you in. Anyone got a Linux distro configured differently that they can explain, or a *BSD they care to try and compare on? Is there any reason (security, 'correctness') to prefer one way over the other?
- jitl 4y agoWhy hasn’t anyone built a clone of npm/npx UX that uses Nix under the hood? I hear so much about how ideal the Nix model is, and how bad NPM is. It seems like this should be “easy”. What gives?
- jbboehr 4y agoHave you seen pnpm[0]? Has some similarities. > Files inside node_modules are cloned or hard linked from a single content-addressable storage Also (IIRC, it's been a long while) it's lockfile contains enough information to translate it directly to a Nix derivation[1]. [0]: https://pnpm.io/ https://pnpm.io/ [1]: https://github.com/nix-community/pnpm2nix https://github.com/nix-community/pnpm2nix
- pxc 4y agoThey're talking about a frontend for Nix that uses a simple subcommand interface with a UX focus, but which is about Nix, not seeking a Nix-like backend for NPM. (I misread their comment the same way as you did the first time :)
- mongol 4y agoPerhaps what is missing is the book "Nix - The good parts". Not saying Nix is not good overall, but getting a condensed description what is worth knowing, leaving out what can be ignored or is obsolete, would be quite valuable.
- xyzzy_plugh 4y agoHere you go: - don't use nix-env ever - enable and use the new nix command (nix3) - enable and use flakes - use home-manager - if on macOS, use nix-darwin - with flakes, freely use nixpkgs unstable (stable is still useful, but flakes provide their own stability through pinned versions).
- baby 4y agoI’m looking at nix-darwin but there is no explanation on what it actually does https://github.com/LnL7/nix-darwin https://github.com/LnL7/nix-darwin
- viraptor 4y agoIt's like a system-wide home-manager alternative for Darwin systems. Or the other way - a NixOS-like whole system management that works on top of Darwin. For some examples: you can manage your homebrew packages, set keyboard preferences, trackpad settings, updates, finder defaults, etc through the nix config.
- Kaze404 4y agoAs a NixOS user, this sounds awesome! Thank you
- xnyanta 4y agoCheck out its manual to discover all of the configuration options you can set. https://daiderd.com/nix-darwin/manual/index.html#sec-options https://daiderd.com/nix-darwin/manual/index.html#sec-options
- 4y ago
- jherdman 4y agoSomething not mentioned here is that each and every single macOS update will break your Nix install too. This is, by far, the most frustrating part of using Nix on macOS.
- mistahchris 4y agoThis is true, but in my experience it has mostly been pretty easy to deal with. Generally it's just a matter of re-linking /etc/zprofile and friends to the ones from the nix-darwin installer (if you're using nix-darwin, which I would recommend).
- quag 4y agoI was surprised recently when upgrading from Catalina to Monterey and all the nix stuff just kept working. It was the first time a major macOS hasn’t broken nix. Does anyone know if this update was a fluke?
- xyzzy_plugh 4y agoThis hasn't been true in my experience. I've been running Nix on macOS for nearly a year without problems.
- deleted 4y ago[deleted]
- pyjamafish 4y agoCould you elaborate on what broke when you updated macOS? Granted, my Nix installation is a single-user installation (so it doesn't have the edited /etc/bashrc and /etc/zshrc that get overridden), but it worked without any issues after I updated from Big Sur to Monterey, so I'm curious about your experience. The only things that broke for me after the update were the xcode command-line tools, which break for everyone[1]. [1](https://stackoverflow.com/questions/32893412/command-line-tools-not-working-os-x-el-capitan-sierra-high-sierra-mojave/ https://stackoverflow.com/questions/32893412/command-line-to...)
- abathur 4y agoI imagine GP is talking about every macOS update forcibly overwriting /etc/zshrc. They bothered writing a system capable of dropping the conflicted file in Relocated Items for us to optionally use--but they appear to be only using it for /etc/bashrc, and not /etc/zshrc. So, people who use zsh by choice or default get dumped on a bit :/ Some background in https://github.com/NixOS/nix/issues/3616 https://github.com/NixOS/nix/issues/3616
- soasme 4y agoThis is my approach: running NixOS on macOS using UTM. https://youtu.be/8gytY4ITSDA https://youtu.be/8gytY4ITSDA
- xyzzy_plugh 4y agoThis is a pretty unusual set up. The title should probably be "how I use Nix on macOS". For folks unfamiliar with Nix, this is a fairly atypical and complicated setup. It's honestly pretty smooth sailing normally.
- baby 4y agoI have tried using nix for weeks on macOS and it’s been a really painful experience. I’ve pretty much given up. I don’t think they care much about user experience tbh.
- ParetoOptimal 4y agoDid you use an approach like the blog or one with nix-darwin, home-manager, and flakes? Not trying to convince you to try again since you seem done, but want any prospective nix users to know which approach you found painful. And if you don't mind, a list of the most painful things that should be improved.
- santicalcagno_2 4y agoI've been using a NixOS VM through VSCode's remote SSH extension for almost a year for all my dev work, and it's been working more or less flawlessly. I haven't had the need to install homebrew in the host macOS yet. Here's my approach: https://calcagno.blog/m1dev/ https://calcagno.blog/m1dev/
- gbrindisi 4y agovery nice! I stumbled on your post right after submitting this, thanks a lot for sharing I’m gonna try this out
- d12bb 4y agoOr I can just use Homebrew with a Brewfile. Sure, not nearly as powerful, but does the job..
- 0x69420 4y agohi, nix on macos user dropping in to deliver a PSA for the non-nixer macos users amongst you reading this article: * you are correct to be terrified * you are correct to think “this is a demented amount of busywork; who in their right mind would do this to themselves?” * you should know that this is a highly atypical setup that does a staggering number of things by hand for no discernible reason * normal people just install https://github.com/LnL7/nix-darwin https://github.com/LnL7/nix-darwin on top of standard nix and enjoy about the same lack of janitorial work as macports/homebrew users, relative to whatever the hell this guy is doing * please don't be scared off nix by this article
- x0rg 4y agoDo you have a more real world example of a darwin-configuration.nix? I want to see how this looks like and maybe hear about experiences with it longer term.
- 0x69420 4y agoi would just link you mine but this is a pseudonymous account; however: most nix-darwin users i know have a darwin-configuration.nix that's nearly identical to the one the installer plops down for you, with the exception of more items under `environment.systemPackages`, and using nix-darwin solely as a declarative alternative to nix-env is totally viable other than a few built-in service configurations and plist defaults, darwin-configuration.nix typically grows much as configuration.nix does on nixos. define or modify a couple packages here and there, shove them into `pkgs` by setting `nixpkgs.overlays`, etc etc. the ux is intentionally very similar to that of nixos what this means is you can look at a lot of people's nixos config repos and get some idea of what you can do just as well with nix-darwin i can, however, offer you my anecdote: nix-darwin has let me completely forget that brew and macports exist, and even let me get away without installing xcode at all -- it's perfectly competent at “getting a suite of dev tools onto a macbook”, but what really sold me on it was just how straightforward adding a new package is: mypkgs $ bc <<<$(cat *.nix | wc -l)/$(ls | wc -l) 32 that's an average of 32 lines to go from “obscure thing that literally nobody packages” to “bona fide part of my system”, and that includes meta blocks with homepage/description/etc, because i periodically try and get some of this stuff merged into mainline nixpkgs the language itself is a little quirky and the evaluation model of the module system is somewhat fraught with fixed-point knot-tying fuckery, but between the process of packaging being so nice and brew/macports pissing me off, i found it easy to drink enough koolaid to get to grips with those aspects i've been using nix-darwin and for almost exactly one year, and replaced all my linux installs with nixos, and i have not looked back whatsoever
- lycos 4y agoI'm actually trying out Nix on a fresh Mac install since this week, but I'm not yet sure if I enjoy it. When things work it feels pretty great, documentation feels lacking though so when I want to do something I haven't done yet I generally try to find examples of something similar. I do think I'm beginning to understand the language better that reading the source nix files almost become the docs for me. The main problem I have is when I try to install a package that fails to install, usually it has to compile. Like today I tried watchexec on my M1, doesn't work. Luckily I can just download a binary watchexec build to get around it but it would be nice to know how to get it working. Worked with homebrew. (but homebrew has it's own problems) The other thing is that I like the idea of using nix-shell for projects, but I hoped they would be more isolated than they appear to be. It's possible for example to have files in a user directory which will be accessible to all projects and package versions I'm using. It hasn't become a problem yet in my testing so far though. Reading other comments I decided I will also play with running things in a VM with NixOS. Maybe I'll end up with a mix of local Nix for some basic stuff and then a development VM.
- Kaze404 4y agoNix shell isn't supposed to provide file system isolation. It is a package manager after all, so what it does best is give a consistent dev environment with isolated dependencies. At that point if the program access mutable state and you want to prevent it (to a reasonable degree), you should use Docker or do it through the command line (like making $HOME point to somewhere else).
- lycos 4y agoOh yeah are definitely right there, I honestly don't know where the expectation came from because it makes perfect sense that it doesn't do that. Why would it. I think it was more me saying "would've been nice.". I'm coming from homebrew + asdf, but so far Nix appears to be working fine for me. I think asdf has a lot of custom config to try and isolate version-specific shared files/modules etc. I can replicate it by setting some environment variables myself in nix shell file though. I've got my basic home manager setup (still need to migrate some manually managed files to nix config) and every project I work on is now running with their own shell.nix file. No huge problems yet, aside from the mentioned watchexec failing. Not yet sure if I'll keep it in my regular workflow, it's been an interesting experience and I would be happy to not need homebrew anymore. (Might just try ports too). I'm also curious to see how fast new versions of software will be added/supported, so I'll have to at least keep this running until that happens.
- jrmurray 4y agoNix as a home brew replacement without using homemanger/nix Darwin is not a great sell to me imo. Using flakes and using it for project dependencies though is amazing and quite easy to use imo. We decided to use it at my job for a new project and it's been pretty amazing https://link.medium.com/DwIGVmRZ6rb https://link.medium.com/DwIGVmRZ6rb