diff options
Diffstat (limited to 'doctrine/lib')
| -rw-r--r-- | doctrine/lib/default.nix | 10 | ||||
| -rw-r--r-- | doctrine/lib/importAll.nix | 20 | ||||
| -rw-r--r-- | doctrine/lib/mk-module.nix | 38 |
3 files changed, 68 insertions, 0 deletions
diff --git a/doctrine/lib/default.nix b/doctrine/lib/default.nix new file mode 100644 index 0000000..1b03fe1 --- /dev/null +++ b/doctrine/lib/default.nix @@ -0,0 +1,10 @@ +{ + lib, + doctrine, + pkgs, +}: let + close = f: args: f (args // {inherit lib pkgs doctrine;}); +in { + importAll = pkgs.callPackage ./importAll.nix {}; + mkModule = close (import ./mk-module.nix); +} diff --git a/doctrine/lib/importAll.nix b/doctrine/lib/importAll.nix new file mode 100644 index 0000000..6acabe9 --- /dev/null +++ b/doctrine/lib/importAll.nix @@ -0,0 +1,20 @@ +{lib}: { + root, + exclude ? [], +}: +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 name (map basename exclude); + + entry = name: _: { + name = basename name; + value = import (root + "/${name}"); + }; + in + mapAttrs' entry (filterAttrs isMatch (readDir root)) diff --git a/doctrine/lib/mk-module.nix b/doctrine/lib/mk-module.nix new file mode 100644 index 0000000..79c24c5 --- /dev/null +++ b/doctrine/lib/mk-module.nix @@ -0,0 +1,38 @@ +{ + name, + hm ? null, + sys ? null, + options ? null, + lib, + config, + pkgs, + doctrine, +}: let + optionsSet = import options { + inherit config lib pkgs cfg name doctrine; + }; + + configSet = import configFiles.${doctrine.namespace} { + inherit config lib pkgs doctrine cfg; + }; + + configFiles = lib.filterAttrs (k: v: v != null) { + inherit sys hm; + }; + + cfg = config.${doctrine.prefix}.${name}; +in { + config = + lib.optionalAttrs (configFiles ? ${doctrine.namespace}) + (lib.mkIf cfg.enable configSet); + + options = lib.optionalAttrs (options + != null + && optionsSet ? ${doctrine.namespace}) { + ${doctrine.prefix}.${name} = + optionsSet.${doctrine.namespace} + // { + enable = lib.mkEnableOption name; + }; + }; +} |
