-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add lib to flake outputs exposing multiService func
closes #25
- Loading branch information
1 parent
2c1bbc1
commit 14904d0
Showing
3 changed files
with
36 additions
and
33 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
# Create an attrsOf module wrapper (`services.${name}`) around the given submodule. | ||
# | ||
# where module filename is of form `${name}.nix`. The submodule takes this | ||
# 'name' parameter, and is expected to set the final process-compose config in | ||
# its `outputs.settings` option. | ||
multiService = mod: | ||
{ config, pkgs, lib, ... }: let | ||
# Derive name from filename | ||
name = lib.pipe mod [ | ||
builtins.baseNameOf | ||
(lib.strings.splitString ".") | ||
builtins.head | ||
]; | ||
in { | ||
options.services.${name} = lib.mkOption { | ||
description = '' | ||
${name} service | ||
''; | ||
default = { }; | ||
type = lib.types.attrsOf (lib.types.submoduleWith { | ||
specialArgs = { inherit pkgs; }; | ||
modules = [ mod ]; | ||
}); | ||
}; | ||
config.settings.imports = | ||
lib.pipe config.services.${name} [ | ||
(lib.filterAttrs (_: cfg: cfg.enable)) | ||
(lib.mapAttrsToList (_: cfg: cfg.outputs.settings)) | ||
]; | ||
}; | ||
} |