-
Notifications
You must be signed in to change notification settings - Fork 1
/
module.nix
52 lines (49 loc) · 1.4 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
46
47
48
49
50
51
52
# https://discourse.nixos.org/t/creating-a-nix-flake-to-package-an-application-and-systemd-service-as-a-nixos-module/18492/2
flake: {
config,
lib,
pkgs,
...
}: let
inherit (builtins) toJSON removeAttrs;
inherit (lib) filterAttrs types mkEnableOption mkOption mkRenamedOptionModule;
inherit (lib.trivial) pipe;
inherit (flake.packages.${pkgs.stdenv.hostPlatform.system}) zapret;
cfg = config.services.zapret;
in {
options.services.zapret = {
enable = mkEnableOption ''zapret daemon'';
config = mkOption {
type = types.str;
# default = '''';
description = ''zapret config'';
};
};
config = lib.mkIf cfg.enable {
systemd.services.zapret = {
description = "zapret daemon";
path = with pkgs; [nftables curl iptables];
after = ["network-online.target"];
wants = ["network-online.target"];
wantedBy = ["multi-user.target"];
serviceConfig = {
Type = "forking";
Restart = "no";
KillMode = "none";
GuessMainPID = "no";
RemainAfterExit = "no";
IgnoreSIGPIPE = "no";
TimeoutSec = "30sec";
EnvironmentFile = builtins.toFile "zapret-config" cfg.config;
ExecStart = ''
${zapret.out}/src/init.d/sysv/zapret start
'';
ExecStop = ''
${zapret.out}/src/init.d/sysv/zapret stop
'';
# preStart = ''
# '';
};
};
};
}