stockholm/krebs/3modules/iana-etc.nix

45 lines
1.3 KiB
Nix
Raw Normal View History

2023-07-04 14:10:23 +00:00
{ config, lib, pkgs, ... }: let
slib = import ../../lib/pure.nix { inherit lib; };
in with lib; {
2017-09-21 18:59:38 +00:00
options.krebs.iana-etc.services = mkOption {
default = {};
type = types.attrsOf (types.submodule ({ config, ... }: {
options = {
port = mkOption {
default = config._module.args.name;
2023-07-04 14:10:23 +00:00
type = types.addCheck types.str (slib.test "[1-9][0-9]*");
2017-09-21 18:59:38 +00:00
};
} // 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" {} /* sh */ ''
{
${concatMapStringsSep "\n" (entry: /* sh */ ''
${concatMapStringsSep "\n"
(proto: let
line = "${entry.${proto}.name} ${entry.port}/${proto}";
in /* sh */ ''
2023-07-04 14:10:23 +00:00
echo ${slib.shell.escape line}
'')
(filter (proto: entry.${proto} != null) ["tcp" "udp"])}
'') (attrValues config.krebs.iana-etc.services)}
2022-05-31 17:32:22 +00:00
cat ${pkgs.iana-etc}/etc/services
} |
sort -b -k 2,2 -u > $out
2017-09-21 18:59:38 +00:00
'');
};
}