summaryrefslogtreecommitdiffstats
path: root/makefu/3modules/udpt.nix
blob: 2086bd5407e86608d2539dd42105c7310075d034 (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
{ config, lib, pkgs, ... }:

with config.krebs.lib;
let
  cfg = config.makefu.udpt;

  out = {
    options.makefu.udpt = api;
    config = lib.mkIf cfg.enable imp;
  };

  api = {
    enable = mkEnableOption "udpt";

    package = mkOption {
      type = types.package;
      default = pkgs.udpt;
    };

    cfgfile = mkOption {
      type = types.path;
      default = "${cfg.package}/etc/udpt.conf";
    };

    user = mkOption {
      description = ''
        user which will run udpt. if kept default a new user will be created
      '';
      type = types.str;
      default = "udpt";
    };

  };

  imp = {
    systemd.services.udpt = {
      description = "udpt server";
      after = [ "network.target" ];
      wantedBy = [ "multi-user.target" ];
      restartIfChanged = true;
      serviceConfig = {
        Type = "simple";
        ExecStart = "${cfg.package}/bin/udpt -c ${shell.escape cfg.cfgfile}";
        PrivateTmp = true;
        User = "${cfg.user}";
      };
    };
    users = lib.mkIf (cfg.user == "udpt") {
      users.udpt = {
        uid = genid "udpt";
      };
      groups.udpt.gid = genid "udpt";
    };
  };
in
out