summaryrefslogtreecommitdiffstats
path: root/nixos/modules/services/web-apps/immich-kiosk.nix
blob: 97aef228d73b43378a745ee222d720043bfbd6d3 (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
{
  config,
  lib,
  pkgs,
  utils,
  ...
}:
let
  cfg = config.services.immich-kiosk;
  format = pkgs.formats.json { };
  secretsReplacement = utils.genJqSecretsReplacement {
    loadCredential = true;
  } cfg.settings "/run/immich-kiosk/config.yaml";
in
{
  meta.maintainers = with lib.maintainers; [ tlvince ];

  options.services.immich-kiosk = {
    enable = lib.mkEnableOption "Immich Kiosk slideshow service";

    package = lib.mkPackageOption pkgs "immich-kiosk" { };

    openFirewall = lib.mkOption {
      type = lib.types.bool;
      default = false;
      description = ''
        Whether to open the firewall for the immich-kiosk port.
      '';
    };

    settings = lib.mkOption {
      type = lib.types.submodule {
        freeformType = format.type;
        options = {
          immich_url = lib.mkOption {
            type = lib.types.str;
            default = config.services.immich.settings.server.externalDomain;
            defaultText = lib.literalExpression "config.services.immich.settings.server.externalDomain";
            description = ''
              URL of the immich instance.
            '';
          };

          kiosk.port = lib.mkOption {
            type = lib.types.port;
            default = 3000;
            description = ''
              Port on which immich-kiosk will listen.
            '';
          };
        };
      };
      default = { };
      description = ''
        Configuration for immich-kiosk. See
        <https://docs.immichkiosk.app/configuration/>
        for available options. Secret values can be loaded from files using
        `._secret = "/path/to/secret";`.
      '';
      example = lib.literalExpression ''
        {
          immich_url = "https://immich.example.com";
          immich_api_key._secret = "/run/secrets/immich-kiosk-api-key";
          albums = [
            "4fa933cf-051f-4621-9ac7-8d06776c261c"
            "6466548c-4995-4fb5-ab1f-f63cc9ff3e5f"
          ];
          duration = 30;
          layout = "splitview";
          disable_ui = true;
        }
      '';
    };
  };

  config = lib.mkIf cfg.enable {
    systemd.services.immich-kiosk = {
      description = "Immich Kiosk slideshow service";
      after = [ "immich-server.service" ];
      wantedBy = [ "multi-user.target" ];

      preStart = secretsReplacement.script;

      serviceConfig = {
        DynamicUser = true;
        ExecStart = lib.getExe cfg.package;
        Group = "immich-kiosk";
        LoadCredential = secretsReplacement.credentials;
        Restart = "on-failure";
        RestartSec = 10;
        RuntimeDirectory = "immich-kiosk";
        RuntimeDirectoryMode = "0700";
        SyslogIdentifier = "immich-kiosk";
        Type = "simple";
        User = "immich-kiosk";
        WorkingDirectory = "/run/immich-kiosk";

        # Hardening
        CapabilityBoundingSet = [ "" ];
        LockPersonality = true;
        NoNewPrivileges = true;
        PrivateDevices = true;
        PrivateTmp = true;
        PrivateUsers = true;
        ProtectClock = true;
        ProtectControlGroups = true;
        ProtectHome = true;
        ProtectHostname = true;
        ProtectKernelLogs = true;
        ProtectKernelModules = true;
        ProtectKernelTunables = true;
        ProtectProc = "invisible";
        RestrictAddressFamilies = [
          "AF_INET"
          "AF_INET6"
        ];
        RestrictNamespaces = true;
        RestrictRealtime = true;
        RestrictSUIDSGID = true;
        SystemCallArchitectures = "native";
        SystemCallFilter = [
          "@system-service"
          "~@privileged"
          "~@resources"
        ];
        UMask = "0077";
      };
    };

    networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall [ cfg.settings.kiosk.port ];
  };
}