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

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

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

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

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