-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmodule.nix
45 lines (42 loc) · 1.24 KB
/
module.nix
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
{ config, pkgs, lib, ... }:
with lib;
let
cfg = config.services.einat;
configFormat = pkgs.formats.toml { };
configFile =
if cfg.configFile != null
then cfg.configFile
else configFormat.generate "config.toml" cfg.config;
in
{
options.services.einat = {
enable = mkEnableOption "einat service";
package = mkPackageOption pkgs "einat" { default = [ "einat" ]; };
configFile = mkOption {
type = types.nullOr types.path;
default = null;
description = "The absolute path to the configuration file.";
};
config = mkOption {
type = configFormat.type;
default = { };
description = "The configuration attribute set.";
};
};
config = mkIf cfg.enable {
assertions = [{
assertion = (cfg.configFile != null) -> (cfg.config == { });
message = "Either but not both `configFile` and `config` should be specified for einat.";
}];
systemd.services.einat = {
description = "einat service";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
restartTriggers = [ configFile ];
serviceConfig = {
ExecStart = "${cfg.package}/bin/einat -c ${configFile}";
};
};
environment.systemPackages = [ cfg.package ];
};
}