-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule.nix
45 lines (40 loc) · 1.15 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, lib, pkgs, ... }:
with lib;
let
cfg = config.services.pingshutdown;
in
{
options.services.pingshutdown = with types; {
enable = mkEnableOption (mdDoc "Shut down host when remote connectivity not available");
package = mkPackageOption pkgs "pingshutdown" { };
environmentFile = mkOption {
type = nullOr path;
default = null;
example = "/run/secrets/pingshutdown";
};
settings = mkOption {
type = types.submodule (settings: {
freeformType = attrsOf str;
});
default = { };
};
};
config = mkIf cfg.enable {
systemd.services.pingshutdown = {
description = "pingshutdown";
after = [ "network.target" "network-online.target" ];
wants = [ "network-online.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart = "${getExe cfg.package}";
RuntimeDirectory = "pingshutdown";
RuntimeDirectoryMode = "0700";
Restart = "always";
EnvironmentFile = [
cfg.environmentFile
(pkgs.writeText "pingshutdown-settings" (generators.toKeyValue { } cfg.settings))
];
};
};
};
}