Last active
February 1, 2016 15:54
-
-
Save ctheune/93f6bdc61b49c5b3af12 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, lib, pkgs, ... }: | |
let | |
fcio = config.fcio; | |
optionalAttr = set: name: default: | |
if builtins.hasAttr name set then set.${name} else default; | |
enc_roles = optionalAttr fcio.enc "classes" []; | |
in | |
{ | |
options = { | |
fcio.roles = lib.mkOption { | |
default = enc_roles; | |
type = lib.types.listOf lib.types.str; | |
description = '' | |
Which roles to activate. E.g: | |
fcio.roles = [ "generic" "webgateway" "webproxy" ]; | |
Defaults to the roles provided by the ENC. ENC-provided roles | |
will have been stripped the 'role::' prefix automatically. | |
''; | |
}; | |
}; | |
config = | |
# Map list of roles to a list of attribute sets enabling each role. | |
let | |
# Optionally remove the old "role::" prefix from Puppet/ENC | |
stripped_roles = map (lib.removePrefix "role::") fcio.roles; | |
# Turn the list of role names (["a", "b"]) into an attribute set | |
# ala { <role> = { enable = true;}; } | |
role_set = lib.listToAttrs ( | |
map (role: { name = role; value = { enable = true; }; }) | |
stripped_roles); | |
in | |
{ | |
flyingcircus.roles = role_set; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And here the traceback when making sure we don't stumble over names containing ".":