]> Git — Sourcephile - sourcephile-nix.git/blob - machines/mermet/security.nix
environment: add networking tools
[sourcephile-nix.git] / machines / mermet / security.nix
1 { pkgs, lib, config, machineName, ... }:
2 let
3 inherit (config.security) gnupg;
4 rootKey = "root/key";
5 initrdKey = "initrd/ssh.key";
6 keygrip = "89F52A879E0019A966503AFFDE72EEA84CDFA3A7";
7 in
8 {
9 imports = [
10 <nixpkgs/nixos/modules/profiles/hardened.nix>
11 ];
12 security.gnupg.store = builtins.getEnv "PASSWORD_STORE_DIR" + "/machines/${machineName}";
13 services.openssh.extraConfig = ''
14 StreamLocalBindUnlink yes
15 '';
16 installer.ssh-nixos = {
17 PATH = [pkgs.gnupg pkgs.openssh];
18 script = lib.mkMerge [
19 (lib.mkBefore ''
20 # Send the SSH key of the initrd
21 gpg --decrypt '${gnupg.store}/${initrdKey}.gpg' |
22 ssh '${config.installer.ssh-nixos.target}' \
23 install -D -m 400 -o root -g root /dev/stdin /root/${initrdKey}
24 '')
25 (lib.mkBefore ''
26 ssh '${config.installer.ssh-nixos.target}' \
27 "gpg-connect-agent --no-autostart --homedir /var/lib/gnupg 'keyinfo --list' /bye 2>&1" |
28 grep -qx -e "gpg-connect-agent: no gpg-agent running in this session" \
29 -e "S KEYINFO ${keygrip} . . . 1 .*" || {
30 # Send the rootKey
31 gpg --decrypt '${gnupg.store}/${rootKey}.pass.gpg' |
32 gpg --batch --pinentry-mode loopback --passphrase-fd 0 --export-secret-subkeys @root@${machineName} |
33 ssh '${config.installer.ssh-nixos.target}' \
34 gpg --no-autostart --homedir /var/lib/gnupg --no-autostart --batch --pinentry-mode loopback --import
35
36 # Send the rootKey's passphrase
37 gpg --decrypt '${gnupg.store}/${rootKey}.pass.gpg' |
38 ssh '${config.installer.ssh-nixos.target}' \
39 gpg-preset-passphrase --homedir /var/lib/gnupg --preset ${keygrip}
40 }
41 '')
42 ];
43 };
44 boot.initrd.network.ssh.hostKeys = [ "/root/${initrdKey}" ];
45 }