Squash of #136
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:
parent
37d944cc5f
commit
c099b40594
6 changed files with 188 additions and 152 deletions
8
Cargo.lock
generated
8
Cargo.lock
generated
|
|
@ -62,9 +62,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anyhow"
|
name = "anyhow"
|
||||||
version = "1.0.91"
|
version = "1.0.90"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c042108f3ed77fd83760a5fd79b53be043192bb3b9dba91d8c574c0ada7850c8"
|
checksum = "37bf3594c4c988a53154954629820791dde498571819ae4ca50ca811e060cc95"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
|
|
@ -274,9 +274,9 @@ checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.88"
|
version = "1.0.87"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7c3a7fc5db1e57d5a779a352c8cdb57b29aa4c40cc69c3a68a7fedc815fbf2f9"
|
checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
|
||||||
21
flake.lock
generated
21
flake.lock
generated
|
|
@ -1,5 +1,25 @@
|
||||||
{
|
{
|
||||||
"nodes": {
|
"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": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1729256560,
|
"lastModified": 1729256560,
|
||||||
|
|
@ -18,6 +38,7 @@
|
||||||
},
|
},
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
|
"nix-vm-test": "nix-vm-test",
|
||||||
"nixpkgs": "nixpkgs"
|
"nixpkgs": "nixpkgs"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
39
flake.nix
39
flake.nix
|
|
@ -1,10 +1,17 @@
|
||||||
{
|
{
|
||||||
description = "Manage system config using nix on any distro";
|
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 =
|
outputs =
|
||||||
{ self, nixpkgs }:
|
inputs:
|
||||||
let
|
let
|
||||||
systems = [
|
systems = [
|
||||||
"aarch64-linux"
|
"aarch64-linux"
|
||||||
|
|
@ -12,22 +19,22 @@
|
||||||
];
|
];
|
||||||
eachSystem =
|
eachSystem =
|
||||||
f:
|
f:
|
||||||
nixpkgs.lib.genAttrs systems (
|
inputs.nixpkgs.lib.genAttrs systems (
|
||||||
system:
|
system:
|
||||||
f {
|
f {
|
||||||
inherit system;
|
inherit system;
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
pkgs = inputs.nixpkgs.legacyPackages.${system};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
lib = import ./nix/lib.nix { inherit nixpkgs; };
|
lib = import ./nix/lib.nix { inherit (inputs) nixpkgs; };
|
||||||
|
|
||||||
packages = eachSystem (
|
packages = eachSystem (
|
||||||
{ pkgs, system }:
|
{ pkgs, system }:
|
||||||
import ./packages.nix { inherit pkgs; }
|
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
|
# Only useful for quick tests
|
||||||
systemConfigs.default = self.lib.makeSystemConfig {
|
systemConfigs.default = inputs.self.lib.makeSystemConfig {
|
||||||
modules = [ ./examples/example.nix ];
|
modules = [ ./examples/example.nix ];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -51,31 +58,23 @@
|
||||||
);
|
);
|
||||||
|
|
||||||
checks = (
|
checks = (
|
||||||
nixpkgs.lib.recursiveUpdate
|
inputs.nixpkgs.lib.recursiveUpdate
|
||||||
(eachSystem (
|
(eachSystem (
|
||||||
{ system, ... }:
|
{ system, ... }:
|
||||||
{
|
{
|
||||||
system-manager = self.packages.${system}.system-manager;
|
system-manager = inputs.self.packages.${system}.system-manager;
|
||||||
}
|
}
|
||||||
))
|
))
|
||||||
{
|
{
|
||||||
x86_64-linux =
|
x86_64-linux =
|
||||||
let
|
let
|
||||||
system = "x86_64-linux";
|
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
|
in
|
||||||
(import ./test/nix/modules {
|
(import ./test/nix/modules {
|
||||||
inherit system;
|
inherit system;
|
||||||
inherit (nixpkgs) lib;
|
inherit (inputs.nixpkgs) lib;
|
||||||
inherit nix-vm-test;
|
nix-vm-test = inputs.nix-vm-test.lib.${system};
|
||||||
system-manager = self;
|
system-manager = inputs.self;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
||||||
254
nix/lib.nix
254
nix/lib.nix
|
|
@ -3,141 +3,141 @@
|
||||||
lib ? import "${nixpkgs}/lib",
|
lib ? import "${nixpkgs}/lib",
|
||||||
nixos ? "${nixpkgs}/nixos",
|
nixos ? "${nixpkgs}/nixos",
|
||||||
}:
|
}:
|
||||||
rec {
|
let
|
||||||
# Function that can be used when defining inline modules to get better location
|
self = {
|
||||||
# reporting in module-system errors.
|
# Function that can be used when defining inline modules to get better location
|
||||||
# Usage example:
|
# reporting in module-system errors.
|
||||||
# { _file = "${printAttrPos (builtins.unsafeGetAttrPos "a" { a = null; })}: inline module"; }
|
# Usage example:
|
||||||
printAttrPos =
|
# { _file = "${printAttrPos (builtins.unsafeGetAttrPos "a" { a = null; })}: inline module"; }
|
||||||
{
|
printAttrPos =
|
||||||
file,
|
{
|
||||||
line,
|
file,
|
||||||
column,
|
line,
|
||||||
}:
|
column,
|
||||||
"${file}:${toString line}:${toString column}";
|
}:
|
||||||
|
"${file}:${toString line}:${toString column}";
|
||||||
|
|
||||||
makeSystemConfig =
|
makeSystemConfig =
|
||||||
{
|
{
|
||||||
modules,
|
modules,
|
||||||
extraSpecialArgs ? { },
|
extraSpecialArgs ? { },
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
# Module that sets additional module arguments
|
# Module that sets additional module arguments
|
||||||
extraArgsModule =
|
extraArgsModule =
|
||||||
{
|
{
|
||||||
lib,
|
lib,
|
||||||
config,
|
config,
|
||||||
pkgs,
|
pkgs,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
{
|
{
|
||||||
_file = "${printAttrPos (builtins.unsafeGetAttrPos "a" { a = null; })}: inline module";
|
_file = "${self.printAttrPos (builtins.unsafeGetAttrPos "a" { a = null; })}: inline module";
|
||||||
_module.args = {
|
_module.args = {
|
||||||
pkgs = import nixpkgs { system = config.nixpkgs.hostPlatform; };
|
pkgs = import nixpkgs { system = config.nixpkgs.hostPlatform; };
|
||||||
utils = import "${nixos}/lib/utils.nix" {
|
utils = import "${nixos}/lib/utils.nix" {
|
||||||
inherit lib config pkgs;
|
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 =
|
etcPath = pkgs.writeTextFile {
|
||||||
(lib.evalModules {
|
name = "etcFiles";
|
||||||
specialArgs = {
|
destination = "/etcFiles.json";
|
||||||
nixosModulesPath = "${nixos}/modules";
|
text = lib.generators.toJSON { } { inherit (config.build.etc) entries staticEnv; };
|
||||||
} // extraSpecialArgs;
|
};
|
||||||
modules = [
|
|
||||||
extraArgsModule
|
|
||||||
./modules
|
|
||||||
] ++ modules;
|
|
||||||
}).config;
|
|
||||||
|
|
||||||
# Get the system as it was defined in the modules.
|
linkFarmNestedEntryFromDrv = dirs: drv: {
|
||||||
system = config.nixpkgs.hostPlatform;
|
name = lib.concatStringsSep "/" (dirs ++ [ "${drv.name}" ]);
|
||||||
pkgs = import nixpkgs { inherit system; };
|
path = drv;
|
||||||
|
};
|
||||||
|
linkFarmEntryFromDrv = linkFarmNestedEntryFromDrv [ ];
|
||||||
|
linkFarmBinEntryFromDrv = linkFarmNestedEntryFromDrv [ "bin" ];
|
||||||
|
|
||||||
returnIfNoAssertions =
|
toplevel =
|
||||||
drv:
|
let
|
||||||
let
|
scripts = lib.mapAttrsToList (_: script: linkFarmBinEntryFromDrv script) config.build.scripts;
|
||||||
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 {
|
entries = [
|
||||||
name = "services";
|
(linkFarmEntryFromDrv servicesPath)
|
||||||
destination = "/services.json";
|
(linkFarmEntryFromDrv etcPath)
|
||||||
text = lib.generators.toJSON { } config.build.services;
|
] ++ 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";
|
||||||
};
|
};
|
||||||
|
deactivateProfileSnippet =
|
||||||
etcPath = pkgs.writeTextFile {
|
{ node, profile }:
|
||||||
name = "etcFiles";
|
self.mkTestPreamble {
|
||||||
destination = "/etcFiles.json";
|
inherit node profile;
|
||||||
text = lib.generators.toJSON { } { inherit (config.build.etc) entries staticEnv; };
|
action = "deactivate";
|
||||||
};
|
};
|
||||||
|
prepopulateProfileSnippet =
|
||||||
linkFarmNestedEntryFromDrv = dirs: drv: {
|
{ node, profile }:
|
||||||
name = lib.concatStringsSep "/" (dirs ++ [ "${drv.name}" ]);
|
self.mkTestPreamble {
|
||||||
path = drv;
|
inherit node profile;
|
||||||
|
action = "prepopulate";
|
||||||
};
|
};
|
||||||
linkFarmEntryFromDrv = linkFarmNestedEntryFromDrv [ ];
|
};
|
||||||
linkFarmBinEntryFromDrv = linkFarmNestedEntryFromDrv [ "bin" ];
|
in
|
||||||
|
self
|
||||||
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";
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,13 @@
|
||||||
example = "x86_64-linux";
|
example = "x86_64-linux";
|
||||||
default = throw "the option nixpkgs.hostPlatform needs to be set.";
|
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 {
|
assertions = lib.mkOption {
|
||||||
|
|
|
||||||
11
packages.nix
11
packages.nix
|
|
@ -31,6 +31,7 @@ in
|
||||||
pkg-config,
|
pkg-config,
|
||||||
makeWrapper,
|
makeWrapper,
|
||||||
nix,
|
nix,
|
||||||
|
clippy,
|
||||||
}:
|
}:
|
||||||
rustPlatform.buildRustPackage {
|
rustPlatform.buildRustPackage {
|
||||||
pname = "system-manager";
|
pname = "system-manager";
|
||||||
|
|
@ -42,7 +43,15 @@ in
|
||||||
pkg-config
|
pkg-config
|
||||||
makeWrapper
|
makeWrapper
|
||||||
];
|
];
|
||||||
checkType = "debug"; # might not be required?
|
|
||||||
|
nativeCheckInputs = [
|
||||||
|
clippy
|
||||||
|
];
|
||||||
|
|
||||||
|
preCheck = ''
|
||||||
|
${lib.getExe pkgs.cargo} clippy
|
||||||
|
'';
|
||||||
|
|
||||||
# TODO: Is prefixing nix here the correct approach?
|
# TODO: Is prefixing nix here the correct approach?
|
||||||
postFixup = ''
|
postFixup = ''
|
||||||
wrapProgram $out/bin/system-manager \
|
wrapProgram $out/bin/system-manager \
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue