aboutsummaryrefslogtreecommitdiff
path: root/modules/home-manager/cooklang-chef/service.nix
blob: 8a9e34b56ce271701614a2ff22e2afb1ebfc13b6 (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
{ config, pkgs, lib, ... }:
with builtins // lib;
let
  cfg = config.services.cooklang-chef;
  pcfg = config.programs.cooklang-chef;
  args = escapeShellArgs ([
    "--port"
    (toString cfg.port)
    "--path"
    cfg.recipeRoot
  ] ++ cfg.extraArgs);
in {
  options.services.cooklang-chef = {
    enable = mkEnableOption "cooklang-chef webserver";
    package = mkOption {
      type = types.package;
      default = pcfg.package;
      description = ''
        cooklang-chef package. It is recommended to set this only in programs.cooklang-chef.
      '';
    };

    recipeRoot = mkOption {
      type = types.path;
      default = pcfg.settings.default_collection or "${config.xdg.dataHome}/cookbook";
    };

    port = mkOption {
      type = types.port;
      default = 9080;
    };

    extraArgs = mkOption {
      type = with types; listOf str;
      default = [];
    };
  };

  config = mkIf cfg.enable {
    systemd.user.services.cooklang-chef = {
      Unit = {
        Description = "A website for serving cooklang cookbooks";
        After = [ "network.target" ];
      };
      Service = {
        Restart = "on-failure";
        RestartSec = 10;
        Type = "simple";
        ExecStart = "${getExe cfg.package} serve ${args}";
      };
      Install = {
        WantedBy = [ "default.target" ];
      };
    };
  };
}