Skip to content

Instantly share code, notes, and snippets.

@yorickvP
Created October 30, 2018 17:34
Show Gist options
  • Select an option

  • Save yorickvP/99f9e16c673a17ec9135065ffba4675d to your computer and use it in GitHub Desktop.

Select an option

Save yorickvP/99f9e16c673a17ec9135065ffba4675d to your computer and use it in GitHub Desktop.
{ config, lib, pkgs, ... }@mod:
let
inherit (lib) types mkOption;
module = with types; { name, config, ... }: { options = {
path = mkOption { default = ../profiles/cd + "/${config.src}.nix"; type = path;};
port = mkOption { type = int; };
};};
modules = with lib; (lib.mapAttrsToList (name: cfg: (let file = toString cfg.path; key = file; in
unifyModuleSyntax file key (applyIfFunction key (import cfg.path cfg) mod))) config.cd);
in
{
options.cd = lib.mkOption {
type = types.attrsOf (types.submodule module);
default = {};
};
config.services = lib.mkMerge (lib.concatMap (x: (builtins.map (y: y.services or {}) (lib.pushDownProperties x.config))) modules);
config.systemd = lib.mkMerge (lib.concatMap (x: (builtins.map (y: y.systemd or {}) (lib.pushDownProperties x.config))) modules);
config.cd.test = { port = 9001; };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment