Skip to content

Commit

Permalink
WIP: add eval-config interface
Browse files Browse the repository at this point in the history
  • Loading branch information
blaggacao committed May 18, 2024
1 parent a767b54 commit 553fa52
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 51 deletions.
65 changes: 14 additions & 51 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,59 +1,22 @@
{ configuration ? import ./configuration.nix
, nixpkgs ? <nixpkgs>
, pkgs ? import <nixpkgs> {
inherit system;
platform = platform;
config = {};
}
, extraModules ? []
, system ? builtins.currentSystem
, platform ? null
, crossSystem ? null }:

let
pkgs = import nixpkgs { inherit system; platform = platform; config = {}; };
pkgsModule = {config, ... }: {
_file = ./default.nix;
key = ./default.nix;
config = {
nixpkgs.pkgs = (import nixpkgs {
inherit system crossSystem;
#crossSystem = (import <nixpkgs/lib>).systems.examples.aarch64-multiplatform;
config = config.nixpkgs.config;
overlays = config.nixpkgs.overlays;
});
nixpkgs.localSystem = {
inherit system;
} // pkgs.lib.optionalAttrs (crossSystem != null) {
inherit crossSystem;
};
};
, crossSystem ? null
}: let
inherit (import ./eval-config.nix {
nixpkgs = pkgs;
inherit extraModules;
}) evalModules;
in rec {
test1 = evalModules {
modules = [configuration];
};
baseModules = [
./base.nix
./system-path.nix
./stage-1.nix
./stage-2.nix
./runit.nix
(nixpkgs + "/nixos/modules/system/etc/etc.nix")
(nixpkgs + "/nixos/modules/system/activation/activation-script.nix")
(nixpkgs + "/nixos/modules/misc/nixpkgs.nix")
(nixpkgs + "/nixos/modules/system/boot/kernel.nix")
(nixpkgs + "/nixos/modules/misc/assertions.nix")
(nixpkgs + "/nixos/modules/misc/lib.nix")
(nixpkgs + "/nixos/modules/config/sysctl.nix")
./ipxe.nix
./systemd-compat.nix
pkgsModule
];
other = {
_module.check = true;
_module.args = {};
};
evalConfig = modules: pkgs.lib.evalModules {
prefix = [];
modules = modules ++ baseModules ++ [ pkgsModule other ] ++ extraModules;
};
in
rec {
test1 = evalConfig [
configuration
];
runner = test1.config.system.build.runvm;
config = test1.config;
}
68 changes: 68 additions & 0 deletions eval-config.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{ nixpkgs
, baseModules ? import ./module-list.nix
, extraModules ? []
}:
let
nixos-lib = import (nixpkgs + /nixos/lib) {
featureFlags.minimalModules = true;
};

modulesModule = {
config = {
_module.args = {
inherit baseModules extraModules;
};
};
};

evalModules = {modules}: nixos-lib.evalModules {
prefix = [];
specialArgs = {
notOSmodulesPath = builtins.toString ./.;
};
modules = modules ++ baseModules ++ extraModules ++ [
modulesModule
];
};

/* This specifies the testing node type which governs the
module system that is applied to each node.
In our case, it needs to be the not os module set.
It also consumes the defaults set for all nodes as well as,
by convention of the nixos testing framework, node wise
specialArgs.
We ignore config.extraBaseModules, however:
use extraModules, instead.
*/
nodeType = {config, hostPkgs, ...}: {
node.type = (nixos-lib.evalModules {
prefix = [];
specialArgs = {
notOSmodulesPath = builtins.toString ./.;
} // config.node.specialArgs;
modules = [config.defaults] ++ baseModules ++ extraModules ++ [
modulesModule
./tests/test-instrumentation.nix
];
}).type;
};

evalTest = module: nixos-lib.evalTest {
imports = [
module
nodeType
];
};
runTest = module: nixos-lib.runTest {
imports = [
module
nodeType
];
};
in {
inherit evalModules evalTest runTest;
}
20 changes: 20 additions & 0 deletions module-list.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
let
nixos = path: {modulesPath, ...}: {
imports = [(modulesPath + path)];
};
in [
./base.nix
./system-path.nix
./stage-1.nix
./stage-2.nix
./runit.nix
./ipxe.nix
./systemd-compat.nix
(nixos "/system/etc/etc.nix")
(nixos "/system/activation/activation-script.nix")
(nixos "/misc/nixpkgs.nix")
(nixos "/system/boot/kernel.nix")
(nixos "/misc/assertions.nix")
(nixos "/misc/lib.nix")
(nixos "/config/sysctl.nix")
]

0 comments on commit 553fa52

Please sign in to comment.