set -l dir (status dirname) function runAction -V dir source "$dir/hooks.fish" source "$dir/nix.fish" source "$dir/settings.fish" echo "Installing dependencies..." and runHook --force installValhallaDeps 'Please set up a function `installValhallaDeps` for installing `fish`, `git`, `jq`, `nix`, `sudo` and `tmux`.' and echo "Preparing nix..." and runHook prepareNix || installNixPkgs if [ -z "$CONFIG_NAME" ] selectProfile config set -x CONFIG_NAME "$config" end and runHook actionInitialization || true echo "Flagging repository as safe..." sudo git config --system --add safe.directory (realpath "$(status dirname)/../..") and runHook actionPreRun || true $argv and runHook actionPostRun || true sudo git config remove-section --system safe || true end function runSetupUserAction -V dir source "$dir/nix.fish" function setupUserAction -V dir -V sudoConfig if [ (id -u) -eq 0 ] set -l cmdline (cat /proc/$fish_pid/cmdline | string split0) if [ -z "$TMUX" ] tmux new-session -e "CONFIG_NAME=$CONFIG_NAME" $cmdline else source "$dir/settings.fish" set -l sudoConfig "/etc/sudoers.d/PortValhalla" set -l name (getOSConfig setupUser.name) begin echo "Creating setup user" and useradd \ --comment "PortValhalla Setup User" \ --system \ --no-user-group \ --groups nix-users \ --create-home \ --uid (getOSConfig setupUser.id --json) \ "$name" end and begin echo "$name ALL=(ALL:ALL) NOPASSWD: ALL" end >"$sudoConfig" and sudo --preserve-env --set-home --user "$name" $cmdline rm "$sudoConfig" userdel -rf "$name" end else $argv uninstallNixPkgs end end runAction setupUserAction $argv end