summaryrefslogtreecommitdiff
path: root/trivionomicon/doctrine
diff options
context:
space:
mode:
Diffstat (limited to 'trivionomicon/doctrine')
-rw-r--r--trivionomicon/doctrine/default.nix16
-rw-r--r--trivionomicon/doctrine/lib/default.nix23
-rw-r--r--trivionomicon/doctrine/lib/import-all.nix21
-rw-r--r--trivionomicon/doctrine/lib/mk-module.nix68
4 files changed, 128 insertions, 0 deletions
diff --git a/trivionomicon/doctrine/default.nix b/trivionomicon/doctrine/default.nix
new file mode 100644
index 0000000..0d50d49
--- /dev/null
+++ b/trivionomicon/doctrine/default.nix
@@ -0,0 +1,16 @@
+{
+ lib ? pkgs.lib,
+ pkgs,
+ prefix ? "trivium",
+ namespace ? null,
+}: let
+ doctrine =
+ {
+ lib = import ./lib {inherit lib pkgs doctrine;};
+ inherit namespace prefix;
+ }
+ // lib.optionalAttrs (pkgs != null) {
+ inherit pkgs;
+ };
+in
+ doctrine
diff --git a/trivionomicon/doctrine/lib/default.nix b/trivionomicon/doctrine/lib/default.nix
new file mode 100644
index 0000000..e2d84b8
--- /dev/null
+++ b/trivionomicon/doctrine/lib/default.nix
@@ -0,0 +1,23 @@
+{
+ 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;
+ }
+ // lib.optionalAttrs (doctrine.namespace != null) {
+ 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..7a1de39
--- /dev/null
+++ b/trivionomicon/doctrine/lib/mk-module.nix
@@ -0,0 +1,68 @@
+{
+ # 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,
+ passthru ? {},
+}: let
+ patchArgs = args: args // passthru // {inherit cfg name doctrine;};
+
+ optionsSet = args: import options (patchArgs args);
+ configSet = args: import configFiles.${namespace} (patchArgs args);
+
+ configFiles = lib.filterAttrs (k: v: v != null) {
+ inherit sys hm;
+ };
+
+ cfg = config.${prefix}.${name};
+ hasConfig = configFiles ? ${namespace};
+in {
+ imports = [
+ (args @ {
+ config,
+ modulesPath ? null,
+ lib,
+ pkgs,
+ ...
+ }:
+ lib.optionalAttrs hasConfig {
+ config = lib.mkIf cfg.enable (lib.mkMerge [
+ (configSet args)
+ {
+ assertions =
+ map (dependency: {
+ assertion = cfg.enable -> config.${prefix}.${dependency}.enable;
+ message = "${prefix}.${name}.enable requires ${prefix}.${dependency}.enable";
+ })
+ requires;
+ }
+ ]);
+ })
+
+ (args @ {
+ config,
+ modulesPath ? null,
+ lib,
+ pkgs,
+ ...
+ }: let
+ hasOptions = options != null && optionsForArgs ? ${namespace};
+ optionsForArgs = optionsSet args;
+ in
+ lib.optionalAttrs (hasOptions || hasConfig) {
+ options.${prefix}.${name} =
+ lib.optionalAttrs hasOptions optionsForArgs.${namespace}
+ // {
+ enable = lib.mkEnableOption name;
+ };
+ })
+ ];
+}