-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Add minimal NixOS entrypoint #153211
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
Merged
Merged
Add minimal NixOS entrypoint #153211
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fbd038e
nixos/lib: init (experimental)
roberth be3967e
nixos/nixpkgs.nix: Make independent
roberth e31e096
nixos/lib: Move evalModules into its own file
roberth 25caf73
nixos/eval-config: Layer on top of nixos/eval-config-minimal
roberth d3f956a
nixos/lib: Add featureFlags, use it for minimal modules
roberth 3168017
nixos/lib: Clarify that nixos.evalModules impl is NOT experimental
roberth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,33 @@ | ||
| let | ||
| # The warning is in a top-level let binding so it is only printed once. | ||
| minimalModulesWarning = warn "lib.nixos.evalModules is experimental and subject to change. See nixos/lib/default.nix" null; | ||
| inherit (nonExtendedLib) warn; | ||
| nonExtendedLib = import ../../lib; | ||
| in | ||
| { # Optional. Allows an extended `lib` to be used instead of the regular Nixpkgs lib. | ||
| lib ? nonExtendedLib, | ||
|
|
||
| # Feature flags allow you to opt in to unfinished code. These may change some | ||
| # behavior or disable warnings. | ||
| featureFlags ? {}, | ||
|
|
||
| # This file itself is rather new, so we accept unknown parameters to be forward | ||
| # compatible. This is generally not recommended, because typos go undetected. | ||
| ... | ||
| }: | ||
| let | ||
| seqIf = cond: if cond then builtins.seq else a: b: b; | ||
| # If cond, force `a` before returning any attr | ||
| seqAttrsIf = cond: a: lib.mapAttrs (_: v: seqIf cond a v); | ||
|
|
||
| eval-config-minimal = import ./eval-config-minimal.nix { inherit lib; }; | ||
| in | ||
| /* | ||
| This attribute set appears as lib.nixos in the flake, or can be imported | ||
| using a binding like `nixosLib = import (nixpkgs + "/nixos/lib") { }`. | ||
| */ | ||
| { | ||
| inherit (seqAttrsIf (!featureFlags?minimalModules) minimalModulesWarning eval-config-minimal) | ||
| evalModules | ||
| ; | ||
| } | ||
This file contains hidden or 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,49 @@ | ||
|
|
||
| # DO NOT IMPORT. Use nixpkgsFlake.lib.nixos, or import (nixpkgs + "/nixos/lib") | ||
| { lib }: # read -^ | ||
|
|
||
| let | ||
|
|
||
| /* | ||
| Invoke NixOS. Unlike traditional NixOS, this does not include all modules. | ||
| Any such modules have to be explicitly added via the `modules` parameter, | ||
| or imported using `imports` in a module. | ||
|
|
||
| A minimal module list improves NixOS evaluation performance and allows | ||
| modules to be independently usable, supporting new use cases. | ||
|
|
||
| Parameters: | ||
|
|
||
| modules: A list of modules that constitute the configuration. | ||
|
|
||
| specialArgs: An attribute set of module arguments. Unlike | ||
| `config._module.args`, these are available for use in | ||
| `imports`. | ||
| `config._module.args` should be preferred when possible. | ||
|
|
||
| Return: | ||
|
|
||
| An attribute set containing `config.system.build.toplevel` among other | ||
| attributes. See `lib.evalModules` in the Nixpkgs library. | ||
|
|
||
| */ | ||
| evalModules = { | ||
| prefix ? [], | ||
| modules ? [], | ||
| specialArgs ? {}, | ||
| }: | ||
| # NOTE: Regular NixOS currently does use this function! Don't break it! | ||
| # Ideally we don't diverge, unless we learn that we should. | ||
| # In other words, only the public interface of nixos.evalModules | ||
| # is experimental. | ||
| lib.evalModules { | ||
| inherit prefix modules; | ||
| specialArgs = { | ||
| modulesPath = builtins.toString ../modules; | ||
| } // specialArgs; | ||
| }; | ||
|
|
||
| in | ||
| { | ||
| inherit evalModules; | ||
| } |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -64,6 +64,11 @@ let | |
| in | ||
|
|
||
| { | ||
| imports = [ | ||
| ./assertions.nix | ||
| ./meta.nix | ||
| ]; | ||
|
|
||
| options.nixpkgs = { | ||
|
|
||
| pkgs = mkOption { | ||
|
|
||
This file contains hidden or 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,8 @@ | ||
| { evalMinimalConfig, pkgs, lib, stdenv }: | ||
| lib.recurseIntoAttrs { | ||
| invokeNixpkgsSimple = | ||
| (evalMinimalConfig ({ config, modulesPath, ... }: { | ||
| imports = [ (modulesPath + "/misc/nixpkgs.nix") ]; | ||
roberth marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| nixpkgs.system = stdenv.hostPlatform.system; | ||
| }))._module.args.pkgs.hello; | ||
| } | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Are you sure this is the right place for evaluating NixOS? I'd have expected this to be in
nixos/default.nix(but I know that place is already used). Maybe someone else has a good idea but this location makes it seem like importing that file gives me library functions around NixOS and not NixOSThere 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.
It is not great, I admit, and as you've noted that's mostly due to
nixos/default.nixbeing taken. I've considered turning the existingnixos/default.nixinto a__functor, but I've seen the command line tools behave weird around__functorand I don't want to touch such an essential file for an experimental feature.I've also considered
nixos/eval-config.nix. While familiarity is good, it is too easily confused withnixos/lib/eval-config.nix, which behaves rather differently, both wrt module list and a ton of legacy behavior we don't need.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.
What about
nixos/minimal-eval.nix?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.
nixos/minimal-eval.nixdoes sound less confusing. or maybenixos/lib/minimal-eval.nix? anything that doesn't break the pattern ofimport ./libpulling in all lib functions, really.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.
Actually, that's exactly what this is doing, when looking at the
flake.nixchange. Itslib.nixosis simply this file.So then it should be
lib/default.nixand the fact that the functions are about minimal evaluation is currently a coincidence.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.
from the angle of what the flake exports you're totally right. but there's a lot of other stuff in
nixos/lib(like that now-standard eval-config.nix) that isn't available fromimport ./nixos/lib. so i guess it's fine either way, and we retract the suggestion.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.
Right, I now better understand your suggestion. Depending on whether those are intended for "public" consumption, the functions in those other files can later be exposed through
nixos/lib/default.nixor moved to anixos/commondirectory where exposure is not desirable.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.
we have
nixos/lib/eval-config.nix, so I would proposenixos/lib/eval-config-minimal.nix. Alsonixos/lib/eval-config.nixshould be usingnixos/lib/eval-config-minimal.nix, so prove it is minimal and therefore the status quo cna be built on top of it.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.
I've moved the implementation as @Ericson2314 suggested, kept
nixos/lib/default.nixfor the purpose of beinglib.nixosin the flake and anyone who likes thelibstyle.I'm undecided whether it only proves a point or whether it should be a requirement. If we find a reason to disconnect the two, proving a point shouldn't stop us from doing that. I can imagine that we find a useful change along the way, that we don't want to apply to conventional NixOS, yet I do hope the two can remain as similar as possible.
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.
Yeah if we have need to direct them, sure. I am not yet familiar with the more ambitious plans discussed before.