Compare commits

..

2 commits

2 changed files with 43 additions and 33 deletions

View file

@ -10,14 +10,15 @@ function runActionSetup -V dir
and runHook prepareNix || installNixPkgs
and echo "Flagging repository as safe..."
and sudo git config --system --add safe.directory (realpath "$(status dirname)/../..")
and sudo git config --system --add safe.directory (realpath -m "$(status dirname)/../..")
and runHook actionPreRun || true
end
function runActionConfigure
function runActionConfigure -V dir
and if [ -z "$CONFIG_NAME" ]
source "$dir/settings.fish"
selectProfile config
set -x CONFIG_NAME "$config"
set -gx CONFIG_NAME "$config"
end
end
@ -37,39 +38,44 @@ function runAction -V dir
end
function runSetupUserAction -V dir
if [ (id -u) -eq 0 ]
source "$dir/settings.fish"
runActionSetup
runActionConfigure
set -l env "CONFIG_NAME=$CONFIG_NAME"
set -l name (getOSConfig setupUser.name)
if [ "$USER" != "$name" ]
set -l cmdline (cat /proc/$fish_pid/cmdline | string split0)
if [ -z "$TMUX" ]
runActionSetup
tmux new-session -e "CONFIG_NAME=$CONFIG_NAME" $cmdline
if [ (id -u) -ne 0 ]
sudo --set-home --preserve-env $cmdline
else
source "$dir/settings.fish"
runActionConfigure
set -l sudoConfig "/etc/sudoers.d/PortValhalla"
set -l name (getOSConfig setupUser.name)
if [ -z "$TMUX" ]
tmux new-session -e "$env" $cmdline
else
set -l sudoConfig "/etc/sudoers.d/PortValhalla"
and begin
echo "Creating setup user"
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"
and useradd \
--comment "PortValhalla Setup User" \
--system \
--groups nix-users \
--create-home \
--uid (getOSConfig setupUser.id --json) \
"$name"
and begin
echo "$name ALL=(ALL:ALL) NOPASSWD: ALL"
end >"$sudoConfig"
and sudo --preserve-env --set-home --user "$name" $cmdline
disposeAction
rm "$sudoConfig"
userdel -rf "$name"
end
end
and begin
echo "$name ALL=(ALL:ALL) NOPASSWD: ALL"
end >"$sudoConfig"
and sudo --preserve-env --set-home --user "$name" $cmdline
disposeAction
rm "$sudoConfig"
userdel -rf "$name"
end
else
$argv

View file

@ -3,10 +3,14 @@ begin
set -l config "$dir/config.fish"
set nixPkgsDir "/nix/var/nix/profiles/per-user/root/channels/nixpkgs"
function __isNixModule -a path
nix-instantiate --eval --expr "{ path }: import path" --argstr path "$path" &>/dev/null
end
function downloadNixPkgs -V config
source "$config"
if [ ! -d "$nixPkgsCache" ]
if ! __isNixModule "$nixPkgsCache"
mkdir -p "$nixPkgsCache"
and git clone https://github.com/NixOS/nixpkgs.git --depth=1 -b "$nixPkgsVersion" "$nixPkgsCache"
and rm -rf "$nixPkgsCache/.git"
@ -16,8 +20,8 @@ begin
function installNixPkgs -V config -V nixPkgsDir
source "$config"
if [ ! -d "$nixPkgsDir" ]
if [ ! -d "$nixPkgsCache" ]
if ! __isNixModule "$nixPkgsDir"
if ! __isNixModule "$nixPkgsCache"
downloadNixPkgs
end