Skip to content

Commit

Permalink
evalService: more versatile customConfig support.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbgi committed May 4, 2021
1 parent 924ec2d commit ead0043
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions lib/default.nix
Expand Up @@ -15,14 +15,26 @@ lib: with lib; rec {
) (attrNames p));

evalService = { pkgs, serviceName, modules, customConfig }:
let customConfig' = if (isAttrs customConfig) && !(customConfig ? service) then {
services.${serviceName} = customConfig;
} else customConfig;
let mkConfig = c: if (isAttrs c)
then (
if c ? nixosModules.${serviceName}
then c.nixosModules.${serviceName}
else if c ? nixosModule
then mkConfig c.nixosModule
else if c ? services then {
services.${serviceName} = c.services.${serviceName} or {};
} else {options, ...}: {
services.${serviceName} =
let validOptions = attrNames options.services.${serviceName};
in filterAttrs (n: _: elem n validOptions) c;
})
else c;

in (lib.modules.evalModules {
prefix = [];
modules = modules ++ [
{ services.${serviceName}.enable = true; }
customConfig'
(mkConfig customConfig)
systemdCompatModule
];
args = { inherit pkgs; };
Expand Down

0 comments on commit ead0043

Please sign in to comment.