aboutsummaryrefslogtreecommitdiff
path: root/flakes/fiche/flake.nix
blob: 16055e8a32cf5be6a20631a2267150ed9d155e7f (plain) (blame)
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
{
  description = "Command line pastebin for sharing terminal output";

  outputs = { self }: {
    nixosModule = { config, lib, pkgs, ... }: {
      options.services.fiche = {
        enable = lib.mkEnableOption "Enable fiche’s service";
        port = lib.mkOption {
          type = lib.types.port;
          description = "Port to listen to";
        };
        domain = lib.mkOption {
          type = lib.types.str;
          description = "Domain";
        };
        dataDir = lib.mkOption {
          type = lib.types.path;
          default = "/var/lib/fiche";
          description = "Directory where to place the pastes";
        };
        https = lib.mkEnableOption "Use https";
      };

      config =
        let cfg = config.services.fiche;
        in lib.mkIf cfg.enable {
          networking.firewall.allowedTCPPorts = [ cfg.port ];

          systemd.services.fiche = {
            description = "Fiche server";
            wantedBy = [ "multi-user.target" ];
            after = [ "network.target" ];

            script = ''
              exec ${pkgs.fiche}/bin/fiche -o ${cfg.dataDir} -d ${cfg.domain} ${lib.optionalString cfg.https "-S "} -p ${builtins.toString cfg.port}
            '';

            serviceConfig = {
              ExecStartPre = [
                "+${pkgs.coreutils}/bin/install -m 0755 -o fiche -d ${cfg.dataDir}"
              ];
              DynamicUser = true;
              User = "fiche";
              PrivateTmp = true;
              Restart = "always";
              WorkingDirectory = cfg.dataDir;
              ReadWritePaths = cfg.dataDir;
            };
          };
        };
    };
  };
}