diff --git a/lib/release-tools.nix b/lib/release-tools.nix index 8101c884..61e4fe3d 100644 --- a/lib/release-tools.nix +++ b/lib/release-tools.nix @@ -1,19 +1,8 @@ { pkgs ? import {} }: let - # Original `evalConfig` - evalConfig' = import "${pkgs.path}/nixos/lib/eval-config.nix"; - - # Specialized `evalConfig` which injects the _mobile-nixos special arg. - evalConfig = args@{ specialArgs ? {}, ... }: evalConfig' (args // { - specialArgs = specialArgs // { - _mobile-nixos = { - inherit evalConfig; - path = ../.; - }; - }; - }); + evalConfig = import "${toString pkgs.path}/nixos/lib/eval-config.nix"; in { # This should *never* rely on lib or pkgs. diff --git a/modules/lib.nix b/modules/lib.nix new file mode 100644 index 00000000..664515eb --- /dev/null +++ b/modules/lib.nix @@ -0,0 +1,35 @@ +{ config, lib, pkgs, baseModules, modules, ... }: + +let + # Keep modules from this eval around + modules' = modules; + + inherit (config.nixpkgs.localSystem) system; + + # We can make use the normal NixOS evalConfig here. + evalConfig = import "${toString pkgs.path}/nixos/lib/eval-config.nix"; +in +{ + lib = { + mobile-nixos = { + # `config.lib.mobile-nixos.composeConfig` is the supported method used to + # re-evaluate a configuration with additional configuration. + # Can be used exactly like `evalConfig`, with one additional param. + # The `config` param directly takes a module (attrset or function). + composeConfig = { config ? {}, modules ? [], ... }@args: + let + filteredArgs = lib.filterAttrs (k: v: k != "config") args; + in + evalConfig ( + filteredArgs // { + # Needed for hermetic eval, otherwise `eval-config.nix` will try + # to use `builtins.currentSystem`. + inherit system; + inherit baseModules; + # Merge in this eval's modules with the argument's modules, and finally + # with the given config. + modules = modules' ++ modules ++ [ config ]; + }); + }; + }; +} diff --git a/modules/module-list.nix b/modules/module-list.nix index 7bb96356..2c99e53d 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -32,6 +32,7 @@ ./initrd-vendor.nix ./initrd.nix ./internal.nix + ./lib.nix ./luks.nix ./mobile-device.nix ./nixpkgs.nix