diff options
| author | Alejandro Soto <alejandro@34project.org> | 2025-08-24 15:48:29 -0600 |
|---|---|---|
| committer | Alejandro Soto <alejandro@34project.org> | 2025-08-24 15:48:29 -0600 |
| commit | ecab16d635554150627403675642d5603ef64cc6 (patch) | |
| tree | f94619061973fc0a5fd6097e27e80a5dde627fda /trivionomicon/doctrine/lib | |
| parent | 0e11a692f223b268ca0d208b0ebf48c80caddfb6 (diff) | |
| parent | 53a923158861a9c52b86f37d826c3f4637476dfa (diff) | |
Add 'trivionomicon/' from commit 'c651b8c4706cfc750303db12ae19e58164a6bebb'
git-subtree-dir: trivionomicon
git-subtree-mainline: 02d3ab9583983e823909020c34b9d5a6894fb773
git-subtree-split: c651b8c4706cfc750303db12ae19e58164a6bebb
Diffstat (limited to 'trivionomicon/doctrine/lib')
| -rw-r--r-- | trivionomicon/doctrine/lib/default.nix | 20 | ||||
| -rw-r--r-- | trivionomicon/doctrine/lib/import-all.nix | 21 | ||||
| -rw-r--r-- | trivionomicon/doctrine/lib/mk-module.nix | 48 |
3 files changed, 89 insertions, 0 deletions
diff --git a/trivionomicon/doctrine/lib/default.nix b/trivionomicon/doctrine/lib/default.nix new file mode 100644 index 0000000..f189e21 --- /dev/null +++ b/trivionomicon/doctrine/lib/default.nix @@ -0,0 +1,20 @@ +{ + lib, + doctrine, + pkgs, +}: let + close = vars: f: args: + ( + if builtins.isPath f + then import f + else f + ) + (args // vars); + + closeLib = close {inherit lib;}; + closeFull = close {inherit lib pkgs doctrine;}; +in { + inherit close; + importAll = closeLib ./import-all.nix; + mkModule = closeFull ./mk-module.nix; +} diff --git a/trivionomicon/doctrine/lib/import-all.nix b/trivionomicon/doctrine/lib/import-all.nix new file mode 100644 index 0000000..423dd9c --- /dev/null +++ b/trivionomicon/doctrine/lib/import-all.nix @@ -0,0 +1,21 @@ +{ + lib, + root, + exclude ? ["default"], +}: +with builtins; +with lib; +# http://chriswarbo.net/projects/nixos/useful_hacks.html + let + basename = removeSuffix ".nix"; + + isMatch = name: type: + (hasSuffix ".nix" name || type == "directory") + && ! elem (basename name) exclude; + + entry = name: _: { + name = basename name; + value = import (root + "/${name}"); + }; + in + mapAttrs' entry (filterAttrs isMatch (readDir root)) diff --git a/trivionomicon/doctrine/lib/mk-module.nix b/trivionomicon/doctrine/lib/mk-module.nix new file mode 100644 index 0000000..f76ccfe --- /dev/null +++ b/trivionomicon/doctrine/lib/mk-module.nix @@ -0,0 +1,48 @@ +{ + # The first few arguments are implicitly passed by the 'close' helper + lib, + pkgs, + doctrine, + name, + config, + hm ? null, + sys ? null, + options ? null, + requires ? [], + prefix ? doctrine.prefix, + namespace ? doctrine.namespace, +}: let + optionsSet = import options { + inherit config lib pkgs cfg name doctrine; + }; + + configSet = import configFiles.${namespace} { + inherit config lib pkgs doctrine cfg; + }; + + configFiles = lib.filterAttrs (k: v: v != null) { + inherit sys hm; + }; + + cfg = config.${prefix}.${name}; +in { + config = + lib.optionalAttrs (configFiles ? ${namespace}) + (lib.mkIf cfg.enable (lib.mkMerge [ + configSet + { + assertions = + map (dependency: { + assertion = cfg.enable -> config.${prefix}.${dependency}.enable; + message = "${prefix}.${name}.enable requires ${prefix}.${dependency}.enable"; + }) + requires; + } + ])); + + options.${prefix}.${name} = + lib.optionalAttrs (options != null && optionsSet ? ${namespace}) optionsSet.${namespace} + // { + enable = lib.mkEnableOption name; + }; +} |
