fix: correct broken submodules

This commit is contained in:
Jake Hamilton 2024-06-13 10:22:57 -07:00
parent 9c29945531
commit 856b88321e
Signed by untrusted user: jakehamilton
GPG key ID: 9762169A1B35EA68
12 changed files with 1663 additions and 173 deletions

View file

@ -3,10 +3,10 @@
"lib": { "lib": {
"locked": { "locked": {
"dir": "lib", "dir": "lib",
"dirtyRev": "f24f0876a9103c7adb8120ce9709fb90c73f2a7c-dirty", "dirtyRev": "9c29945531c58ad81f05cd1f4958c8894a733216-dirty",
"dirtyShortRev": "f24f087-dirty", "dirtyShortRev": "9c29945-dirty",
"lastModified": 1718105966, "lastModified": 1718255029,
"narHash": "sha256-L68G29+bPmwZSERg3VYXdfont/w+mssmWnrs6tyBijk=", "narHash": "sha256-iPMsyNszFA+EzjtIpjmu9EAG7zdjLbuugLtfa64dJos=",
"type": "git", "type": "git",
"url": "file:../?dir=lib" "url": "file:../?dir=lib"
}, },

View file

@ -187,7 +187,7 @@ lib: {
in in
withFreeform (withMeta base); withFreeform (withMeta base);
} }
else builtins.throw "Module `${key}` has unsupported attribute(s): ${invalidKeys}"; else builtins.throw "Module `${key}` (${file}) has unsupported attribute(s): ${invalidKeys}";
## Convert a module that is either a function or an attribute set into ## Convert a module that is either a function or an attribute set into
## a resolved attribute set. If the module was a function then it will ## a resolved attribute set. If the module was a function then it will
@ -428,7 +428,7 @@ lib: {
matched = lib.options.run location option definitions'; matched = lib.options.run location option definitions';
unmatched = []; unmatched = [];
} }
else builtins.throw "The option `${lib.options.getIdentifier location}` in module `${(builtins.head optionDeclarations).__file__}` does not support nested options." else builtins.throw "The option `${lib.options.getIdentifier location}` in module `${(builtins.head optionDeclarations).__file__}` would be a parent of the following options, but its type `${(builtins.head optionDeclarations).options.type.description or "<no description>"}` does not support nested options."
else process location declarations definitions else process location declarations definitions
) )
declarationsByName; declarationsByName;
@ -611,7 +611,7 @@ lib: {
collected = collected =
collect collect
(args.path or "") (args.path or "")
(modules ++ [internal]) ([internal] ++ modules)
( (
{ {
inherit options config; inherit options config;
@ -625,7 +625,8 @@ lib: {
// args // args
); );
in in
lib.modules.combine prefix (lib.lists.reverse collected); lib.modules.combine
prefix (lib.lists.reverse collected);
options = merged.matched; options = merged.matched;

View file

@ -423,5 +423,36 @@ in {
}; };
in in
evaluated.config.aux.message == expected; evaluated.config.aux.message == expected;
"submodules" = let
expected = "Hello, World!";
evaluated = lib.modules.run {
modules = [
{
options = {
aux = lib.options.create {
default.value = {
message = "hi";
};
type = lib.types.attrs.of (lib.types.submodule ({name}: {
# freeform = lib.types.any;
options.message = lib.options.create {
type = lib.types.string;
};
}));
};
};
config = {
aux = {
x = {
message = "Hello, World!";
};
};
};
}
];
};
in
evaluated.config.aux.x.message == expected;
}; };
} }

View file

@ -750,10 +750,16 @@ lib: {
description ? null, description ? null,
}: let }: let
getModules = builtins.map ( getModules = builtins.map (
definition: { definition:
__file__ = definition.__file__; if builtins.isAttrs definition
includes = [definition.value]; then {
} __file__ = definition.__file__;
config = definition.value;
}
else {
__file__ = definition.__file__;
includes = [definition.value];
}
); );
base = lib.modules.run { base = lib.modules.run {
@ -762,9 +768,6 @@ lib: {
modules = modules =
[ [
{ {
options.__module__.args.dynamic.name = lib.options.create {
type = lib.types.string;
};
config.__module__.args.dynamic.name = lib.modules.overrides.default "<name>"; config.__module__.args.dynamic.name = lib.modules.overrides.default "<name>";
} }
] ]
@ -989,7 +992,7 @@ lib: {
## @type List Attrs -> Attrs ## @type List Attrs -> Attrs
one = types: let one = types: let
first = builtins.elemAt types 0; first = builtins.elemAt types 0;
rest = lib.lists.tail types; rest = builtins.tail types;
in in
if types == [] if types == []
then builtins.throw "lib.types.one must be given at least one type" then builtins.throw "lib.types.one must be given at least one type"

View file

@ -10,21 +10,24 @@
++ [ ++ [
./src/export.nix ./src/export.nix
{ {
__file__ = ./default.nix; __file__ = "broken";
options.packages.aux = { # options.foundation = lib.options.create {
foundation = lib.options.create { # type = lib.types.attrs.of lib.types.derivation;
type = lib.types.attrs.of lib.types.package; # };
internal = true;
description = "The foundational packages used to construct the larger package set.";
};
};
config.packages.aux = { # config.foundation = foundation;
foundation = foundation; config.packages.foundation =
}; builtins.mapAttrs (name: package: {
name = package.name;
inherit package;
meta = package.meta;
})
foundation;
} }
]; ];
}; };
in in
result.config.exported result.config

View file

@ -8,10 +8,10 @@
}, },
"locked": { "locked": {
"dir": "foundation", "dir": "foundation",
"dirtyRev": "cd12786be17a611976b44fbba3e245eca512535f-dirty", "dirtyRev": "9c29945531c58ad81f05cd1f4958c8894a733216-dirty",
"dirtyShortRev": "cd12786-dirty", "dirtyShortRev": "9c29945-dirty",
"lastModified": 1718199069, "lastModified": 1718255029,
"narHash": "sha256-H2Mkyp9BPDPte+E++uIG2N/vGtcS3H9Q7tM3fOOEXT0=", "narHash": "sha256-fmrDe4GfvVfXZ9lzaOt+tgBUMFCsyKr0Dlnm8aQwAXs=",
"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": "cd12786be17a611976b44fbba3e245eca512535f-dirty", "dirtyRev": "9c29945531c58ad81f05cd1f4958c8894a733216-dirty",
"dirtyShortRev": "cd12786-dirty", "dirtyShortRev": "9c29945-dirty",
"lastModified": 1718199069, "lastModified": 1718255029,
"narHash": "sha256-H2Mkyp9BPDPte+E++uIG2N/vGtcS3H9Q7tM3fOOEXT0=", "narHash": "sha256-fmrDe4GfvVfXZ9lzaOt+tgBUMFCsyKr0Dlnm8aQwAXs=",
"type": "git", "type": "git",
"url": "file:../?dir=lib" "url": "file:../?dir=lib"
}, },

View file

@ -2,7 +2,7 @@
lib, lib,
config, config,
}: let }: let
cfg = config.exports.modules; cfg = config.exports;
type = lib.types.one [ type = lib.types.one [
lib.types.path lib.types.path

View file

@ -2,6 +2,7 @@
config, config,
lib, lib,
}: let }: let
lib' = config.lib;
in { in {
options = { options = {
exports.packages = lib.options.create { exports.packages = lib.options.create {
@ -14,6 +15,8 @@ in {
}; };
config = { config = {
exported.packages = {}; exported.packages = {
# i686-linux = config.packages.foundation;
};
}; };
} }

File diff suppressed because it is too large Load diff

View file

@ -107,164 +107,354 @@ in {
}; };
}; };
package = lib.types.submodule ({config}: { package = {
freeform = lib.types.any; base = lib.types.submodule ({config}: {
freeform = lib.types.any;
options = { options = {
name = lib.options.create { name = lib.options.create {
type = lib.types.string; type = lib.types.string;
default = { default = {
value = "${config.pname}-${config.version or "unknown"}"; value = "${config.pname}-${config.version or "unknown"}";
text = "\${config.pname}-\${config.version}"; text = "\${config.pname}-\${config.version}";
};
description = "The name of the package.";
};
pname = lib.options.create {
type = lib.types.nullish lib.types.string;
default.value = null;
description = "The name of the package.";
};
version = lib.options.create {
type = lib.types.nullish lib.types.string;
default.value = null;
description = "The version of the package.";
};
meta = lib.options.create {
type = lib'.types.meta;
default = {
text = "{ name = <package>.pname; }";
value = {
name = config.pname;
}; };
}; description = "The name of the package.";
description = "The metadata for the package.";
};
env = lib.options.create {
type = lib.types.attrs.of lib.types.string;
default.value = {};
description = "Environment variables for the package's builder to use.";
};
phases = lib.options.create {
type = lib.types.dag.of (
lib.types.either
lib.types.string
(lib.types.function lib.types.string)
);
default.value = {};
description = "Phases for the package's builder to use.";
};
platform = {
build = lib.options.create {
type = lib.types.string;
description = "The platform the package is built on.";
}; };
host = lib.options.create { pname = lib.options.create {
type = lib.types.string; type = lib.types.nullish lib.types.string;
description = "The platform the package is run on."; default.value = null;
description = "The name of the package.";
}; };
target = lib.options.create { version = lib.options.create {
type = lib.types.string; type = lib.types.nullish lib.types.string;
description = "The platform the package generates code for."; default.value = null;
description = "The version of the package.";
}; };
};
builder = lib.options.create { meta = lib.options.create {
type = lib'.types.builder; type = lib'.types.meta;
description = "The builder for the package."; default = {
}; text = "{ name = <package>.pname; }";
value = {
package = lib.options.create { name = config.pname;
type = lib.types.derivation; };
default = {
value = config.builder.build config.builder config;
text = "<derivation>";
};
description = "The package derivation.";
};
deps = {
build = {
only = lib.options.create {
type = lib'.types.dependencies;
default.value = {};
description = "Dependencies which are only used in the build environment.";
}; };
description = "The metadata for the package.";
};
env = lib.options.create {
type = lib.types.attrs.of lib.types.string;
default.value = {};
description = "Environment variables for the package's builder to use.";
};
phases = lib.options.create {
type = lib.types.dag.of (
lib.types.either
lib.types.string
(lib.types.function lib.types.string)
);
default.value = {};
description = "Phases for the package's builder to use.";
};
platform = {
build = lib.options.create { build = lib.options.create {
type = lib'.types.dependencies; type = lib.types.nullish lib.types.string;
default.value = {}; default.value = null;
description = "Dependencies which are created in the build environment and are run in the build environment."; description = "The platform the package is built on.";
}; };
host = lib.options.create { host = lib.options.create {
type = lib'.types.dependencies; type = lib.types.nullish lib.types.string;
default.value = {}; default.value = null;
description = "Dependencies which are created in the build environment and are run in the host environment."; description = "The platform the package is run on.";
}; };
target = lib.options.create { target = lib.options.create {
type = lib'.types.dependencies; type = lib.types.nullish lib.types.string;
default.value = {}; default.value = null;
description = "Dependencies which are created in the build environment and are run in the target environment."; description = "The platform the package generates code for.";
}; };
}; };
host = { builder = lib.options.create {
only = lib.options.create { type = lib'.types.builder;
type = lib'.types.dependencies; description = "The builder for the package.";
default.value = {}; };
description = "Dependencies which are only used in the host environment.";
package = lib.options.create {
type = lib.types.derivation;
default = {
value = config.builder.build config.builder config;
text = "<derivation>";
};
description = "The package derivation.";
};
deps = {
build = {
only = lib.options.create {
type = lib'.types.dependencies;
default.value = {};
description = "Dependencies which are only used in the build environment.";
};
build = lib.options.create {
type = lib'.types.dependencies;
default.value = {};
description = "Dependencies which are created in the build environment and are run in the build environment.";
};
host = lib.options.create {
type = lib'.types.dependencies;
default.value = {};
description = "Dependencies which are created in the build environment and are run in the host environment.";
};
target = lib.options.create {
type = lib'.types.dependencies;
default.value = {};
description = "Dependencies which are created in the build environment and are run in the target environment.";
};
};
host = {
only = lib.options.create {
type = lib'.types.dependencies;
default.value = {};
description = "Dependencies which are only used in the host environment.";
};
host = lib.options.create {
type = lib'.types.dependencies;
default.value = {};
description = "Dependencies which are run in the host environment.";
};
target = lib.options.create {
type = lib'.types.dependencies;
default.value = {};
description = "Dependencies which are run in the host environment which produces code for the target environment.";
};
};
target = {
only = lib.options.create {
type = lib'.types.dependencies;
default.value = {};
description = "Dependencies which are only used in the target environment.";
};
target = lib.options.create {
type = lib'.types.dependencies;
default.value = {};
description = "Dependencies which are run in the target environment.";
};
};
};
versions = lib.options.create {
type = lib.types.attrs.of lib'.types.package;
default.value = {};
description = "Available versions of the package.";
};
};
});
targeted = lib.types.submodule ({config}: {
freeform = lib.types.any;
options = {
name = lib.options.create {
type = lib.types.string;
default = {
value = "${config.pname}-${config.version or "unknown"}";
text = "\${config.pname}-\${config.version}";
};
description = "The name of the package.";
};
pname = lib.options.create {
type = lib.types.nullish lib.types.string;
default.value = null;
description = "The name of the package.";
};
version = lib.options.create {
type = lib.types.nullish lib.types.string;
default.value = null;
description = "The version of the package.";
};
meta = lib.options.create {
type = lib'.types.meta;
default = {
text = "{ name = <package>.pname; }";
value = {
name = config.pname;
};
};
description = "The metadata for the package.";
};
env = lib.options.create {
type = lib.types.attrs.of lib.types.string;
default.value = {};
description = "Environment variables for the package's builder to use.";
};
phases = lib.options.create {
type = lib.types.dag.of (
lib.types.either
lib.types.string
(lib.types.function lib.types.string)
);
default.value = {};
description = "Phases for the package's builder to use.";
};
platform = {
build = lib.options.create {
type = lib.types.string;
description = "The platform the package is built on.";
}; };
host = lib.options.create { host = lib.options.create {
type = lib'.types.dependencies; type = lib.types.string;
default.value = {}; description = "The platform the package is run on.";
description = "Dependencies which are run in the host environment.";
}; };
target = lib.options.create { target = lib.options.create {
type = lib'.types.dependencies; type = lib.types.string;
default.value = {}; description = "The platform the package generates code for.";
description = "Dependencies which are run in the host environment which produces code for the target environment.";
}; };
}; };
target = { builder = lib.options.create {
only = lib.options.create { type = lib'.types.builder;
type = lib'.types.dependencies; description = "The builder for the package.";
default.value = {}; };
description = "Dependencies which are only used in the target environment.";
package = lib.options.create {
type = lib.types.derivation;
default = {
value = config.builder.build config.builder config;
text = "<derivation>";
};
description = "The package derivation.";
};
deps = {
build = {
only = lib.options.create {
type = lib'.types.dependencies;
default.value = {};
description = "Dependencies which are only used in the build environment.";
};
build = lib.options.create {
type = lib'.types.dependencies;
default.value = {};
description = "Dependencies which are created in the build environment and are run in the build environment.";
};
host = lib.options.create {
type = lib'.types.dependencies;
default.value = {};
description = "Dependencies which are created in the build environment and are run in the host environment.";
};
target = lib.options.create {
type = lib'.types.dependencies;
default.value = {};
description = "Dependencies which are created in the build environment and are run in the target environment.";
};
}; };
target = lib.options.create { host = {
type = lib'.types.dependencies; only = lib.options.create {
default.value = {}; type = lib'.types.dependencies;
description = "Dependencies which are run in the target environment."; default.value = {};
description = "Dependencies which are only used in the host environment.";
};
host = lib.options.create {
type = lib'.types.dependencies;
default.value = {};
description = "Dependencies which are run in the host environment.";
};
target = lib.options.create {
type = lib'.types.dependencies;
default.value = {};
description = "Dependencies which are run in the host environment which produces code for the target environment.";
};
};
target = {
only = lib.options.create {
type = lib'.types.dependencies;
default.value = {};
description = "Dependencies which are only used in the target environment.";
};
target = lib.options.create {
type = lib'.types.dependencies;
default.value = {};
description = "Dependencies which are run in the target environment.";
};
}; };
}; };
};
versions = lib.options.create { versions = lib.options.create {
type = lib.types.attrs.of lib'.types.package; type = lib.types.attrs.of lib'.types.package;
default.value = {}; default.value = {};
description = "Available versions of the package."; description = "Available versions of the package.";
};
}; };
}; });
}); };
dependencies = lib.types.attrs.of (lib.types.nullish lib'.types.package); dependencies = lib.types.attrs.of (lib.types.nullish lib'.types.package);
packages = lib.types.attrs.of (lib.types.submodule { packages = {
freeform = lib.types.nullish lib'.types.package; base = lib.types.attrs.of (lib.types.submodule {
}); freeform = lib'.types.package.base;
# options =
# builtins.foldl' (result: system: {
# "${system}" = lib.options.create {
# type = lib'.types.packages.targeted;
# default.value = {};
# description = "Packages for the architecture `${system}`";
# };
# }) {}
# lib'.systems.doubles.all;
});
targeted = lib.types.attrs.of (lib.types.submodule {
freeform = lib.types.nullish lib'.types.package.targeted;
options = {
cross = lib.options.create {
type = lib'.types.packages.cross;
default.value = {};
description = "Cross-compiled packages targeting another architecture.";
};
};
});
# Cross-compiled packages are accessed via
# packages.cross.<platform>.<namespace>.<name>
cross = lib.types.attrs.of (lib.types.submodule {
freeform = lib.types.attrs.of (lib.types.submodule {
freeform = lib.types.nullish lib'.types.package.targeted;
});
});
};
builder = lib.types.submodule { builder = lib.types.submodule {
freeform = lib.types.any; freeform = lib.types.any;

View file

@ -1,4 +1,5 @@
{ {
exports = ./exports; exports = ./exports;
lib = ./lib; lib = ./lib;
packages = ./packages;
} }

View file

@ -3,19 +3,10 @@
config, config,
}: let }: let
lib' = config.lib; lib' = config.lib;
# configure = namespace: packages:
# builtins.mapAttrs doubles = lib'.systems.doubles.all;
# (key: package: let
# name = generic = builtins.removeAttrs config.packages ["targeted"];
# if package.pname != null && package.version != null
# then "${package.pname}-${package.version}"
# else key;
# in {
# name = lib.modules.overrides.default name;
# package = lib.modules.overrides.default (package.builder package);
# })
# packages;
# configs = builtins.mapAttrs configure config.packages;
in { in {
includes = [ includes = [
# ./aux/foundation.nix # ./aux/foundation.nix
@ -23,9 +14,14 @@ in {
options = { options = {
packages = lib.options.create { packages = lib.options.create {
type = lib'.types.packages; default.value = {};
type = lib.types.attrs.of (lib.types.submodule {
freeform = lib.types.any;
});
}; };
}; };
# config = lib.modules.merge configs; config = {
packages.targeted.i686-linux = generic;
};
} }