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

NIX_USER_CONF_FILES #3458

Merged
merged 1 commit into from Apr 15, 2020
Merged

NIX_USER_CONF_FILES #3458

merged 1 commit into from Apr 15, 2020

Conversation

zimbatm
Copy link
Member

@zimbatm zimbatm commented Mar 30, 2020

add NIX_USER_CONF_FILES

Motivation: maintain project-level configuration files.

Document the whole situation a bit better so that it corresponds to the
implementation, and add NIX_USER_CONF_FILES that allows overriding
which user files Nix will load during startup.

@domenkozar
Copy link
Member

The manual generation is currently failing. I tried understanding the error and bisecting the documentation and wasn't able to reduce the error to something actionable.

If this isn't a proof for NixOS/rfcs#64 then I don't know what is :)

@edolstra
Copy link
Member

edolstra commented Apr 1, 2020

It's actually the opposite: DocBook at least has a concept of an "error". Markdown is garbage in, garbage out.

@zimbatm
Copy link
Member Author

zimbatm commented Apr 1, 2020

I can fix the doc error with some more elbow grease. Can I get feedback on the PR instead? :D

@edolstra does the PR make sense to you overall?

@edolstra
Copy link
Member

edolstra commented Apr 1, 2020

@zimbatm Yes, makes sense. However it may make more sense to add an environment variable NIX_CONF_FILE so you don't need to create a directory just for your configuration file. (E.g. a per-project config file could be in <project-dir>/.nix.conf).

@edolstra
Copy link
Member

edolstra commented Apr 1, 2020

Or generalize this to a list of configuration files (e.g. NIX_CONF_FILES = my-project.conf /etc/nix/nix.conf ~/.config/nix/nix.conf ). After all, it may not be desirable to have the per-project config file completely override the user config file.

@lheckemann
Copy link
Member

What advantage does this have over using the existing XDG_CONF_DIRS support?

@edolstra
Copy link
Member

edolstra commented Apr 1, 2020

@lheckemann Good point, that might be the way to go.

@roberth
Copy link
Member

roberth commented Apr 1, 2020

@lheckemann

This is useful because sometimes it is desirable to be more selective than changing the config home of all XDG-respecting programs.

For example, you'll want your editor to read the usual configuration files.

@lheckemann
Copy link
Member

You don't need to change the config home (where programs write their config to), only add a dir to the config path (where they read their config from) — and if the extra entry in the config path only contains relevant config (i.e. nix config) it'll only affect nix.

@andir
Copy link
Member

andir commented Apr 1, 2020 via email

@roberth
Copy link
Member

roberth commented Apr 1, 2020

I was focused on NIX_USER_CONF_DIR so I didn't notice the plural in XDG_CONFIG_DIRS. This does seem adequate for most cases. If you don't want an extra ".config" directory in your project, it seems like you could generate it in a shell.nix dependency.

@zimbatm
Copy link
Member Author

zimbatm commented Apr 1, 2020

@lheckemann XDG_CONFIG_DIRS is loaded before XDG_CONFIG_HOME as per the XDG spec. If the user has set any configuration they will take precedence over XDG_CONFIG_DIRS.

Copy link
Contributor

@guibou guibou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if I'm authorized to approve, but this looks really nice and solves an important use case. Bonus point for documentation.

@zimbatm
Copy link
Member Author

zimbatm commented Apr 6, 2020

A variation on the XDG idea would be to push XDG_CONFIG_DIRS=$XDG_CACHE_HOME:$XDG_CONFIG_DIRS and then override XDG_CACHE_HOME=$PWD/config where $PWD is the project root. Unfortunately, the first thing I noticed is that git only implements the XDG spec partially and doesn't look at XDG_CONFIG_DIRS. So I think this PR is really needed.

@zimbatm zimbatm force-pushed the nix-user-conf-dir branch 3 times, most recently from 56ce053 to a1cba71 Compare April 6, 2020 19:24
@zimbatm
Copy link
Member Author

zimbatm commented Apr 6, 2020

I fixed the doc generation and added a minimal test. The last thing to address is @edolstra's comment on NIX_CONF_FILE and NIX_CONF_FILES (which make a lot of sense to me).

@zimbatm zimbatm force-pushed the nix-user-conf-dir branch 3 times, most recently from 4b13d54 to 62b0d3d Compare April 7, 2020 14:26
@zimbatm
Copy link
Member Author

zimbatm commented Apr 7, 2020

@edolstra the env has been renamed to NIX_CONF_FILES and now appends to the existing config paths.

@matthewbauer
Copy link
Member

Does this override the system configuration or just append to it? For instance, what happens when a local config has substituters = .... Is https://cache.nixos.org/ still loaded?

@zimbatm
Copy link
Member Author

zimbatm commented Apr 13, 2020

Keys get overridden and the last writer wins. For example, if /etc/nix/nix.conf sets the substituters key and ~/.config/nix/nix.conf as well, then the user config will take precedence. It's a valid concern but I think that should be handled in a separate PR as it extends the scope of the work and is not a new issue introduced by this PR.

@domenkozar
Copy link
Member

That's #2149

@zimbatm
Copy link
Member Author

zimbatm commented Apr 13, 2020

Who is able to give this PR another substantial review? Does it make sense how I changed the code structure to load all the config files?

<listitem>
<para>
And finally, every files pointed to by
<envar>NIX_EXTRA_CONF_FILES</envar>, separated by <literal>:</literal>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this implemented?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes? You can see it in action in the admittedly minimal test.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It only uses NIX_CONF_FILES, not NIX_EXTRA_CONF_FILES.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh ok. This is a typo. Fixed in 976ead5

@PkmX
Copy link

PkmX commented Apr 13, 2020

It also seems like the NIX_CONF_FILES as implemented are actually extra conf files that are read after $XDG_CONFIG_DIRS and $XDG_CONFIG_HOME, but I think @edolstra's comment about NIX_CONF_FILES is that it specifies the absolute list of conf files to be loaded ignoring $NIX_CONF_DIR/nix.conf and all users config files. This would fit my use case where my build system is essentially a wrapper over Nix and needs exact control over the config, and I don't want any system-wide or user-wide nix.conf to be loaded.

doc/manual/command-ref/conf-file.xml Outdated Show resolved Hide resolved
doc/manual/command-ref/conf-file.xml Outdated Show resolved Hide resolved
doc/manual/command-ref/conf-file.xml Outdated Show resolved Hide resolved
doc/manual/command-ref/conf-file.xml Outdated Show resolved Hide resolved
doc/manual/command-ref/conf-file.xml Outdated Show resolved Hide resolved
<para>
And finally, every files pointed to by
<envar>NIX_CONF_FILES</envar>, separated by <literal>:</literal>
if that environment variable exists.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is phrased awkwardly (it's the contents of NIX_CONF_FILE that's separated by :).

doc/manual/command-ref/env-common.xml Outdated Show resolved Hide resolved
doc/manual/command-ref/env-common.xml Outdated Show resolved Hide resolved
src/libstore/globals.cc Outdated Show resolved Hide resolved
src/libutil/util.hh Outdated Show resolved Hide resolved
@zimbatm zimbatm force-pushed the nix-user-conf-dir branch 3 times, most recently from 0a1fd9f to a648322 Compare April 14, 2020 16:44
@zimbatm zimbatm changed the title NIX_USER_CONF_DIR NIX_USER_CONF_FILES Apr 14, 2020
Motivation: maintain project-level configuration files.

Document the whole situation a bit better so that it corresponds to the
implementation, and add NIX_USER_CONF_FILES that allows overriding
which user files Nix will load during startup.
@zimbatm
Copy link
Member Author

zimbatm commented Apr 14, 2020

This is ready for another round of review.

  • I changed NIX_CONF_FILES to NIX_USER_CONF_FILES to be more specific and also indicate that it overrides the user configuration.
  • I changed the logic so that NIX_USER_CONF_FILES replaces the default locations where user config is being loaded. The system /etc/nix/nix.conf is still being loaded in any case as it plays a special role.
  • Fixed the docs, probably introduced some more language issues

@edolstra edolstra merged commit a118293 into NixOS:master Apr 15, 2020
@zimbatm zimbatm deleted the nix-user-conf-dir branch April 15, 2020 11:11
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

Successfully merging this pull request may close these issues.

None yet

9 participants