2021-03-23 19:22:30 +00:00
|
|
|
import ./make-test-python.nix ({ pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
exampleScript = pkgs.writeTextFile {
|
|
|
|
name = "example.sh";
|
|
|
|
text = ''
|
|
|
|
#! ${pkgs.runtimeShell} -e
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
echo "Example script running" >&2
|
|
|
|
${pkgs.coreutils}/bin/sleep 1
|
|
|
|
done
|
|
|
|
'';
|
|
|
|
executable = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
unitFile = pkgs.writeTextFile {
|
|
|
|
name = "example.service";
|
|
|
|
text = ''
|
|
|
|
[Unit]
|
|
|
|
Description=Example systemd service unit file
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
ExecStart=${exampleScript}
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
2022-03-30 09:31:56 +00:00
|
|
|
name = "systemd-misc";
|
2021-03-23 19:22:30 +00:00
|
|
|
|
2022-04-03 18:54:34 +00:00
|
|
|
nodes.machine = { pkgs, lib, ... }: {
|
2021-03-23 19:22:30 +00:00
|
|
|
boot.extraSystemdUnitPaths = [ "/etc/systemd-rw/system" ];
|
2022-03-30 09:31:56 +00:00
|
|
|
|
|
|
|
users.users.limited = {
|
|
|
|
isNormalUser = true;
|
|
|
|
uid = 1000;
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.units."user-1000.slice.d/limits.conf" = {
|
|
|
|
text = ''
|
|
|
|
[Slice]
|
|
|
|
TasksAccounting=yes
|
|
|
|
TasksMax=100
|
|
|
|
'';
|
|
|
|
};
|
2021-03-23 19:22:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
|
|
|
machine.wait_for_unit("multi-user.target")
|
|
|
|
machine.succeed("mkdir -p /etc/systemd-rw/system")
|
|
|
|
machine.succeed(
|
|
|
|
"cp ${unitFile} /etc/systemd-rw/system/example.service"
|
|
|
|
)
|
|
|
|
machine.succeed("systemctl start example.service")
|
|
|
|
machine.succeed("systemctl status example.service | grep 'Active: active'")
|
2022-03-30 09:31:56 +00:00
|
|
|
|
|
|
|
machine.succeed("systemctl show --property TasksMax --value user-1000.slice | grep 100")
|
2021-03-23 19:22:30 +00:00
|
|
|
'';
|
|
|
|
})
|