iana-etc module: allow adding new services

This fixes a bug which only allowed modifying existing services.
This commit is contained in:
tv 2019-12-02 01:11:37 +01:00
parent 7920ebebf0
commit 53fd88bcef

View File

@ -23,32 +23,20 @@ with import <stockholm/lib>;
}; };
config.environment.etc = mkIf (config.krebs.iana-etc.services != {}) { config.environment.etc = mkIf (config.krebs.iana-etc.services != {}) {
services.source = mkForce (pkgs.runCommand "krebs-iana-etc" {} '' services.source = mkForce (pkgs.runCommand "krebs-iana-etc" {} /* sh */ ''
exec < ${pkgs.iana_etc}/etc/services {
exec > $out ${concatMapStringsSep "\n" (entry: /* sh */ ''
awk -F '[ /]+' ' ${concatMapStringsSep "\n"
BEGIN { (proto: let
port=0 line = "${entry.${proto}.name} ${entry.port}/${proto}";
} in /* sh */ ''
${concatMapStringsSep "\n" (entry: '' echo ${shell.escape line}
$2 == ${entry.port} { '')
port=$2 (filter (proto: entry.${proto} != null) ["tcp" "udp"])}
next '') (attrValues config.krebs.iana-etc.services)}
} cat ${pkgs.iana_etc}/etc/services
port == ${entry.port} { } |
${concatMapStringsSep "\n" sort -b -k 2,2 -u > $out
(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
}
'
''); '');
}; };