all repos — dns @ main

DNS records for my domains, managed via dnscontrol

shell.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
{
  pkgs ? (
    let
      sources = import ./lon.nix;
      pkgs = import sources.nixpkgs { };
    in
    pkgs
  ),
  lib ? pkgs.lib,
}:
let
  dnscontrol = pkgs.dnscontrol;

  types = pkgs.runCommand "dnscontrol-types" {
    runtimeInputs = [ dnscontrol ];
  } "${lib.getExe dnscontrol} write-types -o $out";
  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
  '';
in
pkgs.mkShellNoCC {
  packages = with pkgs; [
    lon
    just
    dnscontrol
    prettier

    # fallback for using lorri (shellHook doesn't work as expected)
    (writeShellScriptBin "update-types" update-types)
    (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"

    '')
  ];
  shellHook = update-types;
}