Live data from Hacker News

Using Nix on macOS

checkoway.net

71–80 of 116 posts

Re: Using Nix on macOS

#71

Earlier quoted context omitted.

For all of my personal machines, I use NixOS (both hardware and in cloud machines). But for work, we have a soft-MacOS mandate. On that m1 macbook pro, I run nix-darwin for the mac specific settings I want, and packages that I run in macos, but everything else in a NixOS VM similar to mitchellh/nixos-config. I use UTM (a nice wrapper around qemu), but the rest is just standard nix config, of which, nearly all of it I…

Thanks for pointing out mitchellh/nixos-config. Do you have a config published for nixos with UTM? I’m having a heck of a time getting the screen resolution and font sizes where I want them and I’m kind of lost.

Yep. Note that there's nothing you need to do to configure display resolution in UTM / qemu. You do need the spice guest tools installed in your nixos vm though. The only thing you should need to do is set the resolution in whatever display manager you use in nixos. For me, I run the sway window manager. My display manager is kanshi.

Here's my config: https://git.sr.ht/~averagechris/dotfiles

Here's a branch that I has some aarch64 specific things in it that I'm using for my guest vm config (I will merge it into the main branch when I get an hour or two so this link might die at some point) https://git.sr.ht/~averagechris/dotfiles/tree/aarch64-work-v...

Here's the link to my display manager config https://git.sr.ht/~averagechris/dotfiles/tree/aarch64-work-v...

Re: Using Nix on macOS

#72

Earlier quoted context omitted.

I 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?

I 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.

Can't you just run nix-collect-garbage?

Re: Using Nix on macOS

#73

I'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/

very nice! I stumbled on your post right after submitting this, thanks a lot for sharing I’m gonna try this out

Re: Using Nix on macOS

#75

There 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.

Nix is like Javascript. It's really simple under the hood, so everyone ends up rolling their own "framework".

(Not a bad thing, just be aware that Nix is for when you need DIY development environment infrastructure and don't have the budget to keep a team of seven k8s specialists for the job.)

Re: Using Nix on macOS

#76
post #56
post #15

Earlier quoted context omitted.

> 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…

Yeah, I switched completely to nix after being frustrated with homebrew constantly breaking things (any time I installed something. (Usually involving libicu being replaced with a different version.) And then had to pick up homebrew again for a couple of things. I _really_ like being able to drop into a shell with a few additional packages installed. But nix does have a learning curve and some rough edges. I found it…

The only time things break for me because something is replaced by homebrew is because c/c++ projects seem to so overly rely on dependencies (headers, .a files, etc.) being installed by the os globally. Maybe this is better when the project uses Bazel instead of make/(auto)configure.

Re: Using Nix on macOS

#77
post #57
post #7

Earlier quoted context omitted.

I 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 manag…

People say that but yet nobody linked to a post explaining the “right way” of using nix on macOS

Here 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...

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.

Re: Using Nix on macOS

#78

I 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.

My 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…

I 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.

Re: Using Nix on macOS

#79
post #56
post #15

Earlier quoted context omitted.

> 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…

Yeah, I switched completely to nix after being frustrated with homebrew constantly breaking things (any time I installed something. (Usually involving libicu being replaced with a different version.) And then had to pick up homebrew again for a couple of things. I _really_ like being able to drop into a shell with a few additional packages installed. But nix does have a learning curve and some rough edges. I found it…

I switched to Nix because, unlike Homebrew, it does not include silent Google spyware.

Re: Using Nix on macOS

#80
post #63

Earlier quoted context omitted.

Here 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).

And you do this to install MySQL?

It’s a lot of upfront work sure, but afterward installing any package (including MySQL) is just appending the package name to a list in your config file. The powerful part is that uninstalling the package is as simple as deleting it from that list.

Or if you don’t want to install the package permanently and just want it for a one-off job, `nix-shell -p mysql` starts a shell with mysql on your path, which will disappear as soon as you exit the shell.

Post reply on HN