Apologies in advance for dumping a lot here. This bothered me a bit too much after coming across it again this morning, and after finding a lot of somewhat related-ish issues, new and old, I found this thread and saw you had recently responded. I hope this is an alright place 
I still experience this behavior on Nix 2.24.12 (and I believe onwards, but I haven’t had the time to confirm yet) with that setup
Specifically, here’s the relevant section of my /etc/nix/registry.json
:
{
"exact": true,
"from": {
"id": "nixpkgs",
"type": "indirect"
},
"to": {
"path": "/nix/store/b19xi89pgm1arig3l9xqn1h81zjd1j91-source",
"type": "path"
}
},
And when running nix eval
:
This also ends up affecting the default $NIX_PATH
set by the same module
I believe this, nix copies inputs already in the nix store · Issue #11228 · NixOS/nix · GitHub, and maybe some of nix will pointlessly re-fetch registry entries if they are defined as store paths · Issue #7075 · NixOS/nix · GitHub are signs of an underlying issue that would be the culprit of what I came across in nixos/nixpkgs-flake: enable flakes in systems built from flakes, make ISO behave well by lf- · Pull Request #374460 · NixOS/nixpkgs · GitHub. It appears to have also worsened since Nix 2.18, with the source
path names workaround no longer functioning (I believe it still works in Lix)
My current workaround for this copying when using NIX_PATH
lookup paths (like <nixpkgs>
) is symlinking my Flake inputs to the top-level of my system derivation like so
{
lib,
pkgs,
inputs,
...
}:
let
flakeInputs = pkgs.linkFarm "flake-inputs" (
lib.mapAttrs (lib.const (flake: flake.outPath)) inputs
);
in
{
nix = {
nixPath = lib.mkForce (
lib.mapAttrsToList (name: lib.const "${name}=/run/current-system/inputs/${name}") inputs
);
};
system.extraSystemBuilderCmds = ''
ln -s ${flakeInputs} $out/inputs
'';
}
(Taken from my full config. There are no workarounds for Flakes being copied since they are seemingly always copied at least once)
This doesn’t completely solve the problem though, as even when using files (from $NIX_PATH
lookup paths, plain store paths, anything that’s not a Flake), this behavior will still show up in nix develop
(and AFAICT, only nix develop
):
I’m not sure how recent this regression is, but I’m assuming it’s also from Nix 2.19+ as it doesn’t occur in Lix (I am able to confirm this on Lix 2.91.1 and 2.92)
I also want to CC @jade in case they’re interested and have the time, as this is fairly related to the issues we were discussing in the aforementioned module PR. Hopefully we can apply some workarounds on the NixOS side so people are less likely to come across these issues until they’re fixed upstream