Merge pull request #113241 from chkno/user-activation-scripts

Run userActivationScripts at login
This commit is contained in:
Artturi 2021-09-18 05:25:06 +03:00 committed by GitHub
commit e7b6d118f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 0 deletions

View file

@ -263,6 +263,7 @@ in
script = config.system.userActivationScripts.script;
unitConfig.ConditionUser = "!@system";
serviceConfig.Type = "oneshot";
wantedBy = [ "default.target" ];
};
};
};

View file

@ -461,6 +461,7 @@ in
unit-php = handleTest ./web-servers/unit-php.nix {};
upnp = handleTest ./upnp.nix {};
usbguard = handleTest ./usbguard.nix {};
user-activation-scripts = handleTest ./user-activation-scripts.nix {};
uwsgi = handleTest ./uwsgi.nix {};
v2ray = handleTest ./v2ray.nix {};
vault = handleTest ./vault.nix {};

View file

@ -0,0 +1,33 @@
import ./make-test-python.nix ({ lib, ... }: {
name = "user-activation-scripts";
meta = with lib.maintainers; { maintainers = [ chkno ]; };
machine = {
system.userActivationScripts.foo = "mktemp ~/user-activation-ran.XXXXXX";
users.users.alice = {
initialPassword = "pass1";
isNormalUser = true;
};
};
testScript = ''
def verify_user_activation_run_count(n):
machine.succeed(
'[[ "$(find /home/alice/ -name user-activation-ran.\\* | wc -l)" == %s ]]' % n
)
machine.wait_for_unit("multi-user.target")
machine.wait_for_unit("getty@tty1.service")
machine.wait_until_tty_matches(1, "login: ")
machine.send_chars("alice\n")
machine.wait_until_tty_matches(1, "Password: ")
machine.send_chars("pass1\n")
machine.send_chars("touch login-ok\n")
machine.wait_for_file("/home/alice/login-ok")
verify_user_activation_run_count(1)
machine.succeed("/run/current-system/bin/switch-to-configuration test")
verify_user_activation_run_count(2)
'';
})