Reformat with nixfmt

This commit is contained in:
r-vdp 2024-09-30 11:59:31 +02:00
parent 3aab6ab23a
commit 8441081b6b
No known key found for this signature in database
11 changed files with 837 additions and 674 deletions

View file

@ -1,6 +1,4 @@
(import
(fetchTarball {
(import (fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz";
sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2";
})
{ src = ./.; }).defaultNix
}) { src = ./.; }).defaultNix

View file

@ -1,4 +1,5 @@
{ lib, pkgs, ... }: {
{ lib, pkgs, ... }:
{
config = {
nixpkgs.hostPlatform = "x86_64-linux";
@ -56,11 +57,10 @@
};
};
systemd.services =
lib.listToAttrs
(lib.flip lib.genList 10 (ix:
lib.nameValuePair "service-${toString ix}"
{
systemd.services = lib.listToAttrs (
lib.flip lib.genList 10 (
ix:
lib.nameValuePair "service-${toString ix}" {
enable = true;
description = "service-${toString ix}";
wants = [ "network-online.target" ];
@ -76,7 +76,8 @@
script = ''
sleep ${if ix > 5 then "2" else "1"}
'';
})
}
)
);
systemd.tmpfiles.rules = [ "D /var/tmp/system-manager 0755 root root -" ];
};

108
flake.nix
View file

@ -39,15 +39,16 @@
};
outputs =
{ self
, nixpkgs
, flake-utils
, rust-overlay
, crane
, devshell
, treefmt-nix
, pre-commit-hooks
, ...
{
self,
nixpkgs,
flake-utils,
rust-overlay,
crane,
devshell,
treefmt-nix,
pre-commit-hooks,
...
}@inputs:
{
lib = import ./nix/lib.nix {
@ -60,17 +61,20 @@
modules = [ ./examples/example.nix ];
};
}
//
(flake-utils.lib.eachSystem
// (flake-utils.lib.eachSystem
[
flake-utils.lib.system.x86_64-linux
flake-utils.lib.system.aarch64-linux
]
(system:
(
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ (import rust-overlay) devshell.overlays.default ];
overlays = [
(import rust-overlay)
devshell.overlays.default
];
};
# TODO Pin the version for release
rust = pkgs.rust-bin.stable.latest;
@ -78,7 +82,9 @@
craneLib = (crane.mkLib pkgs).overrideToolchain rust.default;
# Common derivation arguments used for all builds
commonArgs = { dbus, pkg-config }: {
commonArgs =
{ dbus, pkg-config }:
{
src = craneLib.cleanCargoSource ./.;
buildInputs = [
dbus
@ -91,26 +97,35 @@
};
# Build only the cargo dependencies
cargoArtifacts = { dbus, pkg-config }:
craneLib.buildDepsOnly ((commonArgs { inherit dbus pkg-config; }) // {
cargoArtifacts =
{ dbus, pkg-config }:
craneLib.buildDepsOnly (
(commonArgs { inherit dbus pkg-config; })
// {
pname = "system-manager";
});
}
);
system-manager-unwrapped =
{ dbus
, pkg-config
{
dbus,
pkg-config,
}:
craneLib.buildPackage ((commonArgs { inherit dbus pkg-config; }) // {
craneLib.buildPackage (
(commonArgs { inherit dbus pkg-config; })
// {
pname = "system-manager";
cargoArtifacts = cargoArtifacts { inherit dbus pkg-config; };
});
}
);
system-manager =
{ dbus
, makeBinaryWrapper
, nix
, pkg-config
, runCommand
{
dbus,
makeBinaryWrapper,
nix,
pkg-config,
runCommand,
}:
let
unwrapped = system-manager-unwrapped { inherit dbus pkg-config; };
@ -127,21 +142,29 @@
'';
system-manager-clippy =
{ dbus
, pkg-config
{
dbus,
pkg-config,
}:
craneLib.cargoClippy ((commonArgs { inherit dbus pkg-config; }) // {
craneLib.cargoClippy (
(commonArgs { inherit dbus pkg-config; })
// {
cargoArtifacts = cargoArtifacts { inherit dbus pkg-config; };
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
});
}
);
system-manager-test =
{ dbus
, pkg-config
{
dbus,
pkg-config,
}:
craneLib.cargoTest ((commonArgs { inherit dbus pkg-config; }) // {
craneLib.cargoTest (
(commonArgs { inherit dbus pkg-config; })
// {
cargoArtifacts = cargoArtifacts { inherit dbus pkg-config; };
});
}
);
# treefmt-nix configuration
treefmt.config = {
@ -219,7 +242,8 @@
value = "1";
}
];
devshell.startup.pre-commit.text = (pre-commit-hooks.lib.${system}.run {
devshell.startup.pre-commit.text =
(pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
check-format = {
@ -247,14 +271,18 @@
# Build the crate as part of `nix flake check` for convenience
system-manager
system-manager-clippy
system-manager-test;
} //
pkgs.lib.optionalAttrs enableVmTests (import ./test/nix/modules {
system-manager-test
;
}
// pkgs.lib.optionalAttrs enableVmTests (
import ./test/nix/modules {
inherit system;
inherit (pkgs) lib;
inherit (inputs) nix-vm-test;
system-manager = self;
});
})
}
);
}
)
);
}

View file

@ -1,7 +1,7 @@
{ nixpkgs # The nixpkgs flake
, self # The system-manager flake
, nixos # The path to the nixos dir from nixpkgs
,
{
nixpkgs, # The nixpkgs flake
self, # The system-manager flake
nixos, # The path to the nixos dir from nixpkgs
}:
let
inherit (nixpkgs) lib;
@ -11,15 +11,29 @@ in
# 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}";
printAttrPos =
{
file,
line,
column,
}:
"${file}:${toString line}:${toString column}";
makeSystemConfig =
{ modules
, extraSpecialArgs ? { }
{
modules,
extraSpecialArgs ? { },
}:
let
# Module that sets additional module arguments
extraArgsModule = { lib, config, pkgs, ... }: {
extraArgsModule =
{
lib,
config,
pkgs,
...
}:
{
_file = "${self.lib.printAttrPos (builtins.unsafeGetAttrPos "a" { a = null; })}: inline module";
_module.args = {
pkgs = nixpkgs.legacyPackages.${config.nixpkgs.hostPlatform};
@ -31,8 +45,11 @@ in
};
};
config = (lib.evalModules {
specialArgs = { nixosModulesPath = "${nixos}/modules"; } // extraSpecialArgs;
config =
(lib.evalModules {
specialArgs = {
nixosModulesPath = "${nixos}/modules";
} // extraSpecialArgs;
modules = [
extraArgsModule
./modules
@ -43,13 +60,15 @@ in
system = config.nixpkgs.hostPlatform;
pkgs = nixpkgs.legacyPackages.${system};
returnIfNoAssertions = drv:
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;
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";
@ -72,16 +91,16 @@ in
toplevel =
let
scripts = lib.mapAttrsToList
(_: script: linkFarmBinEntryFromDrv script)
config.build.scripts;
scripts = lib.mapAttrsToList (_: script: linkFarmBinEntryFromDrv script) config.build.scripts;
entries = [
(linkFarmEntryFromDrv servicesPath)
(linkFarmEntryFromDrv etcPath)
] ++ scripts;
addPassthru = drv: drv.overrideAttrs (prevAttrs: {
addPassthru =
drv:
drv.overrideAttrs (prevAttrs: {
passthru = (prevAttrs.passthru or { }) // {
inherit config;
};
@ -92,25 +111,30 @@ in
returnIfNoAssertions toplevel;
mkTestPreamble =
{ node
, profile
, action
}: ''
{
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 }:
activateProfileSnippet =
{ node, profile }:
self.lib.mkTestPreamble {
inherit node profile;
action = "activate";
};
deactivateProfileSnippet = { node, profile }:
deactivateProfileSnippet =
{ node, profile }:
self.lib.mkTestPreamble {
inherit node profile;
action = "deactivate";
};
prepopulateProfileSnippet = { node, profile }:
prepopulateProfileSnippet =
{ node, profile }:
self.lib.mkTestPreamble {
inherit node profile;
action = "prepopulate";

View file

@ -1,8 +1,9 @@
{ lib
, config
, pkgs
, system-manager
, ...
{
lib,
config,
pkgs,
system-manager,
...
}:
{
imports = [
@ -31,7 +32,12 @@
type = types.listOf types.unspecified;
internal = true;
default = [ ];
example = [{ assertion = false; message = "you can't enable this for that reason"; }];
example = [
{
assertion = false;
message = "you can't enable this for that reason";
}
];
description = lib.mdDoc ''
This option allows modules to express conditions that must
hold for the evaluation of the system configuration to
@ -95,7 +101,12 @@
allowAnyDistro = lib.mkEnableOption "the usage of system-manager on untested distributions";
preActivationAssertions = lib.mkOption {
type = with lib.types; attrsOf (submodule ({ name, ... }: {
type =
with lib.types;
attrsOf (
submodule (
{ name, ... }:
{
options = {
enable = lib.mkEnableOption "the assertion";
@ -108,7 +119,9 @@
type = types.str;
};
};
}));
}
)
);
default = { };
};
};
@ -140,17 +153,22 @@
system-manager.preActivationAssertions = {
osVersion =
let
supportedIds = [ "nixos" "ubuntu" ];
supportedIds = [
"nixos"
"ubuntu"
];
in
{
enable = !config.system-manager.allowAnyDistro;
script = ''
source /etc/os-release
${lib.concatStringsSep "\n" (lib.flip map supportedIds (supportedId: ''
${lib.concatStringsSep "\n" (
lib.flip map supportedIds (supportedId: ''
if [ $ID = "${supportedId}" ]; then
exit 0
fi
''))}
'')
)}
echo "This OS is not currently supported."
echo "Supported OSs are: ${lib.concatStringsSep ", " supportedIds}"
exit 1
@ -184,7 +202,9 @@
preActivationAssertionScript =
let
mkAssertion = { name, script, ... }: ''
mkAssertion =
{ name, script, ... }:
''
# ${name}
echo -e "Evaluating pre-activation assertion ${name}...\n"
@ -199,12 +219,10 @@
fi
'';
mkAssertions = assertions:
mkAssertions =
assertions:
lib.concatStringsSep "\n" (
lib.mapAttrsToList (name: mkAssertion) (
lib.filterAttrs (name: cfg: cfg.enable)
assertions
)
lib.mapAttrsToList (name: mkAssertion) (lib.filterAttrs (name: cfg: cfg.enable) assertions)
);
in
pkgs.writeShellScript "preActivationAssertions" ''
@ -230,7 +248,9 @@
# TODO: handle globbing
etc =
let
addToStore = name: file: pkgs.runCommandLocal "${name}-etc-link" { } ''
addToStore =
name: file:
pkgs.runCommandLocal "${name}-etc-link" { } ''
mkdir -p "$out/$(dirname "${file.target}")"
ln -s "${file.source}" "$out/${file.target}"
@ -241,32 +261,27 @@
fi
'';
filteredEntries = lib.filterAttrs
(_name: etcFile: etcFile.enable)
config.environment.etc;
filteredEntries = lib.filterAttrs (_name: etcFile: etcFile.enable) config.environment.etc;
srcDrvs = lib.mapAttrs addToStore filteredEntries;
entries = lib.mapAttrs
(name: file: file // { source = "${srcDrvs.${name}}"; })
filteredEntries;
entries = lib.mapAttrs (name: file: file // { source = "${srcDrvs.${name}}"; }) filteredEntries;
staticEnv = pkgs.buildEnv {
name = "etc-static-env";
paths = lib.attrValues srcDrvs;
};
in
{ inherit entries staticEnv; };
{
inherit entries staticEnv;
};
services =
lib.mapAttrs'
(unitName: unit:
services = lib.mapAttrs' (
unitName: unit:
lib.nameValuePair unitName {
storePath =
''${unit.unit}/${unitName}'';
})
(lib.filterAttrs (_: unit: unit.enable)
config.systemd.units);
storePath = ''${unit.unit}/${unitName}'';
}
) (lib.filterAttrs (_: unit: unit.enable) config.systemd.units);
};
};
}

View file

@ -1,4 +1,9 @@
{ lib, config, pkgs, ... }:
{
lib,
config,
pkgs,
...
}:
{
options.environment = {
@ -24,8 +29,7 @@
];
etc = {
"profile.d/system-manager-path.sh".source =
pkgs.writeText "system-manager-path.sh" ''
"profile.d/system-manager-path.sh".source = pkgs.writeText "system-manager-path.sh" ''
export PATH=${pathDir}/bin/:''${PATH}
'';

View file

@ -1,6 +1,7 @@
{ lib
, pkgs
, ...
{
lib,
pkgs,
...
}:
{
options = {
@ -18,8 +19,14 @@
Set of files that have to be linked in {file}`/etc`.
'';
type = lib.types.attrsOf (lib.types.submodule (
{ name, config, options, ... }:
type = lib.types.attrsOf (
lib.types.submodule (
{
name,
config,
options,
...
}:
{
options = {
@ -105,12 +112,15 @@
config = {
target = lib.mkDefault name;
source = lib.mkIf (config.text != null) (
let name' = "etc-" + baseNameOf name;
in lib.mkDerivedConfig options.text (pkgs.writeText name')
let
name' = "etc-" + baseNameOf name;
in
lib.mkDerivedConfig options.text (pkgs.writeText name')
);
};
}
));
)
);
};
};
}

View file

@ -1,8 +1,9 @@
{ lib
, config
, pkgs
, utils
, ...
{
lib,
config,
pkgs,
utils,
...
}:
let
@ -19,14 +20,28 @@ in
# We could consider copying the systemd lib from NixOS and removing the bits
# that are not relevant to us, like this option.
package = lib.mkOption {
type = lib.types.oneOf [ lib.types.str lib.types.path lib.types.package ];
type = lib.types.oneOf [
lib.types.str
lib.types.path
lib.types.package
];
default = pkgs.systemdMinimal;
};
globalEnvironment = lib.mkOption {
type = with lib.types; attrsOf (nullOr (oneOf [ str path package ]));
type =
with lib.types;
attrsOf (
nullOr (oneOf [
str
path
package
])
);
default = { };
example = { TZ = "CET"; };
example = {
TZ = "CET";
};
description = lib.mdDoc ''
Environment variables passed to *all* systemd units.
'';
@ -104,7 +119,9 @@ in
generators = lib.mkOption {
type = lib.types.attrsOf lib.types.path;
default = { };
example = { systemd-gpt-auto-generator = "/dev/null"; };
example = {
systemd-gpt-auto-generator = "/dev/null";
};
description = lib.mdDoc ''
Definition of systemd generators.
For each `NAME = VALUE` pair of the attrSet, a link is generated from
@ -129,14 +146,10 @@ in
wantedBy = [ "default.target" ];
};
timers =
lib.mapAttrs
(name: service:
{
timers = lib.mapAttrs (name: service: {
wantedBy = [ "timers.target" ];
timerConfig.OnCalendar = service.startAt;
})
(lib.filterAttrs (name: service: service.enable && service.startAt != [ ]) cfg.services);
}) (lib.filterAttrs (name: service: service.enable && service.startAt != [ ]) cfg.services);
units =
lib.mapAttrs' (n: v: lib.nameValuePair "${n}.path" (systemd-lib.pathToUnit v)) cfg.paths
@ -145,16 +158,24 @@ in
// lib.mapAttrs' (n: v: lib.nameValuePair "${n}.socket" (systemd-lib.socketToUnit v)) cfg.sockets
// lib.mapAttrs' (n: v: lib.nameValuePair "${n}.target" (systemd-lib.targetToUnit v)) cfg.targets
// lib.mapAttrs' (n: v: lib.nameValuePair "${n}.timer" (systemd-lib.timerToUnit v)) cfg.timers
// lib.listToAttrs (map
(v:
let n = utils.escapeSystemdPath v.where;
in lib.nameValuePair "${n}.mount" (systemd-lib.mountToUnit v))
cfg.mounts)
// lib.listToAttrs (map
(v:
let n = utils.escapeSystemdPath v.where;
in lib.nameValuePair "${n}.automount" (systemd-lib.automountToUnit v))
cfg.automounts);
// lib.listToAttrs (
map (
v:
let
n = utils.escapeSystemdPath v.where;
in
lib.nameValuePair "${n}.mount" (systemd-lib.mountToUnit v)
) cfg.mounts
)
// lib.listToAttrs (
map (
v:
let
n = utils.escapeSystemdPath v.where;
in
lib.nameValuePair "${n}.automount" (systemd-lib.automountToUnit v)
) cfg.automounts
);
};
environment.etc =
@ -164,7 +185,8 @@ in
enabledUnits = lib.filterAttrs (_: unit: unit.enable) cfg.units;
in
{
"systemd/system".source = pkgs.runCommand "system-manager-units"
"systemd/system".source =
pkgs.runCommand "system-manager-units"
{
preferLocalBuild = true;
allowSubstitutes = false;
@ -178,13 +200,18 @@ in
if [ "$(readlink -f $i/$fn)" = /dev/null ]; then
ln -sfn /dev/null $out/$fn
else
${if allowCollisions then ''
${
if allowCollisions then
''
mkdir -p $out/$fn.d
ln -s $i/$fn $out/$fn.d/overrides.conf
'' else ''
''
else
''
echo "Found multiple derivations configuring $fn!"
exit 1
''}
''
}
fi
else
ln -fs $i/$fn $out/
@ -192,20 +219,24 @@ in
done
${lib.concatStrings (
lib.mapAttrsToList (name: unit:
lib.mapAttrsToList (
name: unit:
lib.concatMapStrings (name2: ''
mkdir -p $out/'${name2}.wants'
ln -sfn '../${name}' $out/'${name2}.wants'/
'') (unit.wantedBy or [])
) enabledUnits)}
'') (unit.wantedBy or [ ])
) enabledUnits
)}
${lib.concatStrings (
lib.mapAttrsToList (name: unit:
lib.mapAttrsToList (
name: unit:
lib.concatMapStrings (name2: ''
mkdir -p $out/'${name2}.requires'
ln -sfn '../${name}' $out/'${name2}.requires'/
'') (unit.requiredBy or [])
) enabledUnits)}
'') (unit.requiredBy or [ ])
) enabledUnits
)}
'';
};
};

View file

@ -1,11 +1,14 @@
{ nixosModulesPath
, lib
, ...
{
nixosModulesPath,
lib,
...
}:
{
imports = [
imports =
[
./nginx.nix
] ++
]
++
# List of imported NixOS modules
# TODO: how will we manage this in the long term?
map (path: nixosModulesPath + path) [
@ -14,7 +17,6 @@
"/services/web-servers/nginx/"
];
options =
# We need to ignore a bunch of options that are used in NixOS modules but
# that don't apply to system-manager configs.

View file

@ -5,4 +5,3 @@ let
};
in
(import compat { src = ./.; }).shellNix.default

View file

@ -1,42 +1,55 @@
{ lib
, system-manager
, system
, nix-vm-test
{
lib,
system-manager,
system,
nix-vm-test,
}:
let
forEachUbuntuImage =
name:
{ modules
, testScriptFunction
, extraPathsToRegister ? [ ]
, projectTest ? test: test.sandboxed
{
modules,
testScriptFunction,
extraPathsToRegister ? [ ],
projectTest ? test: test.sandboxed,
}:
let
ubuntu = nix-vm-test.lib.${system}.ubuntu;
in
lib.listToAttrs (lib.flip map (lib.attrNames ubuntu.images)
(imageVersion:
lib.listToAttrs (
lib.flip map (lib.attrNames ubuntu.images) (
imageVersion:
let
toplevel = (system-manager.lib.makeSystemConfig {
toplevel = (
system-manager.lib.makeSystemConfig {
modules = modules ++ [
({ lib, pkgs, ... }: {
options.hostPkgs = lib.mkOption { type = lib.types.raw; readOnly = true; };
(
{ lib, pkgs, ... }:
{
options.hostPkgs = lib.mkOption {
type = lib.types.raw;
readOnly = true;
};
config.hostPkgs = pkgs;
})
}
)
];
});
}
);
inherit (toplevel.config) hostPkgs;
in
lib.nameValuePair "ubuntu-${imageVersion}-${name}"
(projectTest
(ubuntu.${imageVersion} {
lib.nameValuePair "ubuntu-${imageVersion}-${name}" (
projectTest (
ubuntu.${imageVersion} {
testScript = testScriptFunction { inherit toplevel hostPkgs; };
extraPathsToRegister = extraPathsToRegister ++ [
toplevel
];
sharedDirs = { };
}))
}
)
)
)
);
@ -44,7 +57,10 @@ let
# and one that cannot.
# The id parameter is a string that can be used to force reloading the services
# between two configs by changing their contents.
testModule = id: { lib, pkgs, ... }: {
testModule =
id:
{ lib, pkgs, ... }:
{
systemd.services = {
has-reload = {
enable = true;
@ -78,7 +94,9 @@ let
newConfig = system-manager.lib.makeSystemConfig {
modules = [
(testModule "new")
({ lib, pkgs, ... }: {
(
{ lib, pkgs, ... }:
{
config = {
nixpkgs.hostPlatform = system;
@ -107,27 +125,32 @@ let
RemainAfterExit = true;
ExecReload = "${lib.getBin pkgs.coreutils}/bin/true";
};
wantedBy = [ "system-manager.target" "default.target" ];
wantedBy = [
"system-manager.target"
"default.target"
];
script = ''
sleep 2
'';
};
};
};
})
}
)
];
};
in
forEachUbuntuImage "example"
{
forEachUbuntuImage "example" {
modules = [
(testModule "old")
../../../examples/example.nix
];
extraPathsToRegister = [ newConfig ];
testScriptFunction = { toplevel, ... }: ''
testScriptFunction =
{ toplevel, ... }:
''
# Start all machines in parallel
start_all()
@ -138,7 +161,10 @@ forEachUbuntuImage "example"
vm.succeed("grep -F 'Error while creating file in /etc: Unmanaged path already exists in filesystem, please remove it and run system-manager again: /etc/foo_test' /tmp/output.log")
vm.succeed("rm /etc/foo_test")
${system-manager.lib.activateProfileSnippet { node = "vm"; profile = toplevel; }}
${system-manager.lib.activateProfileSnippet {
node = "vm";
profile = toplevel;
}}
vm.wait_for_unit("system-manager.target")
vm.succeed("systemctl status service-9.service")
@ -150,7 +176,10 @@ forEachUbuntuImage "example"
vm.succeed("test -d /var/tmp/system-manager")
${system-manager.lib.activateProfileSnippet { node = "vm"; profile = newConfig; }}
${system-manager.lib.activateProfileSnippet {
node = "vm";
profile = newConfig;
}}
vm.succeed("systemctl status new-service.service")
vm.fail("systemctl status service-9.service")
vm.fail("test -f /etc/a/nested/example/foo3")
@ -177,28 +206,36 @@ forEachUbuntuImage "example"
vm.fail("test -f /etc/baz/bar/foo2")
vm.succeed("test -f /etc/foo_new")
${system-manager.lib.deactivateProfileSnippet { node = "vm"; profile = newConfig; }}
${system-manager.lib.deactivateProfileSnippet {
node = "vm";
profile = newConfig;
}}
vm.fail("systemctl status new-service.service")
vm.fail("test -f /etc/foo_new")
#vm.fail("test -f /var/tmp/system-manager/foo1")
'';
}
}
//
forEachUbuntuImage "prepopulate" {
forEachUbuntuImage "prepopulate" {
modules = [
(testModule "old")
../../../examples/example.nix
];
extraPathsToRegister = [ newConfig ];
testScriptFunction = { toplevel, ... }: ''
testScriptFunction =
{ toplevel, ... }:
''
# Start all machines in parallel
start_all()
vm.wait_for_unit("default.target")
${system-manager.lib.prepopulateProfileSnippet { node = "vm"; profile = toplevel; }}
${system-manager.lib.prepopulateProfileSnippet {
node = "vm";
profile = toplevel;
}}
vm.systemctl("daemon-reload")
# Simulate a reboot, to check that the services defined with
@ -218,28 +255,36 @@ forEachUbuntuImage "prepopulate" {
vm.succeed("grep -F 'launch_the_rockets = true' /etc/foo.conf")
vm.fail("grep -F 'launch_the_rockets = false' /etc/foo.conf")
${system-manager.lib.activateProfileSnippet { node = "vm"; profile = newConfig; }}
${system-manager.lib.activateProfileSnippet {
node = "vm";
profile = newConfig;
}}
vm.succeed("systemctl status new-service.service")
vm.fail("systemctl status service-9.service")
vm.fail("test -f /etc/a/nested/example/foo3")
vm.fail("test -f /etc/baz/bar/foo2")
vm.succeed("test -f /etc/foo_new")
${system-manager.lib.deactivateProfileSnippet { node = "vm"; profile = newConfig; }}
${system-manager.lib.deactivateProfileSnippet {
node = "vm";
profile = newConfig;
}}
vm.fail("systemctl status new-service.service")
vm.fail("test -f /etc/foo_new")
'';
}
}
//
//
forEachUbuntuImage "system-path" {
forEachUbuntuImage "system-path" {
modules = [
(testModule "old")
../../../examples/example.nix
];
extraPathsToRegister = [ newConfig ];
testScriptFunction = { toplevel, hostPkgs, ... }: ''
testScriptFunction =
{ toplevel, hostPkgs, ... }:
''
# Start all machines in parallel
start_all()
vm.wait_for_unit("default.target")
@ -247,7 +292,10 @@ forEachUbuntuImage "system-path" {
vm.fail("bash --login -c '$(which rg)'")
vm.fail("bash --login -c '$(which fd)'")
${system-manager.lib.activateProfileSnippet { node = "vm"; profile = toplevel; }}
${system-manager.lib.activateProfileSnippet {
node = "vm";
profile = toplevel;
}}
vm.wait_for_unit("system-manager.target")
vm.wait_for_unit("system-manager-path.service")
@ -256,10 +304,13 @@ forEachUbuntuImage "system-path" {
vm.succeed("bash --login -c 'realpath $(which rg) | grep -F ${hostPkgs.ripgrep}/bin/rg'")
vm.succeed("bash --login -c 'realpath $(which fd) | grep -F ${hostPkgs.fd}/bin/fd'")
${system-manager.lib.activateProfileSnippet { node = "vm"; profile = newConfig; }}
${system-manager.lib.activateProfileSnippet {
node = "vm";
profile = newConfig;
}}
vm.fail("bash --login -c '$(which rg)'")
vm.fail("bash --login -c '$(which fd)'")
vm.succeed("bash --login -c 'realpath $(which fish) | grep -F ${hostPkgs.fish}/bin/fish'")
'';
}
}