summaryrefslogtreecommitdiffstats
path: root/krebs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2017-09-21 20:59:38 +0200
committertv <tv@krebsco.de>2017-09-21 21:01:24 +0200
commitd2c388ce3928764a78e4158162cb64ce3b5e43ce (patch)
tree9f2fe9582afa401f7ebd7454a7ffcfd84717da55 /krebs
parent82f459f7aeb4bc151a998308046431dd194160f8 (diff)
iana-etc module: init
Diffstat (limited to 'krebs')
-rw-r--r--krebs/3modules/default.nix1
-rw-r--r--krebs/3modules/iana-etc.nix55
2 files changed, 56 insertions, 0 deletions
diff --git a/krebs/3modules/default.nix b/krebs/3modules/default.nix
index 42df3f053..48cf7971b 100644
--- a/krebs/3modules/default.nix
+++ b/krebs/3modules/default.nix
@@ -24,6 +24,7 @@ let
./go.nix
./hidden-ssh.nix
./htgen.nix
+ ./iana-etc.nix
./iptables.nix
./kapacitor.nix
./monit.nix
diff --git a/krebs/3modules/iana-etc.nix b/krebs/3modules/iana-etc.nix
new file mode 100644
index 000000000..f6d47f27e
--- /dev/null
+++ b/krebs/3modules/iana-etc.nix
@@ -0,0 +1,55 @@
+with import <stockholm/lib>;
+{ config, pkgs, ... }: {
+
+ options.krebs.iana-etc.services = mkOption {
+ default = {};
+ type = types.attrsOf (types.submodule ({ config, ... }: {
+ options = {
+ port = mkOption {
+ default = config._module.args.name;
+ type = types.addCheck types.str (test "[1-9][0-9]*");
+ };
+ } // genAttrs ["tcp" "udp"] (protocol: mkOption {
+ default = null;
+ type = types.nullOr (types.submodule {
+ options = {
+ name = mkOption {
+ type = types.str;
+ };
+ };
+ });
+ });
+ }));
+ };
+
+ config.environment.etc = mkIf (config.krebs.iana-etc.services != {}) {
+ services.source = mkForce (pkgs.runCommand "krebs-iana-etc" {} ''
+ exec < ${pkgs.iana_etc}/etc/services
+ exec > $out
+ awk -F '[ /]+' '
+ BEGIN {
+ port=0
+ }
+ ${concatMapStringsSep "\n" (entry: ''
+ $2 == ${entry.port} {
+ port=$2
+ next
+ }
+ port == ${entry.port} {
+ ${concatMapStringsSep "\n"
+ (proto: let
+ s = "${entry.${proto}.name} ${entry.port}/${proto}";
+ in
+ "print ${toJSON s}")
+ (filter (proto: entry.${proto} != null) ["tcp" "udp"])}
+ port=0
+ }
+ '') (attrValues config.krebs.iana-etc.services)}
+ {
+ print $0
+ }
+ '
+ '');
+ };
+
+}