nixpkgs/nixos/tests/sysinit-reactivation.nix
Silvan Mosberger 4f0dadbf38 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build a08b3a4d19.tar.gz \
      --argstr baseRev b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:26:33 +01:00

121 lines
3.6 KiB
Nix

# This runs to two scenarios but in one tests:
# - A post-sysinit service needs to be restarted AFTER tmpfiles was restarted.
# - A service needs to be restarted BEFORE tmpfiles is restarted
{ lib, ... }:
let
makeGeneration = generation: {
"${generation}".configuration = {
systemd.services.pre-sysinit-before-tmpfiles.environment.USER =
lib.mkForce "${generation}-tmpfiles-user";
systemd.services.pre-sysinit-after-tmpfiles.environment = {
NEEDED_PATH = lib.mkForce "/run/${generation}-needed-by-pre-sysinit-after-tmpfiles";
PATH_TO_CREATE = lib.mkForce "/run/${generation}-needed-by-post-sysinit";
};
systemd.services.post-sysinit.environment = {
NEEDED_PATH = lib.mkForce "/run/${generation}-needed-by-post-sysinit";
PATH_TO_CREATE = lib.mkForce "/run/${generation}-created-by-post-sysinit";
};
systemd.tmpfiles.settings.test = lib.mkForce {
"/run/${generation}-needed-by-pre-sysinit-after-tmpfiles".f.user = "${generation}-tmpfiles-user";
};
};
};
in
{
name = "sysinit-reactivation";
meta.maintainers = with lib.maintainers; [ nikstur ];
nodes.machine =
{
config,
lib,
pkgs,
...
}:
{
systemd.services.pre-sysinit-before-tmpfiles = {
wantedBy = [ "sysinit.target" ];
requiredBy = [ "sysinit-reactivation.target" ];
before = [
"systemd-tmpfiles-setup.service"
"systemd-tmpfiles-resetup.service"
];
unitConfig.DefaultDependencies = false;
serviceConfig.Type = "oneshot";
serviceConfig.RemainAfterExit = true;
environment.USER = "tmpfiles-user";
script = "${pkgs.shadow}/bin/useradd $USER";
};
systemd.services.pre-sysinit-after-tmpfiles = {
wantedBy = [ "sysinit.target" ];
requiredBy = [ "sysinit-reactivation.target" ];
after = [
"systemd-tmpfiles-setup.service"
"systemd-tmpfiles-resetup.service"
];
unitConfig.DefaultDependencies = false;
serviceConfig.Type = "oneshot";
serviceConfig.RemainAfterExit = true;
environment = {
NEEDED_PATH = "/run/needed-by-pre-sysinit-after-tmpfiles";
PATH_TO_CREATE = "/run/needed-by-post-sysinit";
};
script = ''
if [[ -e $NEEDED_PATH ]]; then
touch $PATH_TO_CREATE
fi
'';
};
systemd.services.post-sysinit = {
wantedBy = [ "default.target" ];
serviceConfig.Type = "oneshot";
serviceConfig.RemainAfterExit = true;
environment = {
NEEDED_PATH = "/run/needed-by-post-sysinit";
PATH_TO_CREATE = "/run/created-by-post-sysinit";
};
script = ''
if [[ -e $NEEDED_PATH ]]; then
touch $PATH_TO_CREATE
fi
'';
};
systemd.tmpfiles.settings.test = {
"/run/needed-by-pre-sysinit-after-tmpfiles".f.user = "tmpfiles-user";
};
specialisation = lib.mkMerge [
(makeGeneration "second")
(makeGeneration "third")
];
};
testScript =
{ nodes, ... }:
''
def switch(generation):
toplevel = "${nodes.machine.system.build.toplevel}";
machine.succeed(f"{toplevel}/specialisation/{generation}/bin/switch-to-configuration switch")
machine.wait_for_unit("default.target")
machine.succeed("test -e /run/created-by-post-sysinit")
switch("second")
machine.succeed("test -e /run/second-created-by-post-sysinit")
switch("third")
machine.succeed("test -e /run/third-created-by-post-sysinit")
'';
}