feat(entrypoint): expose evalModules for external interop

e.g. colmena can make use of it to declare an heterogeneous set of
systems, mixing Liminix and NixOS systems.

Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
This commit is contained in:
Raito Bezarius 2024-04-21 20:34:39 +02:00
parent 00a99d16b5
commit 258c33f409
2 changed files with 33 additions and 13 deletions

View file

@ -18,24 +18,18 @@ let
}; };
}); });
eval = pkgs.lib.evalModules { evalModules = (import ./lib/eval-config.nix {
specialArgs = { inherit nixpkgs pkgs;
modulesPath = builtins.toString ./modules; inherit (pkgs) lib;
}; });
eval = evalModules {
modules = [ modules = [
{ _module.args = { inherit pkgs; inherit (pkgs) lim; }; }
./modules/hardware.nix
./modules/base.nix
./modules/busybox.nix
./modules/hostname.nix
./modules/kernel
device.module device.module
liminix-config liminix-config
./modules/s6
./modules/users.nix
./modules/outputs.nix
]; ];
}; };
config = eval.config; config = eval.config;
borderVm = ((import <nixpkgs/nixos/lib/eval-config.nix>) { borderVm = ((import <nixpkgs/nixos/lib/eval-config.nix>) {
@ -54,6 +48,8 @@ let
]; ];
}).config.system; }).config.system;
in { in {
inherit evalModules;
outputs = config.system.outputs // { outputs = config.system.outputs // {
default = config.system.outputs.${config.hardware.defaultOutput}; default = config.system.outputs.${config.hardware.defaultOutput};
optionsJson = optionsJson =

24
lib/eval-config.nix Normal file
View file

@ -0,0 +1,24 @@
{ nixpkgs ? <nixpkgs>, pkgs ? (import <nixpkgs> {}), lib ? pkgs.lib }:
args:
let
modulesPath = builtins.toString ../modules;
in
# FIXME: we could replace the `lib` by a lib-only minimal nixpkgs.
(import "${nixpkgs}/lib/modules.nix" { inherit lib; }).evalModules (args // {
specialArgs = (args.specialArgs or {}) // {
inherit modulesPath;
};
modules = (args.modules or []) ++ [
"${modulesPath}/hardware.nix"
"${modulesPath}/base.nix"
"${modulesPath}/busybox.nix"
"${modulesPath}/hostname.nix"
"${modulesPath}/kernel"
"${modulesPath}/s6"
"${modulesPath}/users.nix"
"${modulesPath}/outputs.nix"
# FIXME: we should let the caller inject `pkgs` and `lim` ideally...
] ++ lib.optional (pkgs ? lim) {
_module.args = { inherit (pkgs) lim; };
};
})