-
Notifications
You must be signed in to change notification settings - Fork 7
/
module.nix
76 lines (71 loc) · 2.44 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
flake: { config, pkgs, lib, ... }:
with lib;
let
inherit (flake.packages.${pkgs.stdenv.hostPlatform.system}) kartograf;
cfg = config.services.kartograf;
postScript = pkgs.writeScriptBin "post-script" /* bash */ ''
#!/${pkgs.bash}/bin/bash
timestamp=$(${pkgs.findutils}/bin/find out -mindepth 1 -maxdepth 1 -type d | ${pkgs.coreutils}/bin/cut -d/ -f2)
mv out/$timestamp/final_result.txt ${cfg.resultPath}/asmap-$timestamp.txt
echo "Copied result from /out/$timestamp/final_result.txt to ${cfg.resultPath}/asmap-$timestamp.txt"
rm -rf data out
echo "Cleaned up temporary directories."
'';
in
{
options.services.kartograf = {
enable = mkEnableOption "kartograf";
clean = mkEnableOption "cleaning up of temporary artifacts after processing." // { default = true; };
useIRR = mkEnableOption "using Internet Routing Registry (IRR) data" // { default = true; };
useRV = mkEnableOption "using RouteViews (RV) data" // { default = true; };
schedule = mkOption {
type = types.str;
default = "*-*-01 00:00:00 UTC";
example = "monthly";
description = mdDoc "Systemd OnCalendar setting for kartograf.";
};
resultPath = mkOption {
type = types.path;
default = "/home/kartograf/";
example = "/scratch/results/kartograf/";
description = mdDoc "Directory for results.";
};
};
config = mkIf cfg.enable {
users = {
users.kartograf = {
isSystemUser = true;
group = "kartograf";
home = "/home/kartograf";
createHome = true;
homeMode = "755";
};
groups.kartograf = { };
};
systemd.timers.kartograf = {
wantedBy = [ "timers.target" ];
timerConfig = {
OnCalendar = cfg.schedule;
Unit = [ "kartograf.service" ];
};
};
systemd.services.kartograf = {
description = "kartograf";
after = [ "network-online.target" ];
serviceConfig = {
Environment = "PYTHONUNBUFFERED=1";
ExecStopPost = "${postScript}/bin/post-script";
ExecStart = ''${kartograf}/bin/kartograf map \
${optionalString cfg.clean "--cleanup" } \
${optionalString cfg.useIRR "--irr" } \
${optionalString cfg.useRV "--routeviews" } \
'';
MemoryDenyWriteExecute = true;
WorkingDirectory = cfg.resultPath;
ReadWriteDirectories = cfg.resultPath;
User = "kartograf";
Group = "kartograf";
};
};
};
}