feat: working transient deps

This commit is contained in:
Jake Hamilton 2024-07-03 00:35:21 -07:00
parent 2be3111b2c
commit aa0fd6128b
Signed by: jakehamilton
GPG key ID: 9762169A1B35EA68
12 changed files with 1300 additions and 1309 deletions

View file

@ -3,10 +3,10 @@
"lib": { "lib": {
"locked": { "locked": {
"dir": "lib", "dir": "lib",
"dirtyRev": "a707b0f06be6b36bcbfe88d0a9a5b9a803983a06-dirty", "dirtyRev": "2be3111b2c0911f40b47fe0a1fb22b5f5188cf59-dirty",
"dirtyShortRev": "a707b0f-dirty", "dirtyShortRev": "2be3111-dirty",
"lastModified": 1719079124, "lastModified": 1719251485,
"narHash": "sha256-4HwA3q5f7SUBmcXX9Vz9WsA9oHBQ/GiZTwE4iSVq9s8=", "narHash": "sha256-63NvfFVeTDITfNu60rmCUlaZtAeZUnvrIaOLSk9ScC8=",
"type": "git", "type": "git",
"url": "file:../?dir=lib" "url": "file:../?dir=lib"
}, },

View file

@ -4,184 +4,166 @@ lib: {
## Merge a list of option definitions into a single value. ## Merge a list of option definitions into a single value.
## ##
## @type Location -> List Definition -> Any ## @type Location -> List Definition -> Any
default = default = location: definitions: let
location: definitions: values = lib.options.getDefinitionValues definitions;
let first = builtins.elemAt values 0;
values = lib.options.getDefinitionValues definitions; mergedFunctions = x: lib.options.mergeDefault location (builtins.map (f: f x) values);
first = builtins.elemAt values 0; mergedLists = builtins.concatLists values;
mergedFunctions = x: lib.options.mergeDefault location (builtins.map (f: f x) values); mergedAttrs = builtins.foldl' lib.attrs.merge {} values;
mergedLists = builtins.concatLists values; mergedBools = builtins.any lib.bools.or false values;
mergedAttrs = builtins.foldl' lib.attrs.merge { } values; mergedStrings = lib.strings.concat values;
mergedBools = builtins.any lib.bools.or false values; in
mergedStrings = lib.strings.concat values; if builtins.length values == 1
in then builtins.elemAt values 0
if builtins.length values == 1 then else if builtins.all builtins.isFunction values
builtins.elemAt values 0 then mergedFunctions
else if builtins.all builtins.isFunction values then else if builtins.all builtins.isList values
mergedFunctions then mergedLists
else if builtins.all builtins.isList values then else if builtins.all builtins.isAttrs values
mergedLists then mergedAttrs
else if builtins.all builtins.isAttrs values then else if builtins.all builtins.isBool values
mergedAttrs then mergedBools
else if builtins.all builtins.isBool values then else if builtins.all lib.strings.isString values
mergedBools then mergedStrings
else if builtins.all lib.strings.isString values then else if builtins.all builtins.isInt values && builtins.all (x: x == first) values
mergedStrings then first
else if builtins.all builtins.isInt values && builtins.all (x: x == first) values then
first
# TODO: Improve this error message to show the location and definitions for the option. # TODO: Improve this error message to show the location and definitions for the option.
else else builtins.throw "Cannot merge definitions.";
builtins.throw "Cannot merge definitions.";
## Merge multiple option definitions together. ## Merge multiple option definitions together.
## ##
## @type Location -> Type -> List Definition ## @type Location -> Type -> List Definition
definitions = definitions = location: type: definitions: let
location: type: definitions: identifier = lib.options.getIdentifier location;
let resolve = definition: let
identifier = lib.options.getIdentifier location; properties = builtins.addErrorContext "while evaluating definitions from `${definition.__file__ or "<unknown>"}`:" (
resolve = lib.modules.apply.properties definition.value
definition: );
let normalize = value: {
properties = builtins.addErrorContext "while evaluating definitions from `${definition.__file__}`:" ( __file__ = definition.__file__;
lib.modules.apply.properties definition.value inherit value;
);
normalize = value: {
__file__ = definition.__file__;
inherit value;
};
in
builtins.map normalize properties;
resolved = builtins.concatMap resolve definitions;
overridden = lib.modules.apply.overrides resolved;
values =
if builtins.any (definition: lib.types.is "order" definition.value) overridden.values then
lib.modules.apply.order overridden.values
else
overridden.values;
isDefined = values != [ ];
invalid = builtins.filter (definition: !(type.check definition.value)) values;
merged =
if isDefined then
if builtins.all (definition: type.check definition.value) values then
type.merge location values
else
builtins.throw "A definition for `${identifier}` is not of type `${type.description}`. Definition values:${lib.options.getDefinitions invalid}"
else
builtins.throw "The option `${identifier}` is used but not defined.";
optional = if isDefined then { value = merged; } else { };
in
{
inherit
isDefined
values
merged
optional
;
raw = {
inherit values;
inherit (overridden) highestPriority;
}; };
in
builtins.map normalize properties;
resolved = builtins.concatMap resolve definitions;
overridden = lib.modules.apply.overrides resolved;
values =
if builtins.any (definition: lib.types.is "order" definition.value) overridden.values
then lib.modules.apply.order overridden.values
else overridden.values;
isDefined = values != [];
invalid = builtins.filter (definition: !(type.check definition.value)) values;
merged =
if isDefined
then
if builtins.all (definition: type.check definition.value) values
then type.merge location values
else builtins.throw "A definition for `${identifier}` is not of type `${type.description}`. Definition values:${lib.options.getDefinitions invalid}"
else builtins.throw "The option `${identifier}` is used but not defined.";
optional =
if isDefined
then {value = merged;}
else {};
in {
inherit
isDefined
values
merged
optional
;
raw = {
inherit values;
inherit (overridden) highestPriority;
}; };
};
## Merge multiple option declarations together. ## Merge multiple option declarations together.
## ##
## @type Location -> List Option ## @type Location -> List Option
declarations = declarations = location: options: let
location: options: merge = result: option: let
let mergedType = result.type.mergeType option.options.type.functor;
merge = isTypeMergeable = mergedType != null;
result: option: shared = name: option.options ? ${name} && result ? ${name};
let typeSet = lib.attrs.when ((shared "type") && isTypeMergeable) {type = mergedType;};
mergedType = result.type.mergeType option.options.type.functor; files = result.declarations;
isTypeMergeable = mergedType != null; serializedFiles = builtins.concatStringsSep " and " files;
shared = name: option.options ? ${name} && result ? ${name}; getSubModules = option.options.type.getSubModules or null;
typeSet = lib.attrs.when ((shared "type") && isTypeMergeable) { type = mergedType; }; submodules =
files = result.declarations; if getSubModules != null
serializedFiles = builtins.concatStringsSep " and " files;
getSubModules = option.options.type.getSubModules or null;
submodules =
if getSubModules != null then
builtins.map (module: {
__file__ = option.__file__;
includes = [ module ];
}) getSubModules
++ result.options
else
result.options;
in
if
shared "default"
|| shared "example"
|| shared "description"
|| shared "apply"
|| (shared "type" && !isTypeMergeable)
then then
builtins.throw "The option `${lib.options.getIdentifier location}` in `${option.__file__}` is already declared in ${serializedFiles}" builtins.map (module: {
else __file__ = option.__file__;
option.options includes = [module];
// result })
// { getSubModules
declarations = result.declarations ++ [ option.__file__ ]; ++ result.options
options = submodules; else result.options;
}
// typeSet;
in in
if
shared "default"
|| shared "example"
|| shared "description"
|| shared "apply"
|| (shared "type" && !isTypeMergeable)
then builtins.throw "The option `${lib.options.getIdentifier location}` in `${option.__file__}` is already declared in ${serializedFiles}"
else
option.options
// result
// {
declarations = result.declarations ++ [option.__file__];
options = submodules;
}
// typeSet;
in
builtins.foldl' merge { builtins.foldl' merge {
inherit location; inherit location;
declarations = [ ]; declarations = [];
options = [ ]; options = [];
} options; }
options;
## Merge an option, only supporting a single unique definition. ## Merge an option, only supporting a single unique definition.
## ##
## @type String -> Location -> List Definition -> Any ## @type String -> Location -> List Definition -> Any
unique = unique = message: location: definitions: let
message: location: definitions: identifier = lib.options.getIdentifier location;
let total = builtins.length definitions;
identifier = lib.options.getIdentifier location; first = builtins.elemAt definitions 0;
total = builtins.length definitions; in
first = builtins.elemAt definitions 0; if total == 1
in then first.value
if total == 1 then else if total == 0
first.value then builtins.throw "Cannot merge unused option `${identifier}`.\n${message}"
else if total == 0 then else builtins.throw "The option `${identifier}` is defined multiple times, but must be unique.\n${message}\nDefinitions:${lib.options.getDefinitions definitions}";
builtins.throw "Cannot merge unused option `${identifier}`.\n${message}"
else
builtins.throw "The option `${identifier}` is defined multiple times, but must be unique.\n${message}\nDefinitions:${lib.options.getDefinitions definitions}";
## Merge a single instance of an option. ## Merge a single instance of an option.
## ##
## @type Location -> List Definition -> Any ## @type Location -> List Definition -> Any
one = lib.options.merge.unique ""; one = lib.options.merge.unique "";
equal = equal = location: definitions: let
location: definitions: identifier = lib.options.getIdentifier location;
let first = builtins.elemAt definitions 0;
identifier = lib.options.getIdentifier location; rest = builtins.tail definitions;
first = builtins.elemAt definitions 0; merge = x: y:
rest = builtins.tail definitions; if x != y
merge = then builtins.throw "The option `${identifier}` has conflicting definitions:${lib.options.getDefinitions definitions}"
x: y: else x;
if x != y then merged = builtins.foldl' merge first rest;
builtins.throw "The option `${identifier}` has conflicting definitions:${lib.options.getDefinitions definitions}" in
else if builtins.length definitions == 0
x; then builtins.throw "Cannot merge unused option `${identifier}`."
merged = builtins.foldl' merge first rest; else if builtins.length definitions == 1
in then first.value
if builtins.length definitions == 0 then else merged.value;
builtins.throw "Cannot merge unused option `${identifier}`."
else if builtins.length definitions == 1 then
first.value
else
merged.value;
}; };
## Check whether a value is an option. ## Check whether a value is an option.
@ -192,50 +174,46 @@ lib: {
## Create an option. ## Create an option.
## ##
## @type { type? :: String | Null, apply? :: (a -> b) | Null, default? :: { value :: a, text :: String }, example? :: String | Null, visible? :: Bool | Null, internal? :: Bool | Null, writable? :: Bool | Null, description? :: String | Null } -> Option a ## @type { type? :: String | Null, apply? :: (a -> b) | Null, default? :: { value :: a, text :: String }, example? :: String | Null, visible? :: Bool | Null, internal? :: Bool | Null, writable? :: Bool | Null, description? :: String | Null } -> Option a
create = create = settings @ {
settings@{ type ? lib.types.unspecified,
type ? lib.types.unspecified, apply ? null,
apply ? null, default ? {},
default ? { }, example ? null,
example ? null, visible ? null,
visible ? null, internal ? null,
internal ? null, writable ? null,
writable ? null, description ? null,
description ? null, }: {
}: __type__ = "option";
{ inherit
__type__ = "option"; type
inherit apply
type default
apply example
default visible
example internal
visible writable
internal description
writable ;
description };
;
};
## Create a sink option. ## Create a sink option.
## ##
## @type @alias lib.options.create ## @type @alias lib.options.create
sink = sink = settings: let
settings: defaults = {
let internal = true;
defaults = { visible = false;
internal = true; default = false;
visible = false; description = "A sink option for unused definitions";
default = false; type = lib.types.create {
description = "A sink option for unused definitions"; name = "sink";
type = lib.types.create { check = lib.fp.const true;
name = "sink"; merge = lib.fp.const (lib.fp.const false);
check = lib.fp.const true;
merge = lib.fp.const (lib.fp.const false);
};
apply = value: builtins.throw "Cannot read the value of a Sink option.";
}; };
in apply = value: builtins.throw "Cannot read the value of a Sink option.";
};
in
lib.options.create (defaults // settings); lib.options.create (defaults // settings);
## Get the definition values from a list of options definitions. ## Get the definition values from a list of options definitions.
@ -246,94 +224,93 @@ lib: {
## Convert a list of option identifiers into a single identifier. ## Convert a list of option identifiers into a single identifier.
## ##
## @type List String -> String ## @type List String -> String
getIdentifier = getIdentifier = location: let
location: special = [
let # lib.types.attrs.of (lib.types.submodule {})
special = [ "<name>"
# lib.types.attrs.of (lib.types.submodule {}) # lib.types.list.of (submodule {})
"<name>" "*"
# lib.types.list.of (submodule {}) # lib.types.function
"*" "<function body>"
# lib.types.function ];
"<function body>" escape = part:
]; if builtins.elem part special
escape = part: if builtins.elem part special then part else lib.strings.escape.nix.identifier part; then part
in else lib.strings.escape.nix.identifier part;
in
lib.strings.concatMapSep "." escape location; lib.strings.concatMapSep "." escape location;
## Get a string message of the definitions for an option. ## Get a string message of the definitions for an option.
## ##
## @type List Definition -> String ## @type List Definition -> String
getDefinitions = getDefinitions = definitions: let
definitions: serialize = definition: let
let valueWithRecursionLimit =
serialize = lib.generators.withRecursion {
definition: limit = 10;
let throw = false;
valueWithRecursionLimit = lib.generators.withRecursion { }
limit = 10; definition.value;
throw = false;
} definition.value;
eval = builtins.tryEval (lib.generators.pretty { } valueWithRecursionLimit); eval = builtins.tryEval (lib.generators.pretty {} valueWithRecursionLimit);
lines = lib.strings.split "\n" eval.value; lines = lib.strings.split "\n" eval.value;
linesLength = builtins.length lines; linesLength = builtins.length lines;
firstFiveLines = lib.lists.take 5 lines; firstFiveLines = lib.lists.take 5 lines;
ellipsis = lib.lists.when (linesLength > 5) "..."; ellipsis = lib.lists.when (linesLength > 5) "...";
value = builtins.concatStringsSep "\n " (firstFiveLines ++ ellipsis); value = builtins.concatStringsSep "\n " (firstFiveLines ++ ellipsis);
result = result =
if !eval.success then if !eval.success
"" then ""
else if linesLength > 1 then else if linesLength > 1
":\n " + value then ":\n " + value
else else ": " + value;
": " + value; in "\n- In `${definition.__file__}`${result}";
in in
"\n- In `${definition.__file__}`${result}";
in
lib.strings.concatMap serialize definitions; lib.strings.concatMap serialize definitions;
## Run a set of definitions, calculating the resolved value and associated information. ## Run a set of definitions, calculating the resolved value and associated information.
## ##
## @type Location -> Option -> List Definition -> String & { value :: Any, highestPriority :: Int, isDefined :: Bool, files :: List String, definitions :: List Any, definitionsWithLocations :: List Definition } ## @type Location -> Option -> List Definition -> String & { value :: Any, highestPriority :: Int, isDefined :: Bool, files :: List String, definitions :: List Any, definitionsWithLocations :: List Definition }
run = run = location: option: definitions: let
location: option: definitions: identifier = lib.options.getIdentifier location;
let
identifier = lib.options.getIdentifier location;
definitionsWithDefault = definitionsWithDefault =
if option ? default && option.default ? value then if option ? default && option.default ? value
[ then
{ [
__file__ = builtins.head option.declarations; {
value = lib.modules.overrides.option option.default.value; __file__ = builtins.head option.declarations;
} value = lib.modules.overrides.option option.default.value;
] }
++ definitions ]
else ++ definitions
definitions; else definitions;
merged = merged =
if option.writable or null == false && builtins.length definitionsWithDefault > 1 then if option.writable or null == false && builtins.length definitionsWithDefault > 1
let then let
separatedDefinitions = builtins.map ( separatedDefinitions =
definition: builtins.map (
definition:
definition definition
// { // {
value = (lib.options.merge.definitions location option.type [ definition ]).merged; value = (lib.options.merge.definitions location option.type [definition]).merged;
} }
) definitionsWithDefault; )
in definitionsWithDefault;
builtins.throw "The option `${identifier}` is not writable, but is set more than once:${lib.options.getDefinitions separatedDefinitions}" in
else builtins.throw "The option `${identifier}` is not writable, but is set more than once:${lib.options.getDefinitions separatedDefinitions}"
lib.options.merge.definitions location option.type definitionsWithDefault; else lib.options.merge.definitions location option.type definitionsWithDefault;
value = if option.apply or null != null then option.apply merged.merged else merged.merged; value =
in if option.apply or null != null
then option.apply merged.merged
else merged.merged;
in
option option
// { // {
value = builtins.addErrorContext "while evaluating the option `${identifier}`:" value; value = builtins.addErrorContext "while evaluating the option `${identifier}`:" value;

View file

@ -1048,7 +1048,7 @@ lib: {
merge = location: definitions: let merge = location: definitions: let
process = value: process = value:
if initial.check value if initial.check value
then (builtins.trace "transforming...") transform value then transform value
else value; else value;
normalize = definition: definition // {value = process definition.value;}; normalize = definition: definition // {value = process definition.value;};
normalized = builtins.map normalize definitions; normalized = builtins.map normalize definitions;
@ -1068,6 +1068,43 @@ lib: {
}; };
}; };
## Create a type that allows a value which is either the final type or is transformable
## to the final type.
##
## @type Attrs -> (Any -> Any) -> Attrs -> Attrs
coerceWithLocation = initial: transform: final: let
in
if initial.getSubModules != null
then builtins.throw "lib.types.coerceWithLocation's first argument may not have submodules, but got ${initial.description}"
else
lib.types.create {
name = "Coerce";
description = "${initial.description} that is transformed to ${final.description}";
fallback = final.fallback;
check = value: final.check value || (initial.check value && final.check (transform [] value));
merge = location: definitions: let
process = value:
if initial.check value
then transform location value
else value;
normalize = definition: definition // {value = process definition.value;};
normalized = builtins.map normalize definitions;
in
final.merge location normalized;
getSubOptions = final.getSubOptions;
getSubModules = final.getSubModules;
withSubModules = modules: lib.types.coerceWithLocation initial transform (final.withSubModules modules);
mergeType = x: y: null;
functor =
lib.types.functor "coerceWithLocation"
// {
wrapped = final;
};
children = {
inherit initial final;
};
};
dag = { dag = {
## Create a type that allows a DAG (Directed Acyclic Graph) of a given type. ## Create a type that allows a DAG (Directed Acyclic Graph) of a given type.
## ##

View file

@ -8,10 +8,10 @@
}, },
"locked": { "locked": {
"dir": "foundation", "dir": "foundation",
"dirtyRev": "a707b0f06be6b36bcbfe88d0a9a5b9a803983a06-dirty", "dirtyRev": "2be3111b2c0911f40b47fe0a1fb22b5f5188cf59-dirty",
"dirtyShortRev": "a707b0f-dirty", "dirtyShortRev": "2be3111-dirty",
"lastModified": 1719079124, "lastModified": 1719251485,
"narHash": "sha256-hz9vVcHSvlq/W01UOh/GqPFUoH9DzCFB16n23oj7fnQ=", "narHash": "sha256-9G1TPBdlQNXCZf6A66bCT9m2vhodkSF+rDtqOVuFteY=",
"type": "git", "type": "git",
"url": "file:../?dir=foundation" "url": "file:../?dir=foundation"
}, },
@ -24,10 +24,10 @@
"lib": { "lib": {
"locked": { "locked": {
"dir": "lib", "dir": "lib",
"dirtyRev": "a707b0f06be6b36bcbfe88d0a9a5b9a803983a06-dirty", "dirtyRev": "2be3111b2c0911f40b47fe0a1fb22b5f5188cf59-dirty",
"dirtyShortRev": "a707b0f-dirty", "dirtyShortRev": "2be3111-dirty",
"lastModified": 1719079124, "lastModified": 1719251485,
"narHash": "sha256-hz9vVcHSvlq/W01UOh/GqPFUoH9DzCFB16n23oj7fnQ=", "narHash": "sha256-9G1TPBdlQNXCZf6A66bCT9m2vhodkSF+rDtqOVuFteY=",
"type": "git", "type": "git",
"url": "file:../?dir=lib" "url": "file:../?dir=lib"
}, },

View file

@ -83,7 +83,13 @@ in {
} }
); );
in in
built // {inherit (package) meta;}; built
// {
inherit (package) meta;
extras = {
inherit package;
};
};
}; };
}; };
} }

View file

@ -1,16 +1,13 @@
# This file handles creating all of the exports for this project and is not # This file handles creating all of the exports for this project and is not
# exported itself. # exported itself.
{ {config}: let
lib, inherit (config) lib;
config,
}: let
lib' = config.lib;
in { in {
freeform = lib.types.any; # freeform = lib.types.any;
config = { config = {
exports = { exports = {
lib = config.lib; inherit lib;
modules = import ./modules.nix; modules = import ./modules.nix;
packages = { packages = {
@ -25,7 +22,7 @@ in {
# }; # };
# })) # }))
# .config; # .config;
# foundation-gcc = config.packages.foundation.gcc; foundation-gcc = config.packages.foundation.gcc;
# foundation-binutils = config.packages.foundation.binutils; # foundation-binutils = config.packages.foundation.binutils;
# foundation-linux-headers = config.packages.foundation.linux-headers.versions.latest.extend { # foundation-linux-headers = config.packages.foundation.linux-headers.versions.latest.extend {
# platform.host = lib.modules.overrides.force "x86_64-linux"; # platform.host = lib.modules.overrides.force "x86_64-linux";

View file

@ -1,8 +1,9 @@
{ {
lib, lib,
lib',
config, config,
}: { }: let
lib' = config.lib;
in {
config = { config = {
lib.packages = { lib.packages = {
dependencies = { dependencies = {
@ -20,52 +21,85 @@
in in
builtins.head sorted; builtins.head sorted;
resolve = package: resolve = alias:
if package ? versions if alias ? versions
then then
package.versions.${config.preferences.packages.version} alias.versions.${config.preferences.packages.version}
or (package.versions.${lib'.packages.getLatest package}) or (alias.versions.${lib'.packages.getLatest alias})
else package; else alias;
build = package: build: host: target: let build = alias: build: host: target: let
resolved = lib'.packages.resolve package; package = lib'.packages.resolve alias;
buildDependencies = build': host': target': buildDependencies = build': host': target':
builtins.mapAttrs (name: dep: lib'.packages.build dep build' host' target'); builtins.mapAttrs (name: dep: lib'.packages.build dep build' host' target');
result = resolved.extend ( result = lib.modules.run {
{config}: { modules =
config = { package.__modules__
platform = { ++ [
build = build; lib'.types.package.children.submodule
host = host; (
target = lib.modules.override 150 target; {config}: {
}; config = {
__modules__ = package.__modules__;
platform = {
build = lib.modules.overrides.force (lib'.systems.withBuildInfo build);
host = lib.modules.overrides.force (lib'.systems.withBuildInfo host);
target = lib.modules.overrides.force (lib'.systems.withBuildInfo target);
};
deps = { # NOTE: This does not seem to work and instead the pre-existing deps are used.
build = { # This causes an issue because the platforms will be wrong.
only = buildDependencies build build build resolved.deps.build.only; # deps = {
build = buildDependencies build build target resolved.deps.build.build; # build = {
host = buildDependencies build host target resolved.deps.build.host; # only = buildDependencies build build build package.deps.build.only;
target = buildDependencies build target target resolved.deps.build.target; # build = buildDependencies build build target package.deps.build.build;
}; # host = buildDependencies build host target package.deps.build.host;
host = { # target = buildDependencies build target target package.deps.build.target;
only = buildDependencies host host host resolved.deps.host.only; # };
host = buildDependencies host host target resolved.deps.host.host; # host = {
target = buildDependencies host target target resolved.deps.host.target; # only = buildDependencies host host host package.deps.host.only;
}; # host = buildDependencies host host target package.deps.host.host;
target = { # target = buildDependencies host target target package.deps.host.target;
only = buildDependencies target target target resolved.deps.target.only; # };
target = buildDependencies target target target resolved.deps.target.target; # target = {
}; # only = buildDependencies target target target package.deps.target.only;
}; # target = buildDependencies target target target package.deps.target.target;
# };
# };
};
}
)
];
};
package = config.builder.build config; resolved =
result.config
// {
deps = {
build = {
only = buildDependencies build build build package.deps.build.only;
build = buildDependencies build build target package.deps.build.build;
host = buildDependencies build host target package.deps.build.host;
target = buildDependencies build target target package.deps.build.target;
};
host = {
only = buildDependencies host host host package.deps.host.only;
host = buildDependencies host host target package.deps.host.host;
target = buildDependencies host target target package.deps.host.target;
};
target = {
only = buildDependencies target target target package.deps.target.only;
target = buildDependencies target target target package.deps.target.target;
};
}; };
} };
);
in in
result; resolved
// {
package = resolved.builder.build resolved;
};
}; };
}; };
} }

File diff suppressed because it is too large Load diff

View file

@ -1,8 +1,11 @@
{ {
lib, lib,
lib',
config, config,
}: { }: let
inherit (config) preferences builders;
lib' = config.lib;
in {
config = { config = {
lib.types = { lib.types = {
license = let license = let
@ -52,6 +55,12 @@
in in
lib.types.either type (lib.types.list.of type); lib.types.either type (lib.types.list.of type);
platform =
lib.types.coerce
lib.types.string
lib'.systems.withBuildInfo
lib'.systems.types.platformWithBuildInfo;
builder = lib.types.submodule { builder = lib.types.submodule {
freeform = lib.types.any; freeform = lib.types.any;
@ -63,385 +72,287 @@
}; };
}; };
packages = lib.types.attrs.of (lib'.types.alias); packages = lib.types.attrs.of (lib.types.attrs.of lib'.types.alias);
alias = lib.types.attrs.of ( dependencies = let
lib.types.submodule { initial =
options = { (lib.types.attrs.lazy lib.types.any)
versions = lib.options.create { // {
description = "All available package versions."; check = value:
type = lib.types.attrs.of lib'.types.package.base; lib.types.attrs.any.check value
}; && value ? versions;
}; };
} in
); lib.types.attrs.of (lib.types.coerce initial lib'.packages.resolve lib'.types.package);
dependencies = lib.types.attrs.of ( alias = lib.types.submodule {
lib.types.nullish (lib'.types.package.resolved) options = {
); stable = lib.options.create {
description = "The stable version of the package.";
type = lib.types.nullish lib'.types.package;
};
package = { latest = lib.options.create {
resolved = let description = "The latest version of the package.";
initial = type = lib'.types.package;
lib.types.raw };
// {
check = value:
!(value ? __merged__)
&& lib.types.raw.check
value;
};
transform = value: let versions = lib.options.create {
package = lib'.packages.resolve value; description = "Available versions of the package.";
packageSubmodule = package.extend (args: { type = lib.types.attrs.of lib'.types.package;
options.__export__ = lib.options.create { default.value = {};
type = lib.types.raw; };
default.value = { };
inherit (args) options config; };
};
};
config.__export__ = { package = let
inherit (args) options config; normalize = value:
}; if builtins.isFunction value || builtins.isList value
}); then value
type = lib'.types.package.base.withSubModules (lib'.types.package.base.getSubModules else if value ? __modules__
++ [ then value.__modules__
(args: { else {
options.__export__ = lib.options.create { config = value;
type = lib.types.raw; };
default.value = {
inherit (args) options config;
};
};
config.__export__ = { initial = lib.types.create {
inherit (args) options config; name = "PackageConfig";
}; description = "configuration for a package";
}) check = value: builtins.isFunction value || builtins.isAttrs value || builtins.isList value;
]); merge = location: definitions: let
typeSubmodule = lib.modules.run { normalized =
modules = type.getSubModules; builtins.map
args = type.functor.payload.args; (definition: lib.lists.from.any (normalize definition.value))
}; definitions;
getOptions = export: let
process = path: option:
if builtins.isAttrs option
then
if lib.types.is "option" option
then [
{
inherit path;
option = option;
}
]
else
builtins.concatLists (
lib.attrs.mapToList
(name: value: process (path ++ [name]) value)
option
)
else [];
in
process [] export.options;
packageOptions = getOptions packageSubmodule.__export__;
typeOptions = getOptions typeSubmodule.config.__export__;
customOptions =
builtins.filter
(
packageOption:
builtins.all (typeOption: packageOption.path != typeOption.path) typeOptions
)
packageOptions;
packageOptionsIds = builtins.map (option: builtins.concatStringsSep "." option.path) packageOptions;
typeOptionsIds = builtins.map (option: builtins.concatStringsSep "." option.path) typeOptions;
customOptionsIds = builtins.map (option: builtins.concatStringsSep "." option.path) customOptions;
resolvedOptions =
builtins.foldl' (
resolved: option: let
first = builtins.head option.path;
generated = lib.attrs.set option.path option.option;
in
if first == "__export__" || first == "__module__" || first == "__merged__"
then resolved
else lib.attrs.mergeRecursive resolved generated
) {}
customOptions;
in in
# (builtins.trace (builtins.deepSeq packageOptionsIds packageOptionsIds)) builtins.concatLists
# (builtins.trace (builtins.deepSeq typeOptionsIds typeOptionsIds)) normalized;
# (builtins.trace (builtins.deepSeq customOptionsIds customOptionsIds)) };
# (builtins.trace packageSubmodule.__export__.config)
(args: {
__file__ = packageSubmodule.__export__.config.__file__ or "virtual:tidepool/src/lib/types.nix";
options = transform = location: value: let
resolvedOptions modules =
// { lib.lists.from.any (normalize value);
__merged__ = lib.options.create {
type = lib.types.bool;
default.value = true;
};
};
config = result = lib.modules.run {
builtins.removeAttrs package ["extend" "package" "platform"] prefix = location;
// { modules =
platform = { modules
build = lib.modules.overrides.default package.platform.build.triple; ++ [submodule {config.__modules__ = modules;}];
host = lib.modules.overrides.default package.platform.host.triple; };
target = lib.modules.overrides.default package.platform.target.triple;
};
};
# // {
# builder =
# (builtins.trace "builder")
# (builtins.trace (args.config ? builder))
# lib.modules.alias
# packageSubmodule.__export__.options.builder;
# };
});
in in
lib.types.coerce initial transform lib'.types.package.base; result.config;
base = lib.types.submodule ( final = lib.types.attrs.any;
{
config,
meta,
}: {
options = {
extend = lib.options.create {
description = "Extend the package's submodules with additional configuration.";
type = lib.types.function lib.types.raw;
default.value = value: let
result = meta.extend {
modules =
if builtins.isAttrs value
then [{config = value;}]
else lib.lists.from.any value;
};
in
result.config;
};
name = lib.options.create { submodule = {config}: {
description = "The name of the package."; options = {
type = lib.types.string; __modules__ = lib.options.create {
default = { description = "User specified modules for the package definition.";
text = "\${config.pname}-\${config.version}"; type = lib.types.list.of (initial
value = // {
if config.pname != null && config.version != null merge = lib.options.merge.one;
then "${config.pname}-${config.version}" });
else ""; # writable = false;
}; internal = true;
}; default.value = [];
};
pname = lib.options.create { meta = {
description = "The program name for the package"; description = lib.options.create {
description = "The description for the package.";
type = lib.types.nullish lib.types.string; type = lib.types.nullish lib.types.string;
default.value = null; default.value = null;
}; };
version = lib.options.create { homepage = lib.options.create {
description = "The version for the package."; description = "The homepage for the package.";
type = lib.types.nullish lib.types.version; type = lib.types.nullish lib.types.string;
default.value = null; default.value = null;
}; };
meta = { license = lib.options.create {
description = lib.options.create { description = "The license for the package.";
description = "The description for the package."; type = lib.types.nullish lib'.types.license;
type = lib.types.nullish lib.types.string; default.value = null;
default.value = null;
};
homepage = lib.options.create {
description = "The homepage for the package.";
type = lib.types.nullish lib.types.string;
default.value = null;
};
license = lib.options.create {
description = "The license for the package.";
type = lib.types.nullish lib'.types.license;
default.value = null;
};
free = lib.options.create {
description = "Whether the package is free.";
type = lib.types.bool;
default.value = true;
};
insecure = lib.options.create {
description = "Whether the package is insecure.";
type = lib.types.bool;
default.value = false;
};
broken = lib.options.create {
description = "Whether the package is broken.";
type = lib.types.bool;
default.value = false;
};
main = lib.options.create {
description = "The main entry point for the package.";
type = lib.types.nullish lib.types.string;
default.value = null;
};
platforms = lib.options.create {
description = "The platforms the package supports.";
type = lib.types.list.of lib.types.string;
default.value = [];
};
}; };
platform = { free = lib.options.create {
description = "Whether the package is free.";
type = lib.types.bool;
default.value = true;
};
insecure = lib.options.create {
description = "Whether the package is insecure.";
type = lib.types.bool;
default.value = false;
};
broken = lib.options.create {
description = "Whether the package is broken.";
type = lib.types.bool;
default.value = false;
};
main = lib.options.create {
description = "The main entry point for the package.";
type = lib.types.nullish lib.types.string;
default.value = null;
};
platforms = lib.options.create {
description = "The platforms the package supports.";
type = lib.types.list.of lib.types.string;
default.value = [];
};
};
platform = {
build = lib.options.create {
description = "The build platform for the package.";
type = lib'.types.platform;
default.value = lib'.systems.withBuildInfo "x86_64-linux";
};
host = lib.options.create {
description = "The host platform for the package.";
type = lib'.types.platform;
default.value = lib'.systems.withBuildInfo "x86_64-linux";
};
target = lib.options.create {
description = "The target platform for the package.";
type = lib'.types.platform;
default.value = lib'.systems.withBuildInfo "x86_64-linux";
};
};
name = lib.options.create {
description = "The name of the package.";
type = lib.types.string;
default = {
text = "\${config.pname}-\${config.version}";
value =
if config.pname != null && config.version != null
then "${config.pname}-${config.version}"
else "";
};
};
pname = lib.options.create {
description = "The program name for the package";
type = lib.types.nullish lib.types.string;
default.value = null;
};
version = lib.options.create {
description = "The version for the package.";
type = lib.types.nullish lib.types.version;
default.value = null;
};
builder = lib.options.create {
description = "The builder for the package.";
type = lib'.types.builder;
};
phases = lib.options.create {
description = "The phases for the package.";
type = lib.types.dag.of lib.types.string;
default.value = {};
};
env = lib.options.create {
description = "The environment for the package.";
type = lib.types.attrs.of lib.types.string;
default.value = {};
};
package = lib.options.create {
description = "The built derivation.";
type = lib.types.derivation;
default.value = config.builder.build config;
};
deps = {
build = {
only = lib.options.create {
description = "Dependencies which are only used in the build environment.";
type = lib'.types.dependencies;
default.value = {};
};
build = lib.options.create { build = lib.options.create {
description = "The build platform for the package."; description = "Dependencies which are created in the build environment and are executed in the build environment.";
type = lib.types.string; type = lib'.types.dependencies;
default.value = "x86_64-linux"; default.value = {};
apply = raw: let
system = lib'.systems.from.string raw;
x = lib'.systems.withBuildInfo raw;
in
x;
}; };
host = lib.options.create { host = lib.options.create {
description = "The host platform for the package."; description = "Dependencies which are created in the build environment and are executed in the host environment.";
type = lib.types.string; type = lib'.types.dependencies;
default.value = "x86_64-linux"; default.value = {};
# apply = raw: let
# system = lib'.systems.from.string raw;
# in {
# inherit raw system;
# double = lib'.systems.into.double system;
# triple = lib'.systems.into.triple system;
# };
apply = raw: let
system = lib'.systems.from.string raw;
x = lib'.systems.withBuildInfo raw;
in
x;
}; };
target = lib.options.create { target = lib.options.create {
description = "The target platform for the package."; description = "Dependencies which are created in the build environment and are executed in the target environment.";
type = lib.types.string; type = lib'.types.dependencies;
default.value = "x86_64-linux"; default.value = {};
# apply = raw: let
# system = lib'.systems.from.string raw;
# in {
# inherit raw system;
# double = lib'.systems.into.double system;
# triple = lib'.systems.into.triple system;
# };
apply = raw: let
system = lib'.systems.from.string raw;
x = lib'.systems.withBuildInfo raw;
in
x;
}; };
}; };
phases = lib.options.create { host = {
description = "The phases for the package."; only = lib.options.create {
type = lib.types.dag.of (lib.types.either lib.types.string (lib.types.function lib.types.string)); description = "Dependencies which are only used in the host environment.";
default.value = {}; type = lib'.types.dependencies;
}; default.value = {};
env = lib.options.create {
description = "The environment for the package.";
type = lib.types.attrs.of lib.types.string;
default.value = {};
};
builder = lib.options.create {
description = "The builder for the package.";
type = lib'.types.builder;
};
deps = {
build = {
only = lib.options.create {
description = "Dependencies which are only used in the build environment.";
type = lib'.types.dependencies;
default.value = {};
};
build = lib.options.create {
description = "Dependencies which are created in the build environment and are executed in the build environment.";
type = lib'.types.dependencies;
default.value = {};
};
host = lib.options.create {
description = "Dependencies which are created in the build environment and are executed in the host environment.";
type = lib'.types.dependencies;
default.value = {};
};
target = lib.options.create {
description = "Dependencies which are created in the build environment and are executed in the target environment.";
type = lib'.types.dependencies;
default.value = {};
};
}; };
host = { host = lib.options.create {
only = lib.options.create { description = "Dependencies which are executed in the host environment.";
description = "Dependencies which are only used in the host environment."; type = lib'.types.dependencies;
type = lib'.types.dependencies; default.value = {};
default.value = {};
};
host = lib.options.create {
description = "Dependencies which are executed in the host environment.";
type = lib'.types.dependencies;
default.value = {};
};
target = lib.options.create {
description = "Dependencies which are executed in the host environment which produces code for the target environment.";
type = lib'.types.dependencies;
default.value = {};
};
}; };
target = { target = lib.options.create {
only = lib.options.create { description = "Dependencies which are executed in the host environment which produces code for the target environment.";
description = "Dependencies which are only used in the target environment."; type = lib'.types.dependencies;
type = lib'.types.dependencies; default.value = {};
default.value = {};
};
target = lib.options.create {
description = "Dependencies which are executed in the target environment.";
type = lib'.types.dependencies;
default.value = {};
};
}; };
}; };
package = lib.options.create { target = {
description = "The built derivation."; only = lib.options.create {
type = lib.types.derivation; description = "Dependencies which are only used in the target environment.";
default.value = config.builder.build config; type = lib'.types.dependencies;
default.value = {};
};
target = lib.options.create {
description = "Dependencies which are executed in the target environment.";
type = lib'.types.dependencies;
default.value = {};
};
}; };
}; };
} };
); };
};
type =
(lib.types.coerceWithLocation initial transform final)
// {
name = "Package";
description = "a package definition";
};
in
type
// {
children =
type.children
// {
inherit submodule;
};
};
}; };
}; };
} }

View file

@ -12,6 +12,8 @@ in {
platforms = ["i686-linux"]; platforms = ["i686-linux"];
}; };
name = "${config.pname}-${config.version}";
pname = "a"; pname = "a";
version = "1.0.0"; version = "1.0.0";

View file

@ -1,15 +1,12 @@
{ {config}: let
lib', inherit (config) lib builders packages;
config,
}: let
inherit (config) builders packages;
in { in {
config.packages.aux.b = { config.packages.aux.b = {
versions = { versions = {
"latest" = {config}: { "latest" = {config}: {
options = { options = {
custom = lib'.options.create { custom = lib.options.create {
type = lib'.types.bool; type = lib.types.bool;
}; };
}; };
@ -18,6 +15,8 @@ in {
platforms = ["i686-linux"]; platforms = ["i686-linux"];
}; };
name = "${config.pname}-${config.version}";
custom = true; custom = true;
pname = "b"; pname = "b";

View file

@ -1,9 +1,7 @@
{ {config}: let
lib, inherit (config) lib;
lib',
config, doubles = lib.systems.doubles.all;
}: let
doubles = lib'.systems.doubles.all;
packages = builtins.removeAttrs config.packages ["cross"]; packages = builtins.removeAttrs config.packages ["cross"];
in { in {
@ -17,13 +15,13 @@ in {
packages = lib.options.create { packages = lib.options.create {
description = "The package set."; description = "The package set.";
type = lib.types.submodule { type = lib.types.submodule {
freeform = lib.types.attrs.of (lib.types.submodule {freeform = lib'.types.alias;}); freeform = lib.types.packages;
options.cross = lib.attrs.generate doubles ( options.cross = lib.attrs.generate doubles (
system: system:
lib.options.create { lib.options.create {
description = "The cross-compiled package set for the ${system} target."; description = "The cross-compiled package set for the ${system} target.";
type = lib'.types.packages; type = lib.types.packages;
default = {}; default = {};
} }
); );
@ -49,38 +47,39 @@ in {
builtins.mapAttrs ( builtins.mapAttrs (
name: alias: let name: alias: let
setHost = package: setHost = package:
if package != {} package;
then # if package != {}
(package.extend ( # then
{config}: { # (package.extend (
config = { # {config}: {
platform = { # config = {
host = lib.modules.overrides.force system; # platform = {
target = lib.modules.overrides.default system; # host = lib.modules.overrides.force system;
}; # target = lib.modules.overrides.default system;
# };
deps = { # deps = {
build = { # build = {
only = setHost package.deps.build.only; # only = setHost package.deps.build.only;
build = setHost package.deps.build.build; # build = setHost package.deps.build.build;
host = setHost package.deps.build.host; # host = setHost package.deps.build.host;
target = setHost package.deps.build.target; # target = setHost package.deps.build.target;
}; # };
host = { # host = {
only = setHost package.deps.host.only; # only = setHost package.deps.host.only;
host = setHost package.deps.host.host; # host = setHost package.deps.host.host;
target = setHost package.deps.host.target; # target = setHost package.deps.host.target;
}; # };
target = { # target = {
only = setHost package.deps.target.only; # only = setHost package.deps.target.only;
target = setHost package.deps.target.target; # target = setHost package.deps.target.target;
}; # };
}; # };
}; # };
} # }
)) # ))
.config # .config
else package; # else package;
updated = updated =
alias alias