summaryrefslogtreecommitdiffstats
path: root/nixos/modules/services/networking/nix-store-gcs-proxy.nix
blob: 828f4d5c244dc9068fbccdd46bc578a550669d57 (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
{
  config,
  lib,
  pkgs,
  ...
}:

with lib;

let
  opts =
    { name, config, ... }:
    {
      options = {
        enable = mkOption {
          default = true;
          type = types.bool;
          example = true;
          description = "Whether to enable proxy for this bucket";
        };
        bucketName = mkOption {
          type = types.str;
          default = name;
          example = "my-bucket-name";
          description = "Name of Google storage bucket";
        };
        address = mkOption {
          type = types.str;
          example = "localhost:3000";
          description = "The address of the proxy.";
        };
      };
    };
  enabledProxies = lib.filterAttrs (n: v: v.enable) config.services.nix-store-gcs-proxy;
  mapProxies = function: lib.mkMerge (lib.mapAttrsToList function enabledProxies);
in
{
  options.services.nix-store-gcs-proxy = mkOption {
    type = types.attrsOf (types.submodule opts);
    default = { };
    description = ''
      An attribute set describing an HTTP to GCS proxy that allows us to use GCS
      bucket via HTTP protocol.
    '';
  };

  config.systemd.services = mapProxies (
    name: cfg: {
      "nix-store-gcs-proxy-${name}" = {
        description = "A HTTP nix store that proxies requests to Google Storage";
        wantedBy = [ "multi-user.target" ];

        startLimitIntervalSec = 10;
        serviceConfig = {
          RestartSec = 5;
          ExecStart = ''
            ${pkgs.nix-store-gcs-proxy}/bin/nix-store-gcs-proxy \
              --bucket-name ${cfg.bucketName} \
              --addr ${cfg.address}
          '';

          DynamicUser = true;

          ProtectSystem = "strict";
          ProtectHome = true;
          PrivateTmp = true;
          PrivateDevices = true;
          PrivateMounts = true;
          PrivateUsers = true;

          ProtectKernelTunables = true;
          ProtectKernelModules = true;
          ProtectControlGroups = true;

          NoNewPrivileges = true;
          LockPersonality = true;
          RestrictRealtime = true;
        };
      };
    }
  );

  meta.maintainers = [ maintainers.mrkkrp ];
}