diff --git a/lib/types/default.nix b/lib/types/default.nix new file mode 100644 index 00000000..a5a8b178 --- /dev/null +++ b/lib/types/default.nix @@ -0,0 +1,30 @@ +{ + lib, + dream2nix, + specialArgs, + ... +}: let + t = lib.types; +in rec { + derivation = t.oneOf [t.str t.path t.package]; + + # A stricteer submodule type that prevents derivations from being + # detected as modules by accident. (derivations are attrs as well as modules) + drvPart = let + type = t.submoduleWith { + modules = [dream2nix.modules.dream2nix.core]; + inherit specialArgs; + }; + in + type + // { + # Ensure that derivations are never detected as modules by accident. + check = val: type.check val && (val.type or null != "derivation"); + }; + + # polymorphic type, that can either represent a derivation or a drv-part. + # The stricter`drvPart` type is needed to prevent derivations being + # classified as modules by accident. + # This is important because derivations cannot be merged with drv-parts. + drvPartOrPackage = t.either derivation drvPart; +} diff --git a/modules/dream2nix/WIP-nodejs-builder-v3/types.nix b/modules/dream2nix/WIP-nodejs-builder-v3/types.nix index 4ad58aeb..67187e65 100644 --- a/modules/dream2nix/WIP-nodejs-builder-v3/types.nix +++ b/modules/dream2nix/WIP-nodejs-builder-v3/types.nix @@ -10,23 +10,9 @@ l = lib // builtins; t = l.types; - derivationType = t.oneOf [t.str t.path t.package]; - - # A stricter submodule type that prevents derivations from being - # detected as modules by accident. (derivations are attrs as well as modules) - drvPart = let - type = t.submoduleWith { - modules = [dream2nix.modules.dream2nix.core]; - inherit specialArgs; - }; - in - type - // { - # Ensure that derivations are never detected as modules by accident. - check = val: type.check val && (val.type or null != "derivation"); - }; - - drvPartOrPackage = t.either derivationType drvPart; + dreamTypes = import ../../../lib/types { + inherit dream2nix lib specialArgs; + }; # optPackage = l.mkOption { # # type = t.raw; @@ -35,7 +21,7 @@ # # default = null; # }; optOptionalPackage = l.mkOption { - type = t.nullOr drvPartOrPackage; + type = t.nullOr dreamTypes.drvPartOrPackage; apply = drv: drv.public or drv; default = null; }; @@ -144,7 +130,7 @@ in { fileSystem = { type = t.nullOr (t.attrsOf (t.submodule { options.source = l.mkOption { - type = t.nullOr drvPartOrPackage; + type = t.nullOr dreamTypes.drvPartOrPackage; }; options.bins = optBins; })); diff --git a/modules/dream2nix/mkDerivation/interface.nix b/modules/dream2nix/mkDerivation/interface.nix index aebab952..bae8d433 100644 --- a/modules/dream2nix/mkDerivation/interface.nix +++ b/modules/dream2nix/mkDerivation/interface.nix @@ -10,32 +10,14 @@ common-options = import ../builtins-derivation/derivation-common/options.nix {inherit lib;}; - derivationType = t.oneOf [t.str t.path t.package]; - - # A stricteer submodule type that prevents derivations from being - # detected as modules by accident. (derivations are attrs as well as modules) - drvPart = let - type = t.submoduleWith { - modules = [dream2nix.modules.dream2nix.core]; - inherit specialArgs; - }; - in - type - // { - # Ensure that derivations are never detected as modules by accident. - check = val: type.check val && (val.type or null != "derivation"); - }; - - # polymorphic type, that can either represent a derivation or a drv-part. - # The stricter`drvPart` type is needed to prevent derivations being - # classified as modules by accident. - # This is important because derivations cannot be merged with drv-parts. - drvPartOrPackage = t.either derivationType drvPart; + dreamTypes = import ../../../lib/types { + inherit dream2nix lib specialArgs; + }; # Accepts either a derivation or a drv-parts submodule. # Uses `apply` to automatically convert drv-parts to derivations. optPackage = l.mkOption { - type = t.nullOr drvPartOrPackage; + type = t.nullOr dreamTypes.drvPartOrPackage; apply = drv: drv.public or drv; default = null; }; diff --git a/modules/dream2nix/nodejs-package-lock-v3/interface.nix b/modules/dream2nix/nodejs-package-lock-v3/interface.nix index e045273d..5004dbfb 100644 --- a/modules/dream2nix/nodejs-package-lock-v3/interface.nix +++ b/modules/dream2nix/nodejs-package-lock-v3/interface.nix @@ -14,26 +14,12 @@ t = l.types; cfg = config.nodejs-package-lock-v3; - derivationType = t.oneOf [t.str t.path t.package]; - - # A stricteer submodule type that prevents derivations from being - # detected as modules by accident. (derivations are attrs as well as modules) - drvPart = let - type = t.submoduleWith { - modules = [dream2nix.modules.dream2nix.core]; - inherit specialArgs; - }; - in - type - // { - # Ensure that derivations are never detected as modules by accident. - check = val: type.check val && (val.type or null != "derivation"); - }; - - drvPartOrPackage = t.either derivationType drvPart; + dreamTypes = import ../../../lib/types { + inherit dream2nix lib specialArgs; + }; optPackage = l.mkOption { - type = drvPartOrPackage; + type = dreamTypes.drvPartOrPackage; apply = drv: drv.public or drv; # default = null; };