Hello, I’m in the process of migrating from dotfiles to home-manager and have a question about how program installation is handled by home-manager.
For example I want to have git installed system wide but also configure it through home-manager. What I found out on the internet is, that home-manager will also install git and both installations of git (the system wide installed one and the one in the user profile) are present in the PATH variable, but the one in the user profile takes precedence (because it’s appears earlier in PATH than the system wide installed one). I’m not sure if this is 100% correct, so please correct me if I’m wrong.
Now my questions:
If the above is true, is git really installed twice? Like does it actually take up twice the space?
Or does Nix detect that and create two symlinks (one for the system wide installed git and one for git in the user profile)?
If it’s actually installed twice, is there a way to prevent that? (Maybe even with Nix store deduplication as “last resort”?)
Nix doesn’t have to “detect” anything to keep it from being installed twice. The hash in a package’s /nix/store path is derived from the definition of the package. If two different things (e.g. NixOS and home-manager) use an identical definition, they get the same package. So as long as you’re using the same version of nixpkgs for both of them, they both just decide to use the same path by definition. And then yes, they both have their own mechanisms for setting up symlinks that ultimately appear on your PATH
Wow, thank you so much for your quick answer!
Now I understand how it works and that I don’t need to worry about packages being installed twice.
I’m fairly new to Nix but as far as I understand the following code in my flake.nix makes sure that the same version of nixpkgs is used:
Yes, for the most part. Nixpkgs configuration such as overlays can also change the package hashes, however, so if you set those, you’ll need to keep them the same too in order to be completely assured that everything is shared.
Yes. release-22.11 is for internal use by developers. nixos-22.11 automatically updates to match release-22.11 when hydra has built the packages and tests have passed. Never follow release-22.11 unless you know exactly what you’re doing. It creates subtle problems of various sorts you might not notice immediately.
That’s very interesting @R-VdP because I saw this option yesterday in the documentation but thought it was not necessary because I’ve never seen it in any tutorial or article. Does it replace inputs.nixpkgs.follows or do I have to use both in combination?
Thank you for the clarification. You’re absolutely right. I just checked the home-manager documentation and if home-manager is used as a NixOS module useGlobalPkgs = true is used.
I hope it’s ok to ask this kind of follow up question: I was planning on using home-manager as NixOS module but the home-manager documentation states, that home-manager does not explicitly support rollbacks. Does that affect the ability to select an older configuration in the boot menu if I screw something up?