mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-12-23 14:31:55 +03:00
lib/types: init
This commit is contained in:
parent
aac7f3f77e
commit
8b5ddd6fe9
30
lib/types/default.nix
Normal file
30
lib/types/default.nix
Normal 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;
|
||||
}
|
@ -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;
|
||||
}));
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user