-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Global vs per-user profiles and channels
The motivation for this is basically explained in the contribution guide, as guidance on how to design features like this going forward. In short, I think it is confusing for operations acting on the default profile to *always* do something different based on whether the user is regular or root. Instead, this makes there be flags which are (from the vantage point of today) "do the root default" vs "do the regular user" default. This make the situation teachable: we can point to the flags, and the conditional default, as *exactly* what varies between the root and non-root cases. And by manually specifying enough flags, we can ensure those defaults are overridden and Nix will indeed do the same thing (or fail trying). This is similar to the logic behind the supplementary group setting (#8342), which I also discuss in this new section of the contribution guide as a second example. Instead of creating the default dirs in `getDefaultProfile` (which is a bit odd if the symlink points elsewhere), create the profile dir for the chosen profile in `createGeneration`. That seems more appropriate and keeps the test added in e997512 (where the profiles are deleted but the symlink isn't) working.
- Loading branch information
1 parent
056afb7
commit d2f2c46
Showing
16 changed files
with
356 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Configuration guidelines | ||
|
||
## Don't just autodetect the environment | ||
|
||
Nix can be run in a variety of different ways with different permissions. | ||
Regular users and the super user ("root") can run Nix. | ||
Nix can be be run inside other tool's sandboxes too. | ||
|
||
It can be tempting to try to "make Nix work" by changing what it does based on what permissions we have. | ||
E.g. if there is some operation we don't think will work as a regular user, we might skip it as `getuid() != 0`. | ||
|
||
The problem with just doing this, however, is that it creates more uncertainty for the user. | ||
Nix operations are supposed to be reproducible, but if we start "bending the rules" based on how Nix is run, it gets increasingly likely that an operation would succeed with different results. | ||
|
||
The compromise is as follows: | ||
|
||
1. Whenever one wants to condition some operation on an expression like `getuid() != 0`, instead condition it on a boolean setting. | ||
|
||
2. Make the setting's default value the condition one would have used. | ||
|
||
This still provides the convenience of trying to make things work, but it congregates those suspect impure conditionals in just a select few places, namely where the settings re defined. | ||
This makes it easy to, at glance, see all the ways the current environment influences what is being done. | ||
|
||
> In the future we plan on making the default expressions (e.g. not just the values they might happen to evaluate to, like just `true` or `false`) show up in the docs for the settings, so finding all such settings as described above is in fact easy. | ||
> Consulting the source code to get this information should not be necessary. | ||
It also makes it easy to ensure that things like `getuid()` cannot matter, by explicitly forcing all those options with conditional defaults one way or the other. | ||
|
||
### Examples | ||
|
||
- The default profile | ||
|
||
The default profile is a user-specific one for regular users, but the global one for root. | ||
Rather than just having a conditional method when looking up its path, instead be able to (unconditionally) look up either a per-user or global profile. | ||
Expose both options, but if neither is explicitly chosen, only then make the choice of which option based on `getuid() == 0`. | ||
|
||
- [`require-drop-supplementary-groups`](@docroot@/command-ref/conf-file.md#conf-require-drop-supplementary-groups) | ||
|
||
We always want to drop as many permissions as possible when performing builds, to prevent the derivation being built from doing things we do not expect and do not want it to do. | ||
Part of this is dropping "supplementary groups", which are groups in addition to a user's "primary group". | ||
For non-root users we do not expect this to succeed, because special privilages are required to do this (see the setting for details). | ||
For root users so do expect this to succeed, but inside Linux user namespaces the "fake" root we have may still fail. | ||
|
||
Rather than conditionally attempt this operation on whether we are root, we always attempt it, and conditionally abort the build if we get a permission error. | ||
(Other non-permission errors are still abort the build unconditionally.) | ||
Furthermore the condition to ignore the permission failure here is not directly based on `getuid() == 0`, but instead `require-drop-supplementary-groups`. | ||
Rather, that setting is defaulted based upon `getuid() == 0`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.