all repos — dns @ main

DNS records for my domains, managed via dnscontrol

flake.nix (view raw)

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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
{
  description = "A very basic flake";

  inputs = {
    nixpkgs.url = "https://channels.nixos.org/nixos-26.05/nixexprs.tar.zst";
  };

  outputs = { nixpkgs, ... }: {
    devShells = builtins.mapAttrs (system: pkgs: {
      default =
        let
          inherit (pkgs) lib;
          dnscontrol = pkgs.dnscontrol;

          types = pkgs.runCommand "dnscontrol-types" {
            runtimeInputs = [ dnscontrol ];
          } "${lib.getExe dnscontrol} write-types -o $out";

          update-types = pkgs.writeScriptBin "update-types" ''
            f="types-dnscontrol.d.ts"
            if [[ -e "$f" && ! -L "$f" ]]
            then
              echo "warn: file $f already exists, not updating. Remove to enable automatic updates." >&2
            elif [[ ! ( -L "$f" && "$(readlink -f "$f")" == "${types}" ) ]]
            then
              ln -sf "${types}" "$f"
            fi
          '';

          # fallback for using lorri (shellHook doesn't work as expected)
          get-consumer-key = pkgs.writeScriptBin "get-consumer-key" ''
            #!/${pkgs.fishMinimal}
            # adapted from <https://docs.dnscontrol.org/provider/ovh#activation>

            if set --query OVH_CONSUMER_KEY
                echo >&2 "Nothing to do. OVH_CONSUMER_KEY is set."
                exit 0
            end

            if ! set --query OVH_APP_KEY
                echo >&2 'Need $OVH_APP_KEY! Go to https://eu.api.ovh.com/createApp/'
                exit 1
            end

            set accessRules '[
                {
                    "method": "DELETE",
                    "path": "/domain/zone/*"
                },
                {
                    "method": "GET",
                    "path": "/domain/zone/*"
                },
                {
                    "method": "POST",
                    "path": "/domain/zone/*"
                },
                {
                    "method": "PUT",
                    "path": "/domain/zone/*"
                },
                {
                    "method": "GET",
                    "path": "/domain/*"
                },
                {
                    "method": "PUT",
                    "path": "/domain/*"
                },
                {
                    "method": "POST",
                    "path": "/domain/*/nameServers/update"
                }
            ]'

            xh --body \
                POST https://eu.api.ovh.com/1.0/auth/credential \
                X-Ovh-Application:"$OVH_APP_KEY" \
                accessRules:="$accessRules"

          '';
        in
        pkgs.mkShellNoCC {
          packages = with pkgs; [
            just
            dnscontrol
            prettier
            get-consumer-key
            update-types
          ];
        };

      ci = pkgs.mkShellNoCC {
        packages = with pkgs; [
          just
          dnscontrol
        ];
      };
    }) nixpkgs.legacyPackages;
  };
}