gytis-ivaskevicius / flake-utils-plus

Use Nix flakes without any fluff.
MIT License
494 stars 54 forks source link

`generateNixPathFromInputs` should use a dir entry instead of per-flake entries #105

Closed lilyball closed 2 years ago

lilyball commented 2 years ago

generateNixPathFromInputs symlinks relevant inputs into /etc/nix/inputs and synthesizes a NIX_PATH with an entry for each input. I assume it does this so that way the NIX_PATH entries will always reference the current configuration without having to spawn a new shell. The downside is any additions/removals to the input set won't be reflected in existing shells.

Instead of adding one entry per input to NIX_PATH, it should just add a single entry for /etc/nix/inputs. This way it will always reflect the current state of the system regardless of what happens to the inputs.

gytis-ivaskevicius commented 2 years ago

I don't think I quite catch the issue here, could you elaborate? Maybe with help of few examples. Also adding /etc/nix/inputs would require it to contain default.nix?

I personally really do not care for NIX_PATH and I truly believe that it should get removed. I have added it for compatibility reasons in case you need nix-shell

ElvishJerricco commented 2 years ago

@gytis-ivaskevicius When you have a directory entry without a name in NIX_PATH, then its children become the entries, named after their file names. e.g. NIX_PATH=nixpkgs=/etc/nix/inputs/nixpkgs and NIX_PATH=/etc/nix/inputs both cause <nixpkgs> to evaluate to /etc/nix/inputs/nixpkgs. This is how nix-channel works; you have ~/.nix-defexpr/channels on your NIX_PATH (no foo= prefix), so all the channels it puts in that directory are available with <> syntax.

It's nice because it means you don't need to start a new shell session to get the updated NIX_PATH when you add a new input or remove one. Like if I removed home-manager from my inputs, then <home-manager> would no longer evaluate to /etc/nix/inputs/home-manager, without needing a NIX_PATH update.

lilyball commented 2 years ago

What @ElvishJerricco. And to be clear, you do not put a default.nix in the directory, and you do not give it a label.

Implementing this solution reuses your existing /etc/nix/inputs, and just means that the actual config value looks like

{
  nix.nixPath = mkIf cfg.generateNixPathFromInputs [ "/etc/nix/inputs" ];
}

This produces a NIX_PATH variable that looks like /etc/nix/inputs:/nix/var/nix/profiles/per-user/root/channels:/Users/lily/.nix-defexpr/channels. The new path works exactly like the two entries that were already there.

gytis-ivaskevicius commented 2 years ago

Thank you, I had no idea about this feature of nix