mirror of
https://github.com/juspay/services-flake.git
synced 2024-09-11 12:26:04 +03:00
35 lines
1012 B
Nix
35 lines
1012 B
Nix
{
|
|
# 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))
|
|
];
|
|
};
|
|
}
|