Home

cfg-playground @613f5bf8a366f976d4dfc8637b9b048df14403e2 - refs - log -
-
https://git.jolheiser.com/cfg-playground.git
cfg playground
cfg-playground / nix / module.nix
- raw
 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
{
  pkgs,
  lib,
  config,
  ...
}:
let
  cfg = config.services.cfg-playground;
  pkg = pkgs.callPackage ./pkg.nix { inherit pkgs; };
in
{
  options =
    let
      inherit (lib) mkEnableOption mkOption types;
    in
    {
      services.cfg-playground = {
        enable = mkEnableOption "Enable cfg-playground";

        package = mkOption {
          type = types.package;
          description = "cfg-playground package to use";
          default = pkg;
        };

        hostname = mkOption {
          type = types.str;
          description = "tailnet hostname";
          default = "cfg";

        };
        data-dir = mkOption {
          type = types.str;
          description = "tsnet data directory";
          default = ".tsnet";

        };
        auth-key = mkOption {
          type = types.str;
          description = "tsnet auth key";
        };
        verbose = mkOption {
          type = types.bool;
          default = false;
          description = "Log verbosely";
        };

        user = mkOption {
          type = types.str;
          default = "cfg-playground";
          description = "User account under which cfg-playground runs";
        };

        group = mkOption {
          type = types.str;
          default = "cfg-playground";
          description = "Group account under which cfg-playground runs";
        };
      };
    };
  config = lib.mkIf cfg.enable {
    users.users."${cfg.user}" = {
      home = "/var/lib/cfg-playground";
      createHome = true;
      group = "${cfg.group}";
      isSystemUser = true;
      isNormalUser = false;
      description = "user for cfg-playground service";
    };
    users.groups."${cfg.group}" = { };

    systemd.services = {
      cfg-playground = {
        enable = true;
        script =
          let
            args = [
              "--hostname=${cfg.hostname}"
              "--data-dir=${cfg.data-dir}"
              "--auth-key=${cfg.auth-key}"
              (lib.optionalString cfg.verbose "--verbose")
            ];
          in
          "${cfg.package}/bin/cfg-playground ${builtins.concatStringsSep " " args}";
        wantedBy = [ "multi-user.target" ];
        after = [ "network.target" ];
        path = [ cfg.package ];
        serviceConfig = {
          User = cfg.user;
          Group = cfg.group;
          Restart = "always";
          RestartSec = "15";
          WorkingDirectory = "/var/lib/cfg-playground";
        };
      };
    };
  };
}