Nix copying a store-path into the store

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 :slight_smile:

I still experience this behavior on Nix 2.24.12 (and I believe onwards, but I haven鈥檛 had the time to confirm yet) with that setup

Specifically, here鈥檚 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鈥檛 completely solve the problem though, as even when using files (from $NIX_PATH lookup paths, plain store paths, anything that鈥檚 not a Flake), this behavior will still show up in nix develop (and AFAICT, only nix develop):

I鈥檓 not sure how recent this regression is, but I鈥檓 assuming it鈥檚 also from Nix 2.19+ as it doesn鈥檛 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鈥檙e 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鈥檙e fixed upstream