summaryrefslogtreecommitdiffstats
path: root/krebs/3modules/iana-etc.nix
diff options
context:
space:
mode:
authorlassulus <lassulus@lassul.us>2017-10-01 17:54:06 +0200
committerlassulus <lassulus@lassul.us>2017-10-01 17:54:06 +0200
commitd7f65ea679866f24e4ca52b51bd6f068a6b38195 (patch)
tree6a09e7cc2a4c9af0507bdc189652c78832a2f952 /krebs/3modules/iana-etc.nix
parentd973c779eb71749af464edb1ed0216b0d5317eb2 (diff)
parente62f376e6177f3efb0e0bcd3aad97a991c3b6d60 (diff)
Merge branch 'master' into staging/17.09
Diffstat (limited to 'krebs/3modules/iana-etc.nix')
-rw-r--r--krebs/3modules/iana-etc.nix55
1 files changed, 55 insertions, 0 deletions
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
+ }
+ '
+ '');
+ };
+
+}