nix/docs/setup.sh

46 lines
1.5 KiB
Bash
Raw Normal View History

2023-09-18 09:16:55 +02:00
#!env /bin/bash
# First setup:
user=albert
2023-09-19 10:01:58 +02:00
read -p "Hostname: " hostname;
2023-09-18 09:16:55 +02:00
# run as root:
2023-09-19 10:01:58 +02:00
# eIf on the raspberry pi image:
# sudo nix-channel --add https://nixos.org/channels/nixpkgs-unstable
# sudo nix-channel --update
2023-09-18 09:16:55 +02:00
sudo nix-shell -p git --run git clone https://git.sysctl.io/albert/nix /etc/nixos/git
2023-09-19 00:05:36 +02:00
sudo git clone https://git.sysctl.io/albert/nix /etc/nixos/git
2023-09-18 09:16:55 +02:00
sudo ln -s /etc/nixos/git/flake.nix /etc/nixos/flake.nix
sudo chown -R $user:root /etc/nixos/git
sudo nixos-rebuild switch --flake '/etc/nixos#$host'
sudo mkdir /nix/var/nix/profiles/per-user/$user
echo "Host setup complete."
# as $user:
home-manager switch -b backup --flake /etc/nixos/git
source ~/.bashrc
# Import and trust the GPG key
read -p "Path to GPG Private Key: " gpgKey
gpg --import $gpgKey
echo -e "5\ny\n" | gpg --command-fd 0 --expert --edit-key 64F6C4EB46C4543A trust
# Setup SOPS
2023-09-19 10:01:58 +02:00
sudo nix-shell -p ssh-to-pgp --run "ssh-to-pgp -i /etc/ssh/ssh_host_rsa_key -o /etc/nixos/git/keys/hosts/$(hostname).asc"
# Update your .sops.yaml with this key
2023-09-18 09:16:55 +02:00
cd /etc/nixos/git
nix-shell
sops-update secrets/secrets.yaml
# Set up ssh keys
ssh-keygen -t rsa -b 8192 -f ~/.ssh/id_rsa -N ""
echo "" >> /etc/nixos/git/keys/ssh/keys.txt
2023-09-19 10:01:58 +02:00
echo "# `whoami`@`hostname`" >> /etc/nixos/git/keys/ssh/keys.txt
cat /home/albert/.ssh/id_rsa.pub >> /etc/nixos/git/keys/ssh/keys.txt
2023-09-18 09:16:55 +02:00
# Add all changes to git and and push
2023-09-19 10:01:58 +02:00
git add keys/hosts/`hostname`.asc
git commit -am "Setup of: `whoami`@`hostname`"
2023-09-18 09:16:55 +02:00
git push
echo "Complete. Reboot to complete the config"