https://github.com/numtide/system-manager/pull/136

Contents:

@r-vdp
Avoid rec
ac4a95a

@r-vdp
Avoid re-importing nixpkgs multiple times
21bd839

@r-vdp
Avoid building the application twice
8706306

@r-vdp
Run clippy as part of the check phase
ca50566

@r-vdp
flake.lock: Update
1d968fb

@r-vdp
Adapt systemd module after merge of NixOS/nixpkgs#311394
270e3f0

@r-vdp
Add nix-vm-test flake input
58dd3f9

@r-vdp
Merge remote-tracking branch 'origin/main' into reduce_flake_deps
a92a05f

@r-vdp
flake.lock: Update
9843716

Co-authored-by: r-vdp <ramses@well-founded.dev>
This commit is contained in:
Sofie 2024-10-29 11:55:28 +01:00
parent 37d944cc5f
commit c099b40594
No known key found for this signature in database
GPG key ID: C9E9DE9EDCD42BC1
6 changed files with 188 additions and 152 deletions

View file

@ -3,141 +3,141 @@
lib ? import "${nixpkgs}/lib",
nixos ? "${nixpkgs}/nixos",
}:
rec {
# Function that can be used when defining inline modules to get better location
# reporting in module-system errors.
# Usage example:
# { _file = "${printAttrPos (builtins.unsafeGetAttrPos "a" { a = null; })}: inline module"; }
printAttrPos =
{
file,
line,
column,
}:
"${file}:${toString line}:${toString column}";
let
self = {
# Function that can be used when defining inline modules to get better location
# reporting in module-system errors.
# Usage example:
# { _file = "${printAttrPos (builtins.unsafeGetAttrPos "a" { a = null; })}: inline module"; }
printAttrPos =
{
file,
line,
column,
}:
"${file}:${toString line}:${toString column}";
makeSystemConfig =
{
modules,
extraSpecialArgs ? { },
}:
let
# Module that sets additional module arguments
extraArgsModule =
{
lib,
config,
pkgs,
...
}:
{
_file = "${printAttrPos (builtins.unsafeGetAttrPos "a" { a = null; })}: inline module";
_module.args = {
pkgs = import nixpkgs { system = config.nixpkgs.hostPlatform; };
utils = import "${nixos}/lib/utils.nix" {
inherit lib config pkgs;
makeSystemConfig =
{
modules,
extraSpecialArgs ? { },
}:
let
# Module that sets additional module arguments
extraArgsModule =
{
lib,
config,
pkgs,
...
}:
{
_file = "${self.printAttrPos (builtins.unsafeGetAttrPos "a" { a = null; })}: inline module";
_module.args = {
pkgs = import nixpkgs { system = config.nixpkgs.hostPlatform; };
utils = import "${nixos}/lib/utils.nix" {
inherit lib config pkgs;
};
# Pass the wrapped system-manager binary down
# TODO: Use nixpkgs version by default.
inherit (import ../packages.nix { inherit pkgs; })
system-manager
;
};
# Pass the wrapped system-manager binary down
# TODO: Use nixpkgs version by default.
inherit
(import ../packages.nix { pkgs = import nixpkgs { system = config.nixpkgs.hostPlatform; }; })
system-manager
;
};
config =
(lib.evalModules {
specialArgs = {
nixosModulesPath = "${nixos}/modules";
} // extraSpecialArgs;
modules = [
extraArgsModule
./modules
] ++ modules;
}).config;
inherit (config.nixpkgs) pkgs;
returnIfNoAssertions =
drv:
let
failedAssertions = map (x: x.message) (lib.filter (x: !x.assertion) config.assertions);
in
if failedAssertions != [ ] then
throw "\nFailed assertions:\n${lib.concatStringsSep "\n" (map (x: "- ${x}") failedAssertions)}"
else
lib.showWarnings config.warnings drv;
servicesPath = pkgs.writeTextFile {
name = "services";
destination = "/services.json";
text = lib.generators.toJSON { } config.build.services;
};
config =
(lib.evalModules {
specialArgs = {
nixosModulesPath = "${nixos}/modules";
} // extraSpecialArgs;
modules = [
extraArgsModule
./modules
] ++ modules;
}).config;
etcPath = pkgs.writeTextFile {
name = "etcFiles";
destination = "/etcFiles.json";
text = lib.generators.toJSON { } { inherit (config.build.etc) entries staticEnv; };
};
# Get the system as it was defined in the modules.
system = config.nixpkgs.hostPlatform;
pkgs = import nixpkgs { inherit system; };
linkFarmNestedEntryFromDrv = dirs: drv: {
name = lib.concatStringsSep "/" (dirs ++ [ "${drv.name}" ]);
path = drv;
};
linkFarmEntryFromDrv = linkFarmNestedEntryFromDrv [ ];
linkFarmBinEntryFromDrv = linkFarmNestedEntryFromDrv [ "bin" ];
returnIfNoAssertions =
drv:
let
failedAssertions = map (x: x.message) (lib.filter (x: !x.assertion) config.assertions);
in
if failedAssertions != [ ] then
throw "\nFailed assertions:\n${lib.concatStringsSep "\n" (map (x: "- ${x}") failedAssertions)}"
else
lib.showWarnings config.warnings drv;
toplevel =
let
scripts = lib.mapAttrsToList (_: script: linkFarmBinEntryFromDrv script) config.build.scripts;
servicesPath = pkgs.writeTextFile {
name = "services";
destination = "/services.json";
text = lib.generators.toJSON { } config.build.services;
entries = [
(linkFarmEntryFromDrv servicesPath)
(linkFarmEntryFromDrv etcPath)
] ++ scripts;
addPassthru =
drv:
drv.overrideAttrs (prevAttrs: {
passthru = (prevAttrs.passthru or { }) // {
inherit config;
};
});
in
addPassthru (pkgs.linkFarm "system-manager" entries);
in
returnIfNoAssertions toplevel;
mkTestPreamble =
{
node,
profile,
action,
}:
''
${node}.succeed("${profile}/bin/${action} 2>&1 | tee /tmp/output.log")
${node}.succeed("! grep -F 'ERROR' /tmp/output.log")
'';
activateProfileSnippet =
{ node, profile }:
self.mkTestPreamble {
inherit node profile;
action = "activate";
};
etcPath = pkgs.writeTextFile {
name = "etcFiles";
destination = "/etcFiles.json";
text = lib.generators.toJSON { } { inherit (config.build.etc) entries staticEnv; };
deactivateProfileSnippet =
{ node, profile }:
self.mkTestPreamble {
inherit node profile;
action = "deactivate";
};
linkFarmNestedEntryFromDrv = dirs: drv: {
name = lib.concatStringsSep "/" (dirs ++ [ "${drv.name}" ]);
path = drv;
prepopulateProfileSnippet =
{ node, profile }:
self.mkTestPreamble {
inherit node profile;
action = "prepopulate";
};
linkFarmEntryFromDrv = linkFarmNestedEntryFromDrv [ ];
linkFarmBinEntryFromDrv = linkFarmNestedEntryFromDrv [ "bin" ];
toplevel =
let
scripts = lib.mapAttrsToList (_: script: linkFarmBinEntryFromDrv script) config.build.scripts;
entries = [
(linkFarmEntryFromDrv servicesPath)
(linkFarmEntryFromDrv etcPath)
] ++ scripts;
addPassthru =
drv:
drv.overrideAttrs (prevAttrs: {
passthru = (prevAttrs.passthru or { }) // {
inherit config;
};
});
in
addPassthru (pkgs.linkFarm "system-manager" entries);
in
returnIfNoAssertions toplevel;
mkTestPreamble =
{
node,
profile,
action,
}:
''
${node}.succeed("${profile}/bin/${action} 2>&1 | tee /tmp/output.log")
${node}.succeed("! grep -F 'ERROR' /tmp/output.log")
'';
activateProfileSnippet =
{ node, profile }:
mkTestPreamble {
inherit node profile;
action = "activate";
};
deactivateProfileSnippet =
{ node, profile }:
mkTestPreamble {
inherit node profile;
action = "deactivate";
};
prepopulateProfileSnippet =
{ node, profile }:
mkTestPreamble {
inherit node profile;
action = "prepopulate";
};
}
};
in
self

View file

@ -26,6 +26,13 @@
example = "x86_64-linux";
default = throw "the option nixpkgs.hostPlatform needs to be set.";
};
pkgs = lib.mkOption {
type = lib.types.pkgs;
description = ''The pkgs module argument.'';
default = pkgs;
readOnly = true;
};
};
assertions = lib.mkOption {