What does HackerNews think of home-manager?
Manage a user environment using Nix [maintainer=@rycee]
1. Start learning with https://zero-to-nix.com/
2. Take a look at https://github.com/nix-community/home-manager
Good luck!
My system looks like any other install of Ventura, but all of my configuration, ranging from the terminal and VS Code to macOS-specific system preferences and Safari, is done declaratively in Nix [1]. The overwhelming majority of my installed software also comes from Nix packages, with some exceptions for stuff that is not packaged yet (e.g., I have Podman Desktop, the macOS ZFS port, Lulu, yubikey-manager-qt installed through Homebrew -- fortunately nix-darwin [2] also just lets me have an set of brews/casks in my config).
It was been a bit of a nightmare at first since the error messages are kind of horrific, and there can be a lack of good examples/docs on flakes. But I think the weekend worth of time I invested was worth it since I no longer need to rely on hacky shellscripts or remember to manually configure anything.
[1]: https://nixos.org/
The idea is that instead of creating a bunch of dotfiles and having to read a bunch of documentation, one declaratively states which features they want, say, for zsh or vim or git or xdg, etc; and then home-manager will create and manage them (typically they live in `$HOME/.config/whatever`).
https://github.com/nix-community/home-manager. Some examples on GitHub: https://github.com/search?q=filename%3Ahome.nix.
- VS code (working mostly on Typescript projects these days)
- Emacs for org mode / note taking
- Jetbrains Rider for Game dev
- nvim for, well, vi.
2. Build / Test / Deploy - My mac is completely managed by a Nix / home-manager[1] setup that delegates to homebrew for some apps.
- I add a flake.nix to all projects and use the nix devShell[2] with direnv extension to create development environments with custom commands. I played with the flix language[3] (on JVM) briefly and my nix based workflow worked quite well.
- I use lima with nerdctl[4] for containerization when required. I have a stalled experiment to use VSCode devcontainers[5]. I unfortunately didn't take notes on that experiment so I don't have a lot to share. All I can remember is that the integration to VSCode was quite impressive but trying to get the ergonomics of my local environment replicated required significant effort.
- CI: github actions
[1]: https://github.com/nix-community/home-manager
[2]: https://github.com/numtide/devshell
[3]: https://flix.dev
[4]: https://github.com/lima-vm/lima
[5]: https://containers.dev/overview[1]: https://github.com/nix-community/home-manager [2]: https://code.visualstudio.com/docs/remote/containers#_person...
https://github.com/nix-community/home-manager
I use it on NixOS. It should absolutely work on other distros unfortunately I don't have any first hand experience with that or with what the best way is to set it up on other distos (I think there are few options for how to do it).
But there were a few problems with it: - installed packages needed to be managed separately (the mechanisms for which varied by platform) - managing differing configs for different machines (e.g. headless servers, hardware quirks) was done by managing different branches of this repo and rebasing, which was a pain - it was generally brittle and hard to change
I've started to use https://nixos.org/ and it's been like night and day: https://github.com/RyanGibb/nixos/
My config is version controlled, reproducible, manages packages, and is very composable.
Using the nix package manager and https://github.com/nix-community/home-manager this should work on other Linux distributions, MacOS, and even Windows Subsystem for Linux. Although I haven't tried this for myself yet.
[0] https://github.com/nix-community/home-manager
[1] https://github.com/siraben/dotfiles/blob/bad2e8a29b6622e10bc...
1. For per-user configuration there is home-manager which symlinks dotfiles to Nix store based on a single "home.nix" derivation (state). Home-manager is usable outside of NixOS and, in my opinion, it is better than most dotfiles managers. https://github.com/nix-community/home-manager
2. In NixOS /etc is composed in the same way from the system derivation.
3. Outside of NixOS, I think, one can build systemd units which refer directly to configuration files in Nix store. Probably one can add config paths into wrappers, but it will be very fragile and won't scale.
Overtime the best configuration tended to be just using the defaults because getting used to a tmux.conf on one machine would just become an annoyance one I was on a machine without it. (Plus now you need to use about 12 different configuration languages :))
A huge advantage Nix has over any other configuration tool is that is a single source of truth. A normal dotfiles repo doesn't know anything about the actual programs or OS so it's very easy for it to become incompatible with a machine's actual state.
On Nix, tools like home-manager [1] especially when used in a flake-template like devos [2] just solves this problem really well. It's very easy to make a change, switch to the new configuration, and then commit the change. Managing bespoke services and scripts is very easy because one file in Nix can create a service with a script's contents, create a user, install necessary packages, etc.
I think (desktop) Linux is partly a niche market because the management can be very complex. Nix is certainly very complex itself but its structured enough that it can create very simple systems. There are already several NixOS based OS's that are basically just configuration templates. I could certainly see a more user-friendly distro being released using Nix as the foundation.
[1] https://github.com/nix-community/home-manager [2] https://github.com/divnix/devos
https://github.com/nix-community/home-manager
> or /var, so that's on you to back up, migrate, whatever.
> I too bought the story that being able to re-emerge my whole system was some kind of performance or configuration boon. Eventually I realized that I just wanted to use my computer to get through life...
I don't have fun constantly mucking with my settings either. That novelty long wore off long ago, like with most people who have used Linux 10+ years.
I do however get a benefit being able to set up my same config on multiple machines. For example, recently, I switched from XMonad to sway on my work computer, which necessitated a bunch of config changes. I then synced those changes over to my personal machine with https://github.com/nix-community/home-manager .
C.f. my phone just died, and I got a new android, and the android backup/sync situation gets worse and worse, and it will be a huge pain in the ass fixing my phone so i can hopefully move a few more account settings, 2FAs, etc. over.
The moral of the story is that when I do need to configure something, I want to do it once. Sysadmining repetitively is infuriating.
-----
The linker thing is quite different. I still do like programming (as opposed to sysadmining) for fun, and I want the tools to suck less. I also find infrastructure fun and interesting, be it computer or real world. I am a fairly prolific contributor to the Nix ecosystem, not because what I necessary want to do by myself on my own machine, but simply because I enjoy making the stuff better (and this hobby also sometimes becomes current task on the job, too).
Nix starts from a strong baseline of "sound" builds --- anything that is not sand-boxed, and therefore unlikely to be reproducible / cached correctly now pisses me off a shitty software that doesn't respect by time. The goal is to build on that foundation and also make Nix builds more incremental, so we have both a reliable and tight debug loop. Ultimately I want to see my work and the Nix community at large swamp the rest of the computing world with the productivity that is unleashed and when we stop crippling ourselves with shitty tools.
The flip side is that since goal is social, I have 0 interest in solo dog-fooding. I only use my PRs which I merged upstream; whatever benefits they would bring are certainly outweighed by the costs of living on forks all by oneself.
-----
If not being totally relatable (I rarely find people interested infra changes that don't immediately benefit them) hopefully it is at least clearly distinct from "building out my person nerd terrarium" customizing the computer as individualistic self-expression.
It's been amazing for me. Especially when combined with home-manager [1], which provides declarative user environments and flakes [2], which provide a even more declarative and more easily shareable package format.
Getting my exact setup on a new device - including lots of GUI and terminal app customization - takes a single `nixos-rebuild-switch`, and works every time. Everything is configured in a single config file, from hardware and system service setup, over window manager setup, all the way to installed Vim/VS Code/Chrome plugins and lots of application configs.
The ability to easily roll back to previous configurations and boot into old configs from the boot menu in case something breaks is also brilliant.
You can also just install and run pretty much all software on demand, similar to `npx`, without polluting the system. ( nix run some-app). Declarative, reproducible development environments for each project are the cherry on top.
That said, the onboarding experience is horrible. There are A LOT of things to learn, and the documentation is bad. I also agree that the language, while somewhat fine, is not great and very undiscoverable.
The Nix ecosystem is a diamond in the rough. Sadly it would take a lot of effort to simplify everything and make it more polished.
I'm afraid Nix will continue to remain very niche.
[1] https://github.com/nix-community/home-manager [2] https://nixos.wiki/wiki/Flakes
Otherwise, I would recommend looking at home-manager, it's essentially NixOS but for any linux distro, or even darwin with nix-darwin. https://github.com/nix-community/home-manager
Having spent years on Arch and Gentoo, imo the NixOS community is outstanding even among 'advanced' Linux distros in terms of expertise and kindness.
I'll never forget one time I was having problems with a Python package generation tool and when I mentioned it on IRC, and one of its authors (Rok Garbas, who is so quite active in the community) just hopped on a call to debug the issue I was having right then and there.
If you're on the fence about Nix and that kind of community is valuable to you, make sure to check out the forums [1] and realtime chat [2] (the latter of which is unfortunately still in the process [3] of migrating away from Freenode).
If personal assistance/mentorship of the kind I described at the beginning of this post is appealing to you, several generous and knowledgeable community members host Nix ‘office hours’ [4]. I'm not sure who all are still running them, but I know tomberek is for sure [5] and you can find a link in the footnotes.
There is one serious problem with NixOS and the wider ecosystem right now, namely that the best experience available depends on Nix features that are unreleased. Nix makes it very easy to run bleeding edge builds of Nix and enable these features, but the unofficial status of it all has slowed adoption, integration, and documentation of these tools in the wider community.
That aside— i.e., if you're willing to be a little bit of a pioneer— the community is on the whole pretty rich with good documentation of everything but the bleeding edge, unreleased bits at this point. Those pieces mostly impact the CLI and specifying inputs to the expressions you use to define your system. Everything in the NixOS and Nixpkgs manuals is still accurate. The unreleased components are also fairly mature despite their unofficial status: many folks in the community have been using them for a year or two now.
Finally: if you're interested in dipping your toes in without committing to a system fully managed by Nix and you're a macOS user, nix-darwin [6] provides a pretty NixOS-like experience using a module system and CLI based on NixOS'. There's nothing equally complete in terms of managing system services in a declarative fashion on non-NixOS Linux, but home-manager [7] provides some functionality for enabling user-mode services in a declarative style.
You can check whether your favorite software is packaged for Nix here [8], and additionally NixOS does support several other forms of cross-distro packaging/deployment, including Flatpak, AppImage, and Docker. Steam support is native and works without much fuss, too.
---------
1: https://discourse.nixos.org/
2: https://matrix.to/#/!MKvhXlSTLGJUXpYuWF:nixos.org
3: https://github.com/NixOS/rfcs/pull/94
4: https://discourse.nixos.org/search?q=office%20hours
5: https://discourse.nixos.org/t/nix-office-hours/11945
6: https://github.com/LnL7/nix-darwin
Pros:
* Better, more coherent and unified tooling
* Better docs
* Built with LISP (edit: Scheme), A standard language that is not project-specific. Nix lang is somewhat quirky and takes some getting used to. It's pretty decent though for a narrowly focused domain language.
Cons:
* Tiny community that is much smaller than Nix. nixpkgs is the largest package repository out there, providing most software that you could want.
* Really slow every time I tried it. Nix is written in C++ and actually performs quite well, even when building many hundreds of pacakges.
* Not systemd based. Say of systemd what you will, but there is a reason almost every distro has adopted it. It's just better. Also: most Linux users are familiar with systemd tooling by now, so that makes adoption even harder.
* Strong focus on freedom and not packaging proprietary software. Understandable, given the project origins. But awkward to the point of being mostly impractical for personal use - I can't package everything myself.
* No equivalent to home-manager [1], which is amazing for declarative user environments
[1] nixos.org/
But I think the main barrier to running Docker from Nix on non-NixOS is the lack of a systemd unit file or other init system configuration in Nixpkgs. Nixpkgs just doesn't have any facilities for that atm and afaict no one is working on them right now. There are definitely precursors to that functionality in:
• the NixOS module system, which provides exactly this functionality for NixOS, where the module system is in charge of configuring systemd
• home-manager, a module system like NixOS which adds support for systemd user services on non-NixOS: https://github.com/nix-community/home-manager
• nix-processmgmt, an experimental Nix framework for writing Nix expressions to describe services to be managed by a range of process managers that may or may not be PID 1 (which means the could be usable on non-NixOS): https://github.com/svanderburg/nix-processmgmt
• nix-darwin, a module system for macOS that provides some NixOS functionality, including managing services: https://github.com/LnL7/nix-darwin
The discussion on the service abstraction layer for Nixpkgs/NixOS is also very relevant. It shows that there has been interest in something like this for many years, but it's never quite come together: https://github.com/NixOS/nixpkgs/issues/26067
I wouldn't assume it's just around the corner or inevitable. It is a really exciting possibility, though, and the nix-processmgmt framework seems like something that could evolve into a service abstraction layer for Nixpkgs that could make facilities for managing services available in a uniform way even on non-NixOS Linux.
I also use GNU stow in my dotfiles[1] especially so that my setup still works on systems without Nix installed.
There is, it’s called home-manager [1] and it’s a pretty nice way to manage your config files and user packages even if you’re not on a NixOS system.
I've been using it on all my personal devices for ~6 months and also for some bare metal sever deployments.
A (mostly) immutable system configured with a single config file is an absolute killer feature.
The ability to roll back to a previous config in the bootloader or the terminal is brilliant.
And home-manager [1] provides the same experience for your user environment.
I also looked into Guix, but the community and package repository seem much smaller.
They also don't accept proprietary software in the official package repo. Which is a respectable ideological choice, but really reduces usability a lot compared to nixpkgs.
A functional language, a package manager and an operating system.
I switched all my desktops and laptops to NixOS at the beginning of the year, and I'm starting to use introduce it at multiple companies for data science / ML work environments with full reproducibility and Kubernetes bare metal deployments.
Main benefits:
* pure build system
* extremely easy way to set up and switch between custom environments with their own sets of dependencies (nix-env, nix-shell)
* nix (the package manager) is cross-platform and works on MacOS and other Linux distros (although that's not always smooth sailing...)
* Ephemeral environments that are quickly set up and torn down, like the `nix-shell --packages vlc --run "vlc https://dash.nixcon.net/dash/master.m3u8"`
* (mostly) fully reproducible OS and user environments
* patching and/or locally building dependencies without ending up with a messy system
I can now finally get a (almost) 100% reproducible user environment including hardware configuration (kernel modules, disks, ...), installed packages, configurations, ...
home-manager [1] even enables declarative configuration of things like VS Code/Vim/Firefox plugins, and provides statically typed configuration options for many applications. The package repo is also very comprehensive.
For manually managed servers that aren't just bootstrapped from VM/cloud images the benefits are also wonderful.
It's definitely not all smooth sailing though:
* There is documentation, but it's spread across a lot of pages, disorganized and sometimes quite outdated or incomplete. I often have to read the source code - which is also mostly undocumented.
* Running unpackaged software: you can't just download binary releases and run them, unless they are fully statically linked (like most Go binaries). Instead you either have to whip up a package definition, or manually try to get the binary working (eg with patchelf)
* The language is somewhat quirky. As often the case with such niche languages, documentation and tooling are very subpar and debugging is not exactly a joy. I wish Nix was built on a more common language with good tooling around it. I bet it would be quite a bit more popular, due to the lower barrier of entry. You get used to it though if you are willing to put in some effort.
* Package ecosystem: the package repo is really comprehensive, but maintainership for some less popular ones is not up to Arch + AUR levels. Also the auditing for a lot of the packages is very limited. For any security critical environments or server deployments I would definitely limit myself to a hand full of core packages and/or be prepared for manual auditing. I wish the repo was split up more like Arch into core and community, with different guarantees for auditing and maintenance. (the Flakes effort will hopefully help here quite a bit)
All in all Nix is great though, and it's impressive how stable and featureful the ecosystem has become, despite being somewhat of a niche "product".
I would imagine that you could use Home Manager on a non-NixOS system to at least create reproducible configs for the programs you use, although the OS as a whole would of course still be non-reproducible. However, I do not know how well Home Manager works on non-NixOS systems.
As you mention, just using Nix itself can be sufficient to get a reproducible set of packages on your system. I recall reading a blog post about someone who does this on both Ubuntu and MacOS.[1] The way this person does it is interesting because it’s more sophisticated than spawning the occasional ‘nix-shell’ or something. For example, they get the benefit of Nix “generations,” with a new generation being created each time they modify their declarative config files.
[0] https://github.com/nix-community/home-manager [1] https://www.nmattia.com/posts/2018-03-21-nix-reproducible-se...