aboutsummaryrefslogtreecommitdiff
path: root/modules/customs/soft-serve/default.nix
blob: 05156fd44f83279ba8fd33209afebbab47e9d1f8 (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
{ config, lib, pkgs, ... }:
with lib;
let
  cfg = config.services.soft-serve;
  cfgFile = format.generate "config.yaml" cfg.settings;
  format = pkgs.formats.yaml { };
  dataDir = cfg.dataDir;
  docUrl = "https://github.com/charmbracelet/soft-serve";
in
{
  disabledModules = [ "services/misc/soft-serve.nix" ];

  options = {
    services.soft-serve = {
      enable = mkEnableOption "soft-serve";
      package = mkPackageOption pkgs "soft-serve" { };
      dataDir = mkOption {
        type = types.str;
        default = "/var/lib/soft-serve";
        description = ''
          The directory where soft-serve stores its data files.
        '';
      };
      settings = mkOption {
        type = format.type;
        default = { };
        description = ''
          soft-serve server configurations stored under your data directory.
          See <${docUrl}>.
        '';
      };
    };
  };

  config = mkIf cfg.enable {
    systemd.tmpfiles.rules = [
      "L+ ${dataDir}/config.yaml - - - - ${cfgFile}"
    ];

    systemd.services.soft-serve = {
      description = "Soft Serve git server";
      documentation = lists.singleton docUrl;
      requires = lists.singleton "network-online.target";
      after = lists.singleton "network-online.target";
      wantedBy = lists.singleton "multi-user.target";
      environment.SOFT_SERVE_DATA_PATH = dataDir;
      serviceConfig = {
        Type = "simple";
        Restart = "always";
        RestartSec = 1;
        ExecStart = "${getExe cfg.package} serve";
        WorkingDirectory = dataDir;
      };
    };

    environment.systemPackages = with pkgs; [
      git
    ];
  };
}