lib/types: init

This commit is contained in:
DavHau 2023-10-22 21:20:33 +01:00 committed by mergify[bot]
parent aac7f3f77e
commit 8b5ddd6fe9
4 changed files with 43 additions and 59 deletions

30
lib/types/default.nix Normal file
View File

@ -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;
}

View File

@ -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;
}));

View File

@ -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;
};

View File

@ -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;
};