-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Use envvars NIX_CACHE_HOME, NIX_CONFIG_HOME, NIX_DATA_HOME, NIX_STATE_HOME if defined #11351
Conversation
Why does Nixsa need separate variables for this? Can it not substitute in a wrapper for |
I think it will basically work, however the problem is that Nix can run other commands, certainly when using |
I'm not sure if Could you document these environment variables in |
Thanks for the suggestion, it makes a lot of sense. It's such a good suggestion, that it raises a question. I looked at |
@roberth Ok, I dug a bit in the code. From what I see, So, I don't want to touch Therefore, I don't think that the suffix I still think that the Another alternative can be What do you think? |
I didn't realise the names collided. Sorry for the red herring.
Also reasonable. I think I'm fine with either of your proposed naming schemes. |
@roberth sorry it took me so long. I updated What are the next steps? Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very thoughtful change, thank you @noamraph.
It's notable enough that I'd ask you to add a release note with motivation and a link to the documentation section that changed.
As motivation, I liked this part in your PR description:
This provides more fine-grained control over where Nix looks for files, and allows to have a stand-alone Nix environment, which only uses files in a specific directory, and doesn't touch any global user configuration.
Other than that I think this is good to merge.
Co-authored-by: Valentin Gagarin <[email protected]>
Co-authored-by: Valentin Gagarin <[email protected]>
@fricklerhandwerk Thanks! I committed your suggestions, they improve my text. I added a changelog. How does it look? |
Motivation
Currently Nix uses the XDG environment variables
XDG_{CACHE,CONFIG,DATA,STATE}_HOME
for locating files. I suggest to also look for environment variablesNIX_{CACHE,CONFIG,DATA,STATE}_HOME
, and if they exist, use them instead of the XDG_* ones.This allows more fine-grained control over where Nix looks for files. This allows to have a stand-alone Nix environment, which only uses files in a specific directory, and doesn't touch any global user configuration. Specifically, this makes Nixsa possible, a project I'm working on, which allows you to extract a tarball and immediately get a standalone working Nix environment.
Context
A detail: Nix always uses the
nix
directory inside theXDG_*_HOME
variables (for example, the profile is at$XDG_STATE_HOME/nix/profile
, the configuration is at$XDG_CONFIG_HOME/nix/nix.conf
). IfNIX_*_HOME
is defined, there's no point in adding/nix
to it.This means that this PR can be split into two simpler commits (let me know if you want me to modify it): one commit which is pure refactoring, which makes the
get*Dir()
functions return directories ending with/nix
, and a second commit which makes theget*Dir()
functions first look for aNIX_*_HOME
envvar.I don't see any backwards-compatibility issues with this change, since if the
NIX_*_HOME
envvars don't exist the behavior doesn't change.Priorities and Process
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.