Last active
August 29, 2015 14:16
-
-
Save matejc/3d523d0f138116a51753 to your computer and use it in GitHub Desktop.
This file contains hidden or 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, ... }: | |
with lib; | |
let | |
cfg = config.services.wal; | |
servers = { | |
nginx = import ./nginx.nix; | |
}; | |
walOpts = { config, options, name, ... }: { | |
options = { | |
enable = mkOption { | |
type = types.bool; | |
default = true; | |
description = '' | |
Whether this config should be activated. | |
''; | |
}; | |
name = mkOption { | |
type = types.str; | |
description = '' | |
Name (defaults to attr name). | |
''; | |
}; | |
config = mkOption { | |
type = types.attrs; | |
description = '' | |
Config. | |
''; | |
}; | |
server = mkOption { | |
type = types.enum [ "nginx" ]; | |
description = '' | |
Web server type. | |
''; | |
}; | |
enableSSL = mkOption { | |
type = types.bool; | |
default = false; | |
description = '' | |
Whether to enable SSL for this Nginx server block. | |
''; | |
}; | |
sslCertificate = mkOption { | |
type = types.path; | |
default = null; | |
description = '' | |
Whether to set SSL certificate for this Nginx server block. | |
''; | |
}; | |
sslCertificateKey = mkOption { | |
type = types.path; | |
default = null; | |
description = '' | |
Whether to set SSL key for this Nginx server block. | |
''; | |
}; | |
listenAddress = mkOption { | |
type = types.str; | |
default = "localhost:80"; | |
description = '' | |
Listen address. | |
''; | |
}; | |
listenPort = mkOption { | |
type = types.str; | |
default = "localhost:80"; | |
description = '' | |
Listen port. | |
''; | |
}; | |
root = mkOption { | |
type = types.str; | |
example = "/var/lib/www"; | |
description = '' | |
Root directory. | |
''; | |
}; | |
serverName = mkOption { | |
type = types.str; | |
default = "localhost"; | |
description = '' | |
Domain name for the app. | |
''; | |
}; | |
extraConfig = mkOption { | |
type = types.str; | |
default = ""; | |
description = '' | |
Extra configuration. | |
''; | |
}; | |
preStart = mkOption { | |
type = types.str; | |
default = ""; | |
description = '' | |
Pre start script. | |
''; | |
}; | |
after = mkOption { | |
type = types.listOf types.str; | |
default = []; | |
description = '' | |
Run preStart after this services. | |
''; | |
}; | |
}; | |
config = { | |
name = mkDefault name; | |
}; | |
}; | |
mkWalConfig = server: options: | |
((servers.${server}) { inherit lib pkgs options; }).config; | |
mapWalConfigs = set: | |
(map (attr: mkWalConfig "nginx" set.${attr}) (attrNames set)); | |
in { | |
options = { | |
services.wal = mkOption { | |
description = "The web abstraction layer."; | |
default = { }; | |
type = types.attrsOf (types.submodule walOpts); | |
}; | |
}; | |
# this works | |
config = mkIf (cfg != {}) (mkMerge [ | |
(mkWalConfig "nginx" cfg.owncloud7) | |
]); | |
# this does not | |
/*config = mkIf (cfg != {}) (mkMerge (mapWalConfigs cfg));*/ | |
} |
This file contains hidden or 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
/* | |
I am working on a web server abstraction layer, | |
and since I have nix file for each server - like.. plugins. | |
Inside nginx.nix file I enable services.nginx ... | |
the default.nix basicaly looks like this (this is an example, | |
please bear with me): | |
after adding | |
./services/mysuperservice.nix to module-list.nix | |
and this to configuration.nix | |
services = { | |
mysuperservice.foo = { services.ntp.enable = true; }; | |
}; | |
*/ | |
{ config, lib, pkgs, ... }: | |
with lib; | |
let | |
cfg = config.services.mysuperservice; | |
mysuperserviceOpts = { config, options, name, ... }: { | |
options = { | |
configuration = mkOption { | |
type = types.attrs; | |
description = '' | |
Activate this nixos configuration. | |
''; | |
}; | |
}; | |
}; | |
in { | |
options = { | |
services.mysuperservice = mkOption { | |
description = "The mysuperservice."; | |
default = { }; | |
type = types.attrsOf (types.submodule mysuperserviceOpts); | |
}; | |
}; | |
config = mkIf (cfg != {}) ( | |
mkMerge | |
[ | |
{ services.nginx.enable = true; } | |
] ++ (map (name: cfg.${name}.configuration) (attrNames cfg)) | |
); | |
} | |
/* | |
there is an error when I run this code... | |
and accessing `cfg.mysuperservice.foo` inside a mkMerge .. does not fail | |
it seems that I can not map through services.mysuperservice entries without infinite recursion | |
$ sudo nixos-rebuild switch --fast | |
building the system configuration... | |
error: while evaluating the attribute ‘config.system.build.toplevel’ at "/home/matej/workarea/nixpkgs/nixos/lib/eval-config.nix":26:5: | |
while evaluating the attribute ‘config’ at "/home/matej/workarea/nixpkgs/lib/modules.nix":38:25: | |
while evaluating ‘yieldConfig’ at "/home/matej/workarea/nixpkgs/lib/modules.nix":25:29, called from "/home/matej/workarea/nixpkgs/lib/modules.nix":24:16: | |
while evaluating the attribute ‘environment.checkConfigurationOptions.value’ at "/home/matej/workarea/nixpkgs/lib/modules.nix":206:9: | |
while evaluating the option `environment.checkConfigurationOptions': | |
while evaluating ‘id’ at "/home/matej/workarea/nixpkgs/lib/trivial.nix":9:8, called from "/home/matej/workarea/nixpkgs/lib/modules.nix":204:15: | |
while evaluating ‘fold’ at "/home/matej/workarea/nixpkgs/lib/lists.nix":20:19, called from "/home/matej/workarea/nixpkgs/lib/modules.nix":187:12: | |
while evaluating ‘fold'’ at "/home/matej/workarea/nixpkgs/lib/lists.nix":23:15, called from "/home/matej/workarea/nixpkgs/lib/lists.nix":27:8: | |
while evaluating ‘filterOverrides’ at "/home/matej/workarea/nixpkgs/lib/modules.nix":277:21, called from "/home/matej/workarea/nixpkgs/lib/modules.nix":182:20: | |
while evaluating ‘concatMap’ at "/home/matej/workarea/nixpkgs/lib/lists.nix":54:18, called from "/home/matej/workarea/nixpkgs/lib/modules.nix":284:8: | |
while evaluating ‘concatMap’ at "/home/matej/workarea/nixpkgs/lib/lists.nix":54:18, called from "/home/matej/workarea/nixpkgs/lib/modules.nix":110:20: | |
while evaluating ‘concatMap’ at "/home/matej/workarea/nixpkgs/lib/lists.nix":54:18, called from "/home/matej/workarea/nixpkgs/lib/modules.nix":86:8: | |
while evaluating anonymous function at "/home/matej/workarea/nixpkgs/lib/modules.nix":86:19, called from undefined position: | |
while evaluating ‘pushDownProperties’ at "/home/matej/workarea/nixpkgs/lib/modules.nix":227:24, called from "/home/matej/workarea/nixpkgs/lib/modules.nix":86:75: | |
while evaluating ‘pushDownProperties’ at "/home/matej/workarea/nixpkgs/lib/modules.nix":227:24, called from "/home/matej/workarea/nixpkgs/lib/modules.nix":231:52: | |
while evaluating the attribute ‘content’ at "/home/matej/workarea/nixpkgs/lib/modules.nix":324:14: | |
while evaluating ‘yieldConfig’ at "/home/matej/workarea/nixpkgs/lib/modules.nix":25:29, called from "/home/matej/workarea/nixpkgs/lib/modules.nix":24:16: | |
while evaluating the attribute ‘environment.checkConfigurationOptions.value’ at "/home/matej/workarea/nixpkgs/lib/modules.nix":206:9: | |
infinite recursion encountered | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment