DEVELOPMENT ENVIRONMENT

~liljamo/canwa

ref: f07712ffc5f21bd3755ef74dfe5d5dd467e620aa canwa/nix/module.nix -rw-r--r-- 1.3 KiB
f07712ffJonni Liljamo feat: nix updates, package and module 15 hours ago
                                                                                
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
{
  config,
  lib,
  pkgs,
  ...
}: let
  cfg = config.services.canwa;
  configFormat = pkgs.formats.toml {};
  configFile = configFormat.generate "canwa.toml" cfg.config;
  checkedConfig =
    pkgs.runCommand "checked-canwa.toml" {
    } ''
      cp ${configFile} $out
      ${cfg.package}/bin/canwa --config $out --dry-run
    '';
in {
  options = {
    services.canwa = {
      enable = lib.mkEnableOption "canwa";

      package = lib.mkOption {
        type = lib.types.package;
      };

      user = lib.mkOption {
        type = lib.types.str;
        default = "canwa";
      };

      group = lib.mkOption {
        type = lib.types.str;
        default = "canwa";
      };

      config = lib.mkOption {
        type = configFormat.type;
        default = {};
      };
    };
  };

  config = lib.mkIf cfg.enable {
    systemd.services.canwa = {
      description = "canwa";
      after = ["network-online.target"];
      wants = ["network-online.target"];
      wantedBy = ["multi-user.target"];
      serviceConfig = {
        DynamicUser = true;
        User = cfg.user;
        Group = cfg.group;
        ExecStart = lib.escapeShellArgs [
          "${cfg.package}/bin/canwa"
          "--config"
          "${checkedConfig}"
        ];
        Restart = "on-failure";
      };
    };
  };
}