nix-setup/nixos-edit.script.nix

67 lines
1.7 KiB
Nix
Raw Normal View History

with import <nixpkgs> {};
pkgs.writeShellScriptBin "nixos-edit" ''
#!/bin/sh
2024-10-19 02:39:35 +02:00
if [ "$1" = "init" ] ; then
2024-10-19 03:02:29 +02:00
if [ "$(whoami)" != root ] ; then
echo "re-executing as tudbut"
echo -n "set password for tudbut? (Y/n) "
read yn
if [ "$yn" != "n" ] ; then
passwd tudbut || exit 1
fi
sleep 2
exec sudo -u tudbut nixos-edit init || exit 1
fi
2024-10-19 02:39:35 +02:00
sudo chown -R tudbut: /etc/nixos
echo dir setup done
2024-10-19 03:02:29 +02:00
echo "> setting up ssh"
echo ssh setup
if ! [ -e ~/.ssh/id_rsa ] ; then
ssh-keygen || exit
fi
echo ssh key created
cat ~/.ssh/id_rsa.pub | xclip -selection clipboard
echo "-> copied to clipboard for later"
echo adding it to syncfs
echo "-> you will need to input your password"
ssh root@tudbut.de ssh -p 23 localhost bash -c "echo -e '# $(cat /etc/hostname)\n$(cat ~/.ssh/id_rsa.pub)\n' >> .ssh/authorized_keys" || exit 1
echo "> ssh setup done"
echo "> setting up git"
git config --global user.name "TudbuT"
git config --global user.email "forge-public@mail.tudbut.de"
git config --global init.defaultBranch main
git config --global push.default current
echo configs set
echo mounting syncfs
startsync > /dev/null 2>&1 &
echo opening git key add page
echo "-> close firefox when complete."
firefox "https://git.tudbut.de/user/login?redirect_to=%2fuser%2fsettings%2fkeys" > /dev/null 2>&1
echo correcting remote
cd /etc/nixos
git remote set-url origin 'ssh://git@tudbut.de:222/TudbuT/nix-setup.git'
echo done
2024-10-19 02:39:35 +02:00
exit 0
fi
cd /etc/nixos
if [ "$1" = "pull" ] ; then
git pull
fi
if [ "$1" = "edit" ] || [ "$1" = "" ] ; then
sudo hx .
git add .
EDITOR=hx git commit -a
git push
fi
if [ "$1" = "update" ] ; then
git push
sudo nixos-rebuild switch --upgrade
else
sudo nixos-rebuild switch
fi
''