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

8
Cargo.lock generated
View file

@ -62,9 +62,9 @@ dependencies = [
[[package]]
name = "anyhow"
version = "1.0.91"
version = "1.0.90"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c042108f3ed77fd83760a5fd79b53be043192bb3b9dba91d8c574c0ada7850c8"
checksum = "37bf3594c4c988a53154954629820791dde498571819ae4ca50ca811e060cc95"
[[package]]
name = "bitflags"
@ -274,9 +274,9 @@ checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2"
[[package]]
name = "proc-macro2"
version = "1.0.88"
version = "1.0.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c3a7fc5db1e57d5a779a352c8cdb57b29aa4c40cc69c3a68a7fedc815fbf2f9"
checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a"
dependencies = [
"unicode-ident",
]

21
flake.lock generated
View file

@ -1,5 +1,25 @@
{
"nodes": {
"nix-vm-test": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1729365388,
"narHash": "sha256-PRBcv8IWfXlw7DLuljqyPVAqtcj3/7RtmsKCou8dhAg=",
"owner": "numtide",
"repo": "nix-vm-test",
"rev": "62092e89a2a69fa63fb4f560f48e2f874d3393bb",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "nix-vm-test",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1729256560,
@ -18,6 +38,7 @@
},
"root": {
"inputs": {
"nix-vm-test": "nix-vm-test",
"nixpkgs": "nixpkgs"
}
}

View file

@ -1,10 +1,17 @@
{
description = "Manage system config using nix on any distro";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
nix-vm-test = {
url = "github:numtide/nix-vm-test";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{ self, nixpkgs }:
inputs:
let
systems = [
"aarch64-linux"
@ -12,22 +19,22 @@
];
eachSystem =
f:
nixpkgs.lib.genAttrs systems (
inputs.nixpkgs.lib.genAttrs systems (
system:
f {
inherit system;
pkgs = nixpkgs.legacyPackages.${system};
pkgs = inputs.nixpkgs.legacyPackages.${system};
}
);
in
{
lib = import ./nix/lib.nix { inherit nixpkgs; };
lib = import ./nix/lib.nix { inherit (inputs) nixpkgs; };
packages = eachSystem (
{ pkgs, system }:
import ./packages.nix { inherit pkgs; }
// {
default = self.packages.${system}.system-manager;
default = inputs.self.packages.${system}.system-manager;
}
);
@ -37,7 +44,7 @@
};
# Only useful for quick tests
systemConfigs.default = self.lib.makeSystemConfig {
systemConfigs.default = inputs.self.lib.makeSystemConfig {
modules = [ ./examples/example.nix ];
};
@ -51,31 +58,23 @@
);
checks = (
nixpkgs.lib.recursiveUpdate
inputs.nixpkgs.lib.recursiveUpdate
(eachSystem (
{ system, ... }:
{
system-manager = self.packages.${system}.system-manager;
system-manager = inputs.self.packages.${system}.system-manager;
}
))
{
x86_64-linux =
let
system = "x86_64-linux";
nix-vm-test-src = builtins.fetchTarball {
url = "https://github.com/numtide/nix-vm-test/archive/7901cec00670681b3e405565cb7bffe6a9368240.tar.gz";
sha256 = "0m82a40r3j7qinp3y6mh36da89dkwvpalz6a4znx9rqp6kh3885x";
};
nix-vm-test = import "${nix-vm-test-src}/lib.nix" {
inherit nixpkgs;
inherit system;
};
in
(import ./test/nix/modules {
inherit system;
inherit (nixpkgs) lib;
inherit nix-vm-test;
system-manager = self;
inherit (inputs.nixpkgs) lib;
nix-vm-test = inputs.nix-vm-test.lib.${system};
system-manager = inputs.self;
});
}
);

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 {

View file

@ -31,6 +31,7 @@ in
pkg-config,
makeWrapper,
nix,
clippy,
}:
rustPlatform.buildRustPackage {
pname = "system-manager";
@ -42,7 +43,15 @@ in
pkg-config
makeWrapper
];
checkType = "debug"; # might not be required?
nativeCheckInputs = [
clippy
];
preCheck = ''
${lib.getExe pkgs.cargo} clippy
'';
# TODO: Is prefixing nix here the correct approach?
postFixup = ''
wrapProgram $out/bin/system-manager \