auto: bootstrapping sparky
This commit is contained in:
parent
280d7a6213
commit
95a5f258f9
|
@ -228,11 +228,11 @@
|
|||
"nix-secrets": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1716728224,
|
||||
"narHash": "sha256-dgsNHeMkH4z++dpZvNXEDySvJdalXmz4Xz7JNyWxH1w=",
|
||||
"lastModified": 1716728838,
|
||||
"narHash": "sha256-Gmsb1Bovwg+6XTwuyohpv1Ez8em0phLDEPWyh1Z4vS4=",
|
||||
"ref": "refs/heads/master",
|
||||
"rev": "d0273ccbae8ca91ff7684a7b65f328eb28a3cb79",
|
||||
"revCount": 43,
|
||||
"rev": "46bedb594c7f12f800a3d224e549dede64da968b",
|
||||
"revCount": 44,
|
||||
"type": "git",
|
||||
"url": "ssh://git@git.bitlab21.com/sam/nix-secrets.git"
|
||||
},
|
||||
|
|
|
@ -23,7 +23,7 @@ sed -i "/$ip/d" ~/.ssh/known_hosts
|
|||
echo "Copying pubkey to target host"
|
||||
ssh-copy-id -i "$(readlink -f "$HOME/.ssh/id_ed25519.pub")" "root@$ip"
|
||||
|
||||
# Create temp directory for ssh and luks to be copied to host:
|
||||
# Create temp directory for ssh keys to be copied to host:
|
||||
temp=$(mktemp -d)
|
||||
|
||||
# Function to cleanup temporary directory on exit
|
||||
|
@ -32,19 +32,13 @@ cleanup() {
|
|||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
# Create the directory where services are to find the host keys
|
||||
# Create the directory where sshd expects to find the host keys
|
||||
install -d -m755 "$temp/persist/etc/ssh"
|
||||
install -d -m755 "$temp/tmp"
|
||||
|
||||
# Extract luks key from secrets
|
||||
luks_key=$(nix-shell -p sops --run "SOPS_AGE_KEY_FILE=~/.config/sops/age/keys.txt sops -d --extract '[""\"passwords""\"][""\"root""\"]' ../nix-secrets/secrets.yaml")
|
||||
echo "$luks_key" > "$temp/tmp/luks_secrets.key"
|
||||
|
||||
# Create ssh keys if not exists
|
||||
echo "Creating '$hostname' ssh keys"
|
||||
ssh-keygen -t ed25519 -f "$temp/persist/etc/ssh/ssh_host_ed25519_key" -C root@"$hostname" -N ""
|
||||
|
||||
# Change permissions
|
||||
chmod 600 "$temp/persist/etc/ssh/ssh_host_ed25519_key"
|
||||
chmod 644 "$temp/persist/etc/ssh/ssh_host_ed25519_key.pub"
|
||||
|
||||
|
@ -67,6 +61,10 @@ sed -i "{
|
|||
|
||||
just update-sops-secrets && just update-flake-secrets && just update-flake
|
||||
|
||||
# Extract luks key from secrets
|
||||
luks_key=$(nix-shell -p sops --run "SOPS_AGE_KEY_FILE=~/.config/sops/age/keys.txt sops -d --extract '[""\"passwords""\"][""\"root""\"]' ../nix-secrets/secrets.yaml")
|
||||
echo "$luks_key" > /tmp/luks_secret.key
|
||||
|
||||
# Install Nixos to target
|
||||
cd "$HOME/nixos"
|
||||
git add . && git commit -m "auto: bootstrapping $hostname" && git push
|
||||
|
@ -74,6 +72,9 @@ git add . && git commit -m "auto: bootstrapping $hostname" && git push
|
|||
SHELL=/bin/sh nix run github:nix-community/nixos-anywhere -- --extra-files "$temp" --flake .#"$config" root@"$ip" -i "$HOME/.ssh/id_ed25519"
|
||||
[ $? != 0 ] && echo "Error installing Nixos" && exit 1
|
||||
|
||||
# Delete luks key
|
||||
rm /tmp/luks_secret.key
|
||||
|
||||
## Delete keys from local known_hosts
|
||||
echo "Deleting host from known_hosts"
|
||||
sed -i "/$ip/d" ~/.ssh/known_hosts
|
||||
|
|
Loading…
Reference in New Issue