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; | |
}; | |
} |
Author
ctheune
commented
Feb 1, 2016
Here's the repl for when I do not set any roles:
[root@default:~/nixos]# nix-repl -I nixpkgs=/root/nixos/ '<nixpkgs/nixos>'
Welcome to Nix version 1.10. Type :? for help.
Loading ‘<nixpkgs/nixos>’...
Added 6 variables.
nix-repl> config.flyingcircus.roles.nginx
{ enable = false; }
nix-repl> config.flyingcircus.roles.haproxy
{ enable = false; }
nix-repl> config.fcio.roles
[ ]
nix-repl> config.flyingcircus.roles
{ dovecot = { ... }; haproxy = { ... }; mysql = { ... }; nginx = { ... }; postgresql = { ... }; varnish = { ... }; }
And here is the error when I actually set a role
[root@default:~/nixos]# nix-repl -I nixpkgs=/root/nixos/ '<nixpkgs/nixos>'
Welcome to Nix version 1.10. Type :? for help.
Loading ‘<nixpkgs/nixos>’...
Added 6 variables.
nix-repl> config.fcio.roles
[ "haproxy" ]
nix-repl> config.flyingcircus.roles.haproxy
error: The option `flyingcircus.roles.haproxy.enable' defined in `/nix/store/93sw5by95rf377s92kl06rs3harkak1f-modules/flyingcircus/role.nix' does not exist.
nix-repl>
And here the traceback when making sure we don't stumble over names containing ".":
error: while evaluating the attribute ‘config.system.build.toplevel’ at /root/nixos/nixos/modules/system/activation/top-level.nix:241:5:
while evaluating ‘fold’ at /root/nixos/lib/lists.nix:20:19, called from /root/nixos/nixos/modules/system/activation/top-level.nix:125:12:
while evaluating ‘fold'’ at /root/nixos/lib/lists.nix:23:15, called from /root/nixos/lib/lists.nix:27:8:
while evaluating ‘showWarnings’ at /root/nixos/nixos/modules/system/activation/top-level.nix:93:18, called from /root/nixos/nixos/modules/system/activation/top-level.nix:100:16:
while evaluating ‘fold’ at /root/nixos/lib/lists.nix:20:19, called from /root/nixos/nixos/modules/system/activation/top-level.nix:93:23:
while evaluating ‘fold'’ at /root/nixos/lib/lists.nix:23:15, called from /root/nixos/lib/lists.nix:27:8:
while evaluating the attribute ‘warnings’ at /root/nixos/lib/attrsets.nix:145:44:
while evaluating anonymous function at /root/nixos/lib/modules.nix:74:45, called from /root/nixos/lib/attrsets.nix:145:52:
while evaluating the attribute ‘value’ at /root/nixos/lib/modules.nix:287:9:
while evaluating the option `warnings':
while evaluating the attribute ‘isDefined’ at /root/nixos/lib/modules.nix:319:5:
while evaluating ‘filterOverrides’ at /root/nixos/lib/modules.nix:391:21, called from /root/nixos/lib/modules.nix:303:18:
while evaluating ‘concatMap’ at /root/nixos/lib/lists.nix:62:18, called from /root/nixos/lib/modules.nix:397:8:
while evaluating ‘concatMap’ at /root/nixos/lib/lists.nix:62:18, called from /root/nixos/lib/modules.nix:298:17:
while evaluating anonymous function at /root/nixos/lib/modules.nix:298:28, called from undefined position:
while evaluating ‘dischargeProperties’ at /root/nixos/lib/modules.nix:361:25, called from /root/nixos/lib/modules.nix:299:62:
while evaluating the attribute ‘value’ at /root/nixos/lib/modules.nix:199:48:
while evaluating the attribute ‘config.warnings’ at /root/nixos/nixos/modules/system/boot/systemd.nix:600:5:
while evaluating ‘mapAttrsToList’ at /root/nixos/lib/attrsets.nix:169:23, called from /root/nixos/nixos/modules/system/boot/systemd.nix:600:29:
while evaluating the attribute ‘services’ at /root/nixos/lib/attrsets.nix:145:44:
while evaluating anonymous function at /root/nixos/lib/modules.nix:74:45, called from /root/nixos/lib/attrsets.nix:145:52:
while evaluating the attribute ‘value’ at /root/nixos/lib/modules.nix:287:9:
while evaluating the option `systemd.services':
while evaluating the attribute ‘isDefined’ at /root/nixos/lib/modules.nix:319:5:
while evaluating ‘filterOverrides’ at /root/nixos/lib/modules.nix:391:21, called from /root/nixos/lib/modules.nix:303:18:
while evaluating ‘concatMap’ at /root/nixos/lib/lists.nix:62:18, called from /root/nixos/lib/modules.nix:397:8:
while evaluating ‘concatMap’ at /root/nixos/lib/lists.nix:62:18, called from /root/nixos/lib/modules.nix:298:17:
while evaluating anonymous function at /root/nixos/lib/modules.nix:298:28, called from undefined position:
while evaluating ‘dischargeProperties’ at /root/nixos/lib/modules.nix:361:25, called from /root/nixos/lib/modules.nix:299:62:
while evaluating the attribute ‘value’ at /root/nixos/lib/modules.nix:199:48:
while evaluating the attribute ‘config.services’ at /root/nixos/nixos/modules/system/upstart/upstart.nix:284:5:
while evaluating ‘flip’ at /root/nixos/lib/trivial.nix:57:16, called from /root/nixos/nixos/modules/system/upstart/upstart.nix:285:7:
while evaluating ‘mapAttrs'’ at /root/nixos/lib/attrsets.nix:157:18, called from /root/nixos/lib/trivial.nix:57:19:
while evaluating the attribute ‘jobs’ at /root/nixos/lib/attrsets.nix:145:44:
while evaluating anonymous function at /root/nixos/lib/modules.nix:74:45, called from /root/nixos/lib/attrsets.nix:145:52:
while evaluating the attribute ‘value’ at /root/nixos/lib/modules.nix:287:9:
while evaluating the option `jobs':
while evaluating the attribute ‘isDefined’ at /root/nixos/lib/modules.nix:319:5:
while evaluating ‘filterOverrides’ at /root/nixos/lib/modules.nix:391:21, called from /root/nixos/lib/modules.nix:303:18:
while evaluating ‘concatMap’ at /root/nixos/lib/lists.nix:62:18, called from /root/nixos/lib/modules.nix:397:8:
while evaluating ‘concatMap’ at /root/nixos/lib/lists.nix:62:18, called from /root/nixos/lib/modules.nix:298:17:
while evaluating anonymous function at /root/nixos/lib/modules.nix:298:28, called from undefined position:
while evaluating ‘dischargeProperties’ at /root/nixos/lib/modules.nix:361:25, called from /root/nixos/lib/modules.nix:299:62:
while evaluating the attribute ‘condition’ at /root/nixos/lib/modules.nix:437:14:
while evaluating the attribute ‘condition’ at /root/nixos/lib/modules.nix:437:14:
while evaluating the attribute ‘flyingcircus.roles.haproxy.enable’ at /root/nixos/lib/attrsets.nix:145:44:
while evaluating anonymous function at /root/nixos/lib/modules.nix:74:45, called from /root/nixos/lib/attrsets.nix:145:52:
while evaluating ‘yieldConfig’ at /root/nixos/lib/modules.nix:73:29, called from /root/nixos/lib/modules.nix:76:16:
while evaluating anonymous function at /root/nixos/lib/modules.nix:79:24, called from /root/nixos/lib/modules.nix:79:11:
while evaluating the attribute ‘names’ at /root/nixos/lib/modules.nix:214:54:
value is a list while a set was expected, at /root/nixos/lib/modules.nix:214:62
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment