nix/docs/setup.sh
2025-01-10 20:26:57 +00:00

56 lines
1.6 KiB
Bash
Executable file

#!/usr/bin/env bash
pushd /etc/nixos/git
# Home-Manager Setup
echo ">>> Setting up Home Manager..... "
sudo mkdir /nix/var/nix/profiles/per-user/albert
# For some reason the syncthing folder takes this over and makes it owned by root
sudo mkdir /home/albert/.config
sudo chown albert:albert /home/albert/.config
sudo chown -R albert:root /nix/var/nix/profiles/per-user/albert
home-manager switch -b backup --flake /etc/nixos/git
# Setup SOPS
echo "Setting up SOPS keys..... "
echo ">>> !!!!!"
echo ">>> !!!!!"
echo ">>> !!!!!"
echo ">>> !!!!! Copy this signature to .sops.yaml: "
# Currently only RSA keys are allowed
# Forcing v1.1.2 for this issue:
# https://github.com/Mic92/ssh-to-pgp/issues/73
sudo nix run \
github:Mic92/ssh-to-pgp/c175033ca42c116939a3decb2a6461b7396c9bb1 --\
-comment "Generated `date +%Y.%m.%d`" \
-email "root@`hostname`" \
-i /etc/ssh/ssh_host_rsa_key \
-o /etc/nixos/git/keys/hosts/$(hostname).asc
echo ">>> !!!!!"
echo ">>> !!!!!"
echo ">>> !!!!!"
# Set up ssh keys
echo ">>> Setting up SSH Keys..... "
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -N ""
echo "" >> ./keys/ssh/keys.txt
echo "# ($(date)) $(whoami)@$(hostname)" >> ./keys/ssh/keys.txt
cat /home/albert/.ssh/id_ed25519.pub >> ./keys/ssh/keys.txt
# Add all changes to git and and push
echo ">>> Pushing to git..... "
git add keys/hosts/`hostname`.asc
git -c commit.gpgsign=false commit -am "Setup: `hostname`"
git push
echo
echo
echo ">>> Complete. Once '.sops.yaml' is updated, "
echo ">>> run 'update-secrets' and reboot."
echo
echo
echo ">>> Reminder: Upload these changes to git"
popd || exit