aboutsummaryrefslogtreecommitdiff
path: root/modules/services/nixos/glance.nix
blob: 04b2e0909f78dcd3f385970bcb7749cba7f955b5 (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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
{
  pkgs,
  config,
  lib,
  ...
}: let
  cfg = config.collinux.services.glance;

  modularService = {
    lib,
    config,
    options,
    ...
  }: let
    cfg = config.glance;
  in {
    options.glance = {
      package = lib.mkOption {
        description = "the `glance` package";
        type = lib.types.package;
      };
      settings = lib.mkOption {
        description = "glance configuration file contents";
        type = (pkgs.formats.json {}).type;
      };
    };
    config =
      {
        configData."config.yml".text = builtins.toJSON (
          {
            server = {
              port = 8080;
              proxied = true;
              host = "127.0.0.1";
              assets-path = "/var/lib/glance";
            };
          }
          // cfg.settings
        );
        process.argv = [(lib.getExe cfg.package) "-config" config.configData."config.yml".path];
      }
      // lib.optionalAttrs (options ? systemd) {
        systemd.service = {
          wantedBy = ["multi-user.target"];

          serviceConfig = {
            DynamicUser = true;
            StateDirectory = "glance";

            PrivateNetwork = true;
            NoNewPrivileges = true;
            PrivateTmp = true;
            ProtectSystem = "strict";
            ProtectHome = true;
            ProtectKernelTunables = true;
            ProtectKernelModules = true;
            ProtectControlGroups = true;
          };
        };

        systemd.sockets."glance-proxy" = {
          wantedBy = ["sockets.target"];
          listenStreams = ["/run/glance/glance.sock"];
          socketConfig = {
            SocketMode = "0660";
            SocketGroup = "caddy";
          };
        };

        systemd.services."glance-proxy" = {
          requires = ["glance.service"];
          after = ["glance.service"];
          unitConfig.JoinsNamespaceOf = "glance.service";

          serviceConfig = {
            ExecStart = "${pkgs.systemd}/lib/systemd/systemd-socket-proxyd 127.0.0.1:8080";
            DynamicUser = true;
            PrivateNetwork = true;
            PrivateTmp = true;
            NoNewPrivileges = true;
            ProtectSystem = "strict";
            ProtectHome = true;
          };
        };
      };
  };
in {
  config = lib.mkIf cfg.enable {
    system.services."glance" = {
      imports = [modularService];
      glance = {
        package = pkgs.glance;
        settings = let
          servicesLinks = builtins.attrValues cfg.homelabServices;
          wrap = x: [x];
        in {
          branding.hide-footer = true;
          pages = wrap {
            name = "Dashboard";
            width = "slim";
            hide-desktop-navigation = true;
            center-vertically = true;
            columns = wrap {
              size = "full";
              widgets = [
                {
                  type = "search";
                  autofocus = true;
                  search-engine = "duckduckgo";
                  bangs = [
                    {
                      title = "GitHub";
                      shortcut = "gh";
                      url = "https://github.com/search?q={QUERY}&type=repositories";
                    }
                    {
                      title = "I'm Feeling Lucky";
                      shortcut = "!";
                      url = "https://www.google.com/search?q={QUERY}&btnI=&sourceid=navclient&gfns=1";
                    }
                    {
                      title = "YouTube Music";
                      shortcut = "ytm";
                      url = "https://music.youtube.com/search?q={QUERY}";
                    }
                    {
                      title = "Google AI Mode";
                      shortcut = "ai";
                      url = "https://www.google.com/search?udm=50&q={QUERY}";
                    }
                  ];
                }
                {
                  type = "server-stats";
                  servers = wrap {
                    type = "local";
                    name = "ganymede";
                    hide-mountpoints-by-default = true;
                    mountpoints = {
                      "/".hide = false;
                      "/media".hide = false;
                    };
                  };
                }
                {
                  type = "monitor";
                  cache = "1m";
                  title = "Services";
                  sites = servicesLinks;
                }
              ];
            };
          };
        };
      };
    };

    services.caddy.virtualHosts."home.ganymede".extraConfig = ''
      import internal
      reverse_proxy unix///run/glance/glance.sock
    '';
  };
}