]> Git — Sourcephile - sourcephile-nix.git/blob - servers/losurdo/security.nix
nix: add julm to some meta.maintainers
[sourcephile-nix.git] / servers / losurdo / security.nix
1 { pkgs, lib, config, ... }:
2 let
3 inherit (config.security) pass;
4 rootKey = "root/key";
5 in
6 {
7 imports = [
8 <nixpkgs/nixos/modules/profiles/hardened.nix>
9 ];
10 security.pass = {
11 store = ../../../sec/pass/servers/losurdo;
12 secrets."${rootKey}" = {
13 gpg = ../../../sec/gnupg/servers/losurdo/root/key.gpg;
14 # Symmetrically decrypt and load the rootKey into root's gnupg secret keyring.
15 postStart = ''
16 set -x
17 ${pkgs.gnupg}/bin/gpg --batch --pinentry-mode loopback \
18 --passphrase-file /${rootKey}.pass \
19 --import '${pass.secrets."${rootKey}".path}'
20 shred -u '${pass.secrets."${rootKey}".path}'
21 '';
22 };
23 };
24 install.ssh-nixos = {
25 PATH = with pkgs; [gnupg openssh];
26 # Decrypt the rootKey passphrase and send it to the target host.
27 script = lib.mkBefore ''
28 gpg --decrypt '${pass.store}/${rootKey}.pass.gpg' |
29 ssh '${config.install.ssh-nixos.target}' install -D -m 400 -o root -g root /dev/stdin /${rootKey}.pass
30 '';
31 };
32 systemd.services = lib.mapAttrs' (target: secret:
33 # Start the rootKey service before the other services decrypting secrets.
34 lib.nameValuePair (lib.removeSuffix ".service" secret.service)
35 (lib.optionalAttrs (target != "${rootKey}") {
36 after = [ pass.secrets."${rootKey}".service ];
37 wants = [ pass.secrets."${rootKey}".service ];
38 })
39 ) pass.secrets;
40 }