diff options
author | github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> | 2022-01-20 18:01:55 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-20 18:01:55 +0000 |
commit | aeb6db8171d63f9db06449c6062c4e922bc740f8 (patch) | |
tree | 282b9789c9954c15d6b066b8d4e6f8c9bd94a8ff /nixos/lib | |
parent | 464d6108b0c5fefbf881a077823a3fbd1d6d0416 (diff) | |
parent | ce88a19065b1619cebde2b3b7d72e37e50eebc8d (diff) | |
download | nixpkgs-aeb6db8171d63f9db06449c6062c4e922bc740f8.tar nixpkgs-aeb6db8171d63f9db06449c6062c4e922bc740f8.tar.gz nixpkgs-aeb6db8171d63f9db06449c6062c4e922bc740f8.tar.bz2 nixpkgs-aeb6db8171d63f9db06449c6062c4e922bc740f8.tar.lz nixpkgs-aeb6db8171d63f9db06449c6062c4e922bc740f8.tar.xz nixpkgs-aeb6db8171d63f9db06449c6062c4e922bc740f8.tar.zst nixpkgs-aeb6db8171d63f9db06449c6062c4e922bc740f8.zip |
Merge staging-next into staging
Diffstat (limited to 'nixos/lib')
-rw-r--r-- | nixos/lib/default.nix | 33 | ||||
-rw-r--r-- | nixos/lib/eval-config-minimal.nix | 49 | ||||
-rw-r--r-- | nixos/lib/eval-config.nix | 12 |
3 files changed, 90 insertions, 4 deletions
diff --git a/nixos/lib/default.nix b/nixos/lib/default.nix new file mode 100644 index 00000000000..2b3056e0145 --- /dev/null +++ b/nixos/lib/default.nix @@ -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 + ; +} diff --git a/nixos/lib/eval-config-minimal.nix b/nixos/lib/eval-config-minimal.nix new file mode 100644 index 00000000000..d45b9ffd426 --- /dev/null +++ b/nixos/lib/eval-config-minimal.nix @@ -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; +} diff --git a/nixos/lib/eval-config.nix b/nixos/lib/eval-config.nix index 00e58e24e92..e3eb88a60eb 100644 --- a/nixos/lib/eval-config.nix +++ b/nixos/lib/eval-config.nix @@ -33,6 +33,12 @@ let pkgs_ = pkgs; in let + evalModulesMinimal = (import ./default.nix { + inherit lib; + # Implicit use of feature is noted in implementation. + featureFlags.minimalModules = { }; + }).evalModules; + pkgsModule = rec { _file = ./eval-config.nix; key = _file; @@ -70,11 +76,9 @@ let }; allUserModules = modules ++ legacyModules; - noUserModules = lib.evalModules ({ - inherit prefix; + noUserModules = evalModulesMinimal ({ + inherit prefix specialArgs; modules = baseModules ++ extraModules ++ [ pkgsModule modulesModule ]; - specialArgs = - { modulesPath = builtins.toString ../modules; } // specialArgs; }); # Extra arguments that are useful for constructing a similar configuration. |