-
-
Save betaboon/1d97b72fae8a97cf1270347d8e50074d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ 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 | |
]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ 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