summary refs log tree commit diff
path: root/pkgs/common.nix
blob: 7493f41ddaffceda6ac0a98701453c55b4b36e6b (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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
{
  lib,
  dockerTools,
  system,
  ...
}:

let
  systemToArch = {
    "x86_64-linux" = {
      short = "x86";
      arch = "amd64";
    };
    "aarch64-linux" = {
      short = "arm";
      arch = "arm64";
    };
  };

  mkImage =
    {
      name,
      tag,
      digest,
      ...
    }@inputs:
    let
      arch = systemToArch.${system};

      image = dockerTools.pullImage {
        imageName = name;
        imageDigest = digest;
        finalImageName = name;
        finalImageTag = tag;
        os = "linux";
        inherit (inputs.${arch.short}) sha256;
        inherit (arch) arch;
      };
    in
    {
      image = "${name}:${tag}";
      imageFile = image;
      base = image;
    };

  images = {
    alpine = mkImage {
      name = "alpine";
      tag = "3.20.3";
      digest = "sha256:1e42bbe2508154c9126d48c2b8a75420c3544343bf86fd041fb7527e017a4b4a";
      x86.sha256 = "02fr1isg8s2h7j8n5rda7avswnh7vpfhrix3rmvqsjp8cx3qbkz3";
      arm.sha256 = "06c0q5kk60i89y1d83a28wk282ymp806xjcsmlca4cwwqp590j0q";
    };

    postgres13 = mkImage {
      name = "postgres";
      tag = "13-alpine";
      digest = "sha256:857aa00fc7e8541e3e5818b7bb8596182cb5c1b3ad964e4184e90682d5ca0d57";
      x86.sha256 = "1yc0576kdfsz55ybjaykki2mhr6w9yrby7wslx8pfmn7xkykzq9w";
      arm.sha256 = "0kjxk2sd03445mgf54x1ir9w2zmjn41zgmyns2h3k3cd7qazhkrx";
    };

    postgres14 = mkImage {
      name = "postgres";
      tag = "14-alpine";
      digest = "sha256:3f5fc44eeb8e8b42448e218f05299105761a2c33b54a89d9fd06c87cd5f7b043";
      x86.sha256 = "1zpiv9d6mj9d3n2xhgz0wn8q7a4gzjrk0hp8vpm706wwh72q8nir";
      arm.sha256 = "1gh6f4frfilr5mp6smp1k00aijd9vh1kv711a64044yl9kqr2nci";
    };

    postgres15 = mkImage {
      name = "postgres";
      tag = "15-alpine";
      digest = "sha256:8b963ea3038c3b32182ee7f592ccde21242fa7c5fd9d1b72aa333c27f1bfc809";
      x86.sha256 = "0cfmp4v1a4b2m21ljsc3f3kn23rl9nki6z37ks9jclzxh9hy629n";
      arm.sha256 = "0wydmscp4znjdflycvjqwjfry9crizhav0wc2hnajbyvk4ql32h8";
    };
  };

  soloOrDuoPort =
    p:
    with builtins;
    if isList p then
      assert length p == 2;
      {
        host = elemAt p 0;
        container = elemAt p 1;
      }
    else if isInt p then
      {
        host = p;
        container = p;
      }
    else
      throw "unknown port type given";

  ports = {
    globalPort =
      p:
      let
        ports = soloOrDuoPort p;
        host = toString ports.host;
        container = toString ports.container;
      in
      "0.0.0.0:${host}:${container}";

    tailnetPort =
      me: p:
      let
        ports = soloOrDuoPort p;
        host = toString ports.host;
        container = toString ports.container;
      in
      "${me.tailscale.ip}:${host}:${container}";
  };
in
images // ports