summaryrefslogtreecommitdiff
path: root/hosts/surtr/tls.nix
blob: 63d3a897f7fbfc7af62e71dee103c76787a4257c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
{ pkgs, ... }:
let
  knotDNSCredentials = zone: pkgs.writeTextFile "lego-credentials" ''
    EXEC_PATH=${knotDNSExec zone}/bin/update-dns.sh
  '';
  knotDNSExec = zone: pkgs.writeScriptBin "update-dns.sh" ''
    #!${pkgs.zsh}/bin/zsh -xe

    mode=$1
    fqdn=$2
    challenge=$3

    owner=''${fqdn%"${zone}."}

    knotc zone-begin "${zone}"

    case "''${mode}" in
      present)
        knotc zone-set ${zone} "''${owner}" 300 TXT "''${challenge}"
        ;;
      cleanup)
        knotc zone-unset ${zone} "''${owner}" TXT "''${challenge}"
        ;;
      *)
        exit 2
        ;;
    esac

    knotc zone-commit "${zone}"
  '';
in {
  config = {
    fileSystems."/var/lib/acme" =
      { device = "surtr/safe/var-lib-acme";
        fsType = "zfs";
      };

    security.acme = {
      server = "https://acme-staging-v02.api.letsencrypt.org/directory";
      
      acceptTerms = true;
      preliminarySelfsigned = false;
      email = "phikeebaogobaegh@141.li";
      certs = {
        "rheperire.org" = {
          domain = "rheperire.org";
          extraDomainNames = [ "*.rheperire.org" ];
          dnsProvider = "exec";
          credentialsFile = knotDNSCredentials "rheperire.org";
        };
      };
    };
  };
}