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

treewide: add checks for nix.enable #1332

Merged
merged 12 commits into from
Feb 14, 2025
Merged

Conversation

emilazy
Copy link
Collaborator

@emilazy emilazy commented Feb 11, 2025

Things that expect a managed Nix installation should have a corresponding assertion so that we don’t incorrectly use the default nix.package when the user has opted out of Nix management or otherwise interfere with use of an unmanaged system Nix. NixOS had some of these checks already but I didn’t catch them when backporting the functionality in the initial PR; others are in modules only present in nix-darwin, or else should probably be upstreamed to NixOS at some point. Also fix some miscellaneous other bugs where we were incorrectly using the managed defaults or assuming the guaranteed presence of an active Nix installation even when nix.enable was turned off. See commit messages for more details.


Note: This work was funded by Determinate Systems.

This was added to Nixpkgs in eb8b70c020e6693b29634660fa173d7f14f882eb.
This was added to Nixpkgs in eb8b70c020e6693b29634660fa173d7f14f882eb.
When we’re not managing the Nix installation, these defaults
aren’t used out of the box and won’t accurately represent the
state of any unmanaged Nix or the desired Nix package, so reading
the option defaults is a bug.

This was previously a warning for `nix.package` and a silent failure
for all the others. Now that all the problematic accesses in nix-darwin
have been appropriately conditionalized, and since a throw gives a
backtrace where a warning doesn’t, give throwing defaults to all the
`nix.*` options that don’t reflect reality and that that modules
shouldn’t be reading when `nix.enable` is off.

I’m not in love with the implementation strategy here… ideally
we’d think of something better than this and then upstream it to
NixOS. `nix.nrBuildUsers` growing a fake default that is never used
is particularly unfortunate. But this should hopefully catch mistakes
in module code reasonably reliably.
When `nix.enable` is off, we don’t necessarily have an active
Nix installation, so there won’t necessarily be an active
`/nix/var/nix/gcroots` directory to link things into. NixOS just skips
this unconditionally when `nix.enable` is off, but that doesn’t
work well with a context in which we usually expect `nix.enable`
to be coupled with an unmanaged system installation of Nix.
@emilazy emilazy merged commit 678b226 into LnL7:master Feb 14, 2025
3 checks passed
@emilazy emilazy deleted the push-vyxwvkuuvvvw branch February 14, 2025 15:50
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.

2 participants