Automatically create a setup user

This commit is contained in:
Manuel Thalmann 2024-07-13 09:52:30 +02:00
parent e017d8fb64
commit 60d3556f10
3 changed files with 141 additions and 79 deletions

View file

@ -12,6 +12,20 @@
options = { options = {
valhalla = { valhalla = {
setupUser = {
name = mkOption {
type = types.str;
description = "The name of the user used to set up the system.";
default = "heimdall";
};
id = mkOption {
type = types.int;
description = "The UID of the user used to set up the system.";
default = 420;
};
};
timeZone = mkOption { timeZone = mkOption {
type = types.nullOr types.str; type = types.nullOr types.str;
description = "The time zone of the system."; description = "The time zone of the system.";

View file

@ -1,14 +1,15 @@
#!/bin/env fish #!/bin/env fish
begin begin
set -l dir (status dirname) set -l dir (status dirname)
source "$dir/../../Common/Scripts/config.fish"
source "$dir/../../Common/Scripts/hooks.fish"
source "$dir/../../Common/Scripts/wait-network.fish"
set -q CONFIG_MODULE || set -l CONFIG_MODULE "$dir/config.nix" set -q CONFIG_MODULE || set -l CONFIG_MODULE "$dir/config.nix"
source "$dir/../../Common/Scripts/config.fish"
set -l mountDir (getConfig valhalla.partition.rootDir) set -l mountDir (getConfig valhalla.partition.rootDir)
function setupOS -V dir -V CONFIG_MODULE -V mountDir
source "$dir/../../Common/Scripts/hooks.fish"
source "$dir/../../Common/Scripts/wait-network.fish"
set -q USER_NAME || set -l USER_NAME manuel set -q USER_NAME || set -l USER_NAME manuel
set -q USER_DISPLAYNAME set -q USER_DISPLAYNAME
set -q USER_GROUPS || set -l USER_GROUPS "" set -q USER_GROUPS || set -l USER_GROUPS ""
@ -95,4 +96,19 @@ begin
and rm "$serviceFile" and rm "$serviceFile"
end end
end end
end
function autologin -S
set -l file "/etc/systemd/system/getty@tty1.service.d/autologin.conf"
arch-chroot "$mountDir" mkdir -p (dirname "$file")
begin
printf %s\n \
"[Service]" \
"ExecStart=" \
"ExecStart=-/sbin/agetty -o '-p -f -- \\u' --noclear --autologin root %I \$TERM"
end | arch-chroot "$mountDir" tee "$file" > /dev/null
end
source "$dir/../../Common/OS/setup.fish"
end end

View file

@ -0,0 +1,32 @@
#!/bin/env fish
begin
set -l dir (status dirname)
source "$dir/../Scripts/config.fish"
source "$dir/../Scripts/hooks.fish"
set -l name (getConfig valhalla.setupUser.name)
set -l mountDir (getConfig valhalla.partition.rootDir)
runHook setupOS || true
and runHook createUser || \
begin
chroot "$mountDir" \
useradd \
--comment "PortValhalla setup user" \
--system \
--no-user-group \
--groups wheel \
--create-home \
--uid (getConfig valhalla.setupUser.id --json) \
"$name"
end
chroot "$mountDir" usermod -aG wheel "$name"
begin
echo "$name ALL=(ALL:ALL) NOPASSWD: ALL"
end | chroot "$mountDir" tee "/etc/sudoers.d/PortValhalla" > /dev/null
and runHook autologin || true
and echo "Setup finished!"
and echo "Please reboot your machine"
end