Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lilyball opened this issue Dec 1, 2021 · 4 comments

Comments

@lilyball
Copy link

lilyball commented Dec 1, 2021

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
Copy link
Owner

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
Copy link

@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
Copy link
Author

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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants