mirror of
https://github.com/SebastianStork/nixos-config.git
synced 2026-01-21 15:11:34 +01:00
Add script to provision keys
This commit is contained in:
parent
d71748e36a
commit
07635949e6
3 changed files with 53 additions and 2 deletions
|
|
@ -70,8 +70,8 @@
|
||||||
./flake/dev-shell.nix
|
./flake/dev-shell.nix
|
||||||
./flake/formatter.nix
|
./flake/formatter.nix
|
||||||
./flake/hosts.nix
|
./flake/hosts.nix
|
||||||
./flake/install-anywhere.nix
|
|
||||||
./flake/modules.nix
|
./flake/modules.nix
|
||||||
|
./flake/scripts.nix
|
||||||
./flake/sops.nix
|
./flake/sops.nix
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
|
||||||
50
flake/scripts.nix
Normal file
50
flake/scripts.nix
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
_: {
|
||||||
|
perSystem =
|
||||||
|
{ pkgs, ... }:
|
||||||
|
{
|
||||||
|
packages.provision-keys = pkgs.writeShellApplication {
|
||||||
|
name = "provision-keys";
|
||||||
|
|
||||||
|
runtimeInputs = [
|
||||||
|
pkgs.sops
|
||||||
|
pkgs.ssh-to-age
|
||||||
|
|
||||||
|
pkgs.bitwarden-cli
|
||||||
|
pkgs.jq
|
||||||
|
];
|
||||||
|
|
||||||
|
excludeShellChecks = [ "SC2155" ];
|
||||||
|
|
||||||
|
text = ''
|
||||||
|
if [[ $# -ne 1 ]]; then
|
||||||
|
echo "Usage: $0 <host>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
host="$1"
|
||||||
|
|
||||||
|
impermanence=$(nixos-option --flake ".#$host" custom.impermanence.enable | awk '/^Value:/ {getline; print $1}')
|
||||||
|
|
||||||
|
if [ "$impermanence" = "true" ]; then
|
||||||
|
root="/tmp/anywhere/$host/persist"
|
||||||
|
else
|
||||||
|
root="/tmp/anywhere/$host"
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir --parents "$root/etc/ssh"
|
||||||
|
ssh-keygen -C "root@$host" -f "$root/etc/ssh/ssh_host_ed25519_key" -N "" -q
|
||||||
|
|
||||||
|
new_age_key=$(ssh-to-age -i "$root/etc/ssh/ssh_host_ed25519_key.pub")
|
||||||
|
|
||||||
|
# Replace old age key with new age key
|
||||||
|
sed -i -E "s|(agePublicKey\s*=\s*\")[^\"]*(\";)|\1$new_age_key\2|" "hosts/$host/default.nix"
|
||||||
|
|
||||||
|
export BW_SESSION=$(bw login | awk -F'"' '/export BW_SESSION/ {print $2}')
|
||||||
|
export SOPS_AGE_KEY=$(bw get item 'admin age-key' | jq -r '.notes')
|
||||||
|
export SOPS_CONFIG=$(nix build .#sops-config --print-out-paths)
|
||||||
|
|
||||||
|
sops updatekeys --yes "hosts/$host/secrets.json"
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
3
justfile
3
justfile
|
|
@ -20,7 +20,8 @@ deploy +hosts:
|
||||||
deploy --skip-checks --targets $(echo {{ hosts }} | sed 's/[^ ]*/\.#&/g')
|
deploy --skip-checks --targets $(echo {{ hosts }} | sed 's/[^ ]*/\.#&/g')
|
||||||
|
|
||||||
install host destination='root@installer':
|
install host destination='root@installer':
|
||||||
nix run github:nix-community/nixos-anywhere -- --extra-files ~/.ssh/{{ host }} --flake .#{{ host }} --target-host {{ destination }}
|
nix run .#provision-keys -- {{ host }}
|
||||||
|
nix run github:nix-community/nixos-anywhere -- --extra-files /tmp/anywhere/{{ host }} --flake .#{{ host }} --target-host {{ destination }}
|
||||||
|
|
||||||
repair:
|
repair:
|
||||||
nix-store --verify --check-contents --repair
|
nix-store --verify --check-contents --repair
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue