ryantm / home-manager-template

A quick-start template for using home-manager in a more reproducible way.
https://github.com/ryantm/home-manager-template
Creative Commons Zero v1.0 Universal
111 stars 5 forks source link

nix fails to record a dependency when home-manager is built this way #9

Open pdg137 opened 4 months ago

pdg137 commented 4 months ago

I noticed something weird about the way this installs home-manager. Starting with a fresh checkout of the repo:

$ git reset --hard
HEAD is now at 5725905 update nixpkgs-unstable, stop using nixpkgs-channels
$ nix-shell

[nix-shell:~/gitprojects/public/home-manager-template]$ type home-manager

home-manager is /nix/store/kh0l3n7aba7gqz1asspbb55pkgx2w1p1-home-manager/bin/home-manager

Let's look at what nix thinks the dependencies of home-manager are:

[nix-shell:~/gitprojects/public/home-manager-template]$ nix-store --query --references /nix/store/kh0l3n7aba7gqz1asspbb55pkgx2w1p1-home-manager/bin/home-manager

/nix/store/7fdm1ij6f7xwjmhpici1bh3xh08n0sp7-coreutils-8.31
/nix/store/98an38bw0fwk6a5mickblc0h07jf00vz-gnused-4.8
/nix/store/chs6kqcqk2vmzmrckaa11dvm3qljcdni-less-551
/nix/store/k8p54jg8ipvnfz435mayf5bnqhw4qqap-bash-4.4-p23
/nix/store/ny7vshs45d5k193ql3b51dak0hjwwqc2-findutils-4.7.0

But look, there's a store path in there that was not picked up:

[nix-shell:~/gitprojects/public/home-manager-template]$ grep home-manager-src /nix/store/kh0l3n7aba7gqz1asspbb55pkgx2w1p1-home-manager/bin/home-manager

    for path in "/nix/store/qxdxvvbcfh2b39hd52zj1n2f6s24vnsc-home-manager-src" \

[nix-shell:~/gitprojects/public/home-manager-template]$ 

I can reproduce this basic thing just by running nix-build https://github.com/nix-community/home-manager/archive/refs/heads/master.zip -A home-manager so it's not necessarily a problem with this repository. And it probably won't cause a problem with the way this repository is structured. But it means that if you set up a gcroot for home-manager and collect garbage, you'll be left with a broken home-manager. Or if you try to use nix-copy-closure to copy home-manager somewhere, it will fail to copy the "home-manager-src" path.

What's going on?

pdg137 commented 4 months ago

Here is my workaround for this strange issue:

https://github.com/pdg137/config/commit/8c3de2f5d475760e7dd224365feb5f59ae765cb4

This allows me to build a home-manager switch script that runs fine after a garbage collection and that I can copy to another machine with nix-copy-closure.

pdg137 commented 4 months ago

See https://github.com/nix-community/home-manager/pull/5174