nix-env -u すると名前衝突のエラーがでるがでる。解決したい。
nix-env を実行すると下記のようなエラーがでる。
warning: name collision in input Nix expressions, skipping '/home/xxx/.nix-defexpr/channels_root/nixpkgs'
おそらく nixpkgs が複数登録されていると思われる。
channels_rootというディレクトリはマルチユーザモードの場合にrootユーザのチャンネルを参照するためのもののようだ。
~/.nix-defexpr/channels
This is a symlink to /nix/var/nix/profiles/per-user/username/channels. It ensures that nix-env can find your channels. In a multi-user installation, you may also have ~/.nix-defexpr/channels_root, which links to the channels of the root user.
https://nixos.org/manual/nix/stable/command-ref/nix-channel.html
ルートユーザではない場合に生成される様子が伺える
code: cc
if (getuid() != 0)
replaceSymlink(
fmt("%s/profiles/per-user/root/channels", settings.nixStateDir),
globals.instSource.nixExprPath + "/channels_root");
https://github.com/NixOS/nix/blob/a0b517de5796d9a82b18242ecc63f507869237b1/src/nix-env/nix-env.cc#L1390-L1393
つまり、nixpkgsというチャンネルがrootと自分が登録したチャンネルで2つあり、競合していると考えるのが自然
code: shell
$ nix-channel --list
nixpkgs https://nixos.org/channels/nixpkgs-unstable
$ cat ~/.nix-defexpr/channels_root/manifest.nix
[ { meta = { }; name = "nixpkgs"; out = { outPath = "/nix/store/mwvlfhmhzmq9d7bb2s606gy0dj7w5b9d-nixpkgs"; }; outPath = "/nix/store/mwvlfhmhzmq9d7bb2s606gy0dj7w5b9d-nixpkgs"; outputs = "out" ; system = "builtin"; type = "derivation"; } ]
$ cat ~/.nix-defexpr/channels/manifest.nix
[ { meta = { }; name = "nixpkgs"; out = { outPath = "/nix/store/y0cjq40dardpg6xsqnbysb9m5h0kxmg7-nixpkgs"; }; outPath = "/nix/store/y0cjq40dardpg6xsqnbysb9m5h0kxmg7-nixpkgs"; outputs = "out" ; system = "builtin"; type = "derivation"; } ]
このように複数のチャンネルがあるにも関わらず名前が同じになってしまっている。
解決案
案1 自分固有のnix-channelを登録しない
rootを参照することになるはず。しかし、rootのchannel更新はどうすればできるのだろうか
sudo nix-channel --update と sudoをつければよい。つけない場合は更新されないので注意が必要
案2 自分固有のchannelは競合しないように名前を変える
インストール時にチャンネルを明示する必要があるかもしれない
案3 気にしない
おそらくユーザのものが優先されるため警告を気にしなければよい