Skip to content

Instantly share code, notes, and snippets.

@betaboon
Last active October 18, 2018 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save betaboon/1d97b72fae8a97cf1270347d8e50074d to your computer and use it in GitHub Desktop.
Save betaboon/1d97b72fae8a97cf1270347d8e50074d to your computer and use it in GitHub Desktop.
{ config, pkgs, ...}: {
imports = [ ./mymodule.nix ];
mymodule.services.service1.enable = true;
mymodule.services.service2.enable = true;
networking.firewall.allowedTCPPorts = [
config.mymodule.services.service1.port
config.mymodule.services.service2.port
];
}
{ config, pkgs, lib, ... }: with lib; {
options.mymodule.services = mkOption {
default = {};
type = with types; attrsOf ( submodule {
port = mkOption {
type = with types; nullOr int;
default = null;
};
});
apply = services: let
notNullOrDefault = value: default: if value != null then value else default;
ensureAssignedPort = service: defaultPort: service // { port = notNullOrDefault service.port defaultPort; };
in listToAttrs(imap0(n: name:
nameValuePair name (ensureAssignedPort services.${name} (5000 + n)))
(attrNames services)
);
};
config = mkIf (services != {}) {
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment