wip: working single dependency reference via coercion

This commit is contained in:
Jake Hamilton 2024-06-24 10:51:25 -07:00
parent 8233d4aedf
commit 0f602b1cb7
Signed by: jakehamilton
GPG key ID: 9762169A1B35EA68
12 changed files with 1297 additions and 1120 deletions

View file

@ -3,10 +3,10 @@
"lib": { "lib": {
"locked": { "locked": {
"dir": "lib", "dir": "lib",
"dirtyRev": "9850da8aa9dc9be22e237c9b424a18e801e53ecb-dirty", "dirtyRev": "a707b0f06be6b36bcbfe88d0a9a5b9a803983a06-dirty",
"dirtyShortRev": "9850da8-dirty", "dirtyShortRev": "a707b0f-dirty",
"lastModified": 1718529861, "lastModified": 1719079124,
"narHash": "sha256-tv/0C7ixH+9Ij+r+5nua48OlXXXnbdEsnenxX4eG/Sk=", "narHash": "sha256-4HwA3q5f7SUBmcXX9Vz9WsA9oHBQ/GiZTwE4iSVq9s8=",
"type": "git", "type": "git",
"url": "file:../?dir=lib" "url": "file:../?dir=lib"
}, },

File diff suppressed because it is too large Load diff

View file

@ -8,10 +8,10 @@
}, },
"locked": { "locked": {
"dir": "foundation", "dir": "foundation",
"dirtyRev": "9850da8aa9dc9be22e237c9b424a18e801e53ecb-dirty", "dirtyRev": "a707b0f06be6b36bcbfe88d0a9a5b9a803983a06-dirty",
"dirtyShortRev": "9850da8-dirty", "dirtyShortRev": "a707b0f-dirty",
"lastModified": 1718529861, "lastModified": 1719079124,
"narHash": "sha256-X1Wd6mDz8GTaoxt1ylkvZfrJOcZtspJrEjXMtJ2ZyG0=", "narHash": "sha256-hz9vVcHSvlq/W01UOh/GqPFUoH9DzCFB16n23oj7fnQ=",
"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": "9850da8aa9dc9be22e237c9b424a18e801e53ecb-dirty", "dirtyRev": "a707b0f06be6b36bcbfe88d0a9a5b9a803983a06-dirty",
"dirtyShortRev": "9850da8-dirty", "dirtyShortRev": "a707b0f-dirty",
"lastModified": 1718529861, "lastModified": 1719079124,
"narHash": "sha256-X1Wd6mDz8GTaoxt1ylkvZfrJOcZtspJrEjXMtJ2ZyG0=", "narHash": "sha256-hz9vVcHSvlq/W01UOh/GqPFUoH9DzCFB16n23oj7fnQ=",
"type": "git", "type": "git",
"url": "file:../?dir=lib" "url": "file:../?dir=lib"
}, },

View file

@ -1,25 +1,39 @@
{ lib, config }: {
let lib,
config,
}: let
cfg = config.builders.basic; cfg = config.builders.basic;
lib' = config.lib; lib' = config.lib;
inherit (config) foundation; inherit (config) foundation;
in in {
{
config.builders = { config.builders = {
basic = { basic = {
executable = "${foundation.stage2-bash}/bin/bash"; executable = "${foundation.stage2-bash}/bin/bash";
build = build = package: let
package: phases = lib.dag.apply.defaults package.phases {
let unpack = lib.dag.entry.before ["patch"] "";
phases = package.phases;
sorted = lib.dag.sort.topological phases;
script = lib.strings.concatMapSep "\n" ( patch = lib.dag.entry.between ["configure"] ["unpack"] "";
entry: if builtins.isFunction entry.value then entry.value package else entry.value
) sorted.result; configure = lib.dag.entry.between ["build"] ["patch"] "";
build = lib.dag.entry.between ["install"] ["configure"] "";
install = lib.dag.entry.after ["build"] "";
};
sorted = lib.dag.sort.topographic phases;
script =
lib.strings.concatMapSep "\n" (
entry:
if builtins.isFunction entry.value
then entry.value package
else entry.value
)
sorted.result;
system = package.platform.build.double; system = package.platform.build.double;
@ -33,8 +47,7 @@ in
SHELL = cfg.executable; SHELL = cfg.executable;
PATH = PATH = let
let
bins = lib.paths.bin ( bins = lib.paths.bin (
(lib'.packages.dependencies.getPackages package.deps.build.host) (lib'.packages.dependencies.getPackages package.deps.build.host)
++ [ ++ [

View file

@ -1,10 +1,11 @@
# 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.
{ lib, config }:
let
lib' = config.lib;
in
{ {
lib,
config,
}: let
lib' = config.lib;
in {
freeform = lib.types.any; freeform = lib.types.any;
config = { config = {
@ -13,6 +14,8 @@ in
modules = import ./modules.nix; modules = import ./modules.nix;
packages = { packages = {
aux-a = config.packages.aux.a;
# foundation-gcc-x86_64 = # foundation-gcc-x86_64 =
# (config.packages.foundation.gcc.versions."13.2.0".extend (args: { # (config.packages.foundation.gcc.versions."13.2.0".extend (args: {
# config = { # config = {
@ -22,11 +25,11 @@ 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";
}; # };
# example-x = config.packages.example.x; # example-x = config.packages.example.x;
# cross-example-x-x86_64-linux = config.packages.cross.x86_64-linux.example.x; # cross-example-x-x86_64-linux = config.packages.cross.x86_64-linux.example.x;
}; };

View file

@ -1,11 +1,12 @@
{ lib, config }:
let
in
{ {
lib,
config,
}: let
in {
config = { config = {
lib.options = { lib.options = {
package = lib.options.create { package = lib.options.create {
type = config.lib.types.package; type = config.lib.types.package.base;
description = "A package definition."; description = "A package definition.";
}; };
}; };

View file

@ -2,14 +2,11 @@
lib, lib,
lib', lib',
config, config,
}: }: {
{
config = { config = {
lib.packages = { lib.packages = {
dependencies = { dependencies = {
getPackages = getPackages = dependencies: let
dependencies:
let
available = builtins.filter (dependency: !(builtins.isNull dependency)) ( available = builtins.filter (dependency: !(builtins.isNull dependency)) (
builtins.attrValues dependencies builtins.attrValues dependencies
); );
@ -17,31 +14,27 @@
builtins.map (dependency: dependency.package) available; builtins.map (dependency: dependency.package) available;
}; };
getLatest = getLatest = alias: let
alias:
let
versions = builtins.attrNames alias.versions; versions = builtins.attrNames alias.versions;
sorted = builtins.sort (lib.versions.gte) versions; sorted = builtins.sort (lib.versions.gte) versions;
in in
builtins.head sorted; builtins.head sorted;
build = resolve = package:
package: build: host: target: if package ? versions
let then
resolved =
if package ? versions then
package.versions.${config.preferences.packages.version} package.versions.${config.preferences.packages.version}
or (package.versions.${lib'.packages.getLatest package}) or (package.versions.${lib'.packages.getLatest package})
else else package;
package;
buildDependencies = build = package: build: host: target: let
build': host': target': resolved = lib'.packages.resolve package;
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 = resolved.extend (
{ config }: {config}: {
{
config = { config = {
platform = { platform = {
build = build; build = build;

View file

@ -2,15 +2,12 @@
lib, lib,
lib', lib',
config, config,
}: }: {
{
config = { config = {
lib.types = { lib.types = {
license = license = let
let
type = lib.types.submodule ( type = lib.types.submodule (
{ config }: {config}: {
{
options = { options = {
name = { name = {
full = lib.options.create { full = lib.options.create {
@ -73,28 +70,160 @@
options = { options = {
versions = lib.options.create { versions = lib.options.create {
description = "All available package versions."; description = "All available package versions.";
type = lib.types.attrs.of lib'.types.package; type = lib.types.attrs.of lib'.types.package.base;
}; };
}; };
} }
); );
dependencies = lib.types.attrs.of ( dependencies = lib.types.attrs.of (
lib.types.nullish (lib.types.either lib'.types.alias lib'.types.package) lib.types.nullish (lib'.types.package.resolved)
); );
package = lib.types.submodule ( package = {
{ config, meta }: resolved = let
initial =
lib.types.raw
// {
check = value:
!(value ? __merged__)
&& lib.types.raw.check
value;
};
transform = value: let
package = lib'.packages.resolve value;
packageSubmodule = package.extend (args: {
options.__export__ = lib.options.create {
type = lib.types.raw;
default.value = {
inherit (args) options config;
};
};
config.__export__ = {
inherit (args) options config;
};
});
type = lib'.types.package.base.withSubModules (lib'.types.package.base.getSubModules
++ [
(args: {
options.__export__ = lib.options.create {
type = lib.types.raw;
default.value = {
inherit (args) options config;
};
};
config.__export__ = {
inherit (args) options config;
};
})
]);
typeSubmodule = lib.modules.run {
modules = type.getSubModules;
args = type.functor.payload.args;
};
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
# (builtins.trace (builtins.deepSeq packageOptionsIds packageOptionsIds))
# (builtins.trace (builtins.deepSeq typeOptionsIds typeOptionsIds))
# (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 =
resolvedOptions
// {
__merged__ = lib.options.create {
type = lib.types.bool;
default.value = true;
};
};
config =
builtins.removeAttrs package ["extend" "package" "platform"]
// {
platform = {
build = lib.modules.overrides.default package.platform.build.triple;
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
lib.types.coerce initial transform lib'.types.package.base;
base = lib.types.submodule (
{
config,
meta,
}: {
options = { options = {
extend = lib.options.create { extend = lib.options.create {
description = "Extend the package's submodules with additional configuration."; description = "Extend the package's submodules with additional configuration.";
type = lib.types.function lib.types.raw; type = lib.types.function lib.types.raw;
default.value = default.value = value: let
value:
let
result = meta.extend { result = meta.extend {
modules = if builtins.isAttrs value then [ { config = value; } ] else lib.lists.from.any value; modules =
if builtins.isAttrs value
then [{config = value;}]
else lib.lists.from.any value;
}; };
in in
result.config; result.config;
@ -106,7 +235,9 @@
default = { default = {
text = "\${config.pname}-\${config.version}"; text = "\${config.pname}-\${config.version}";
value = value =
if config.pname != null && config.version != null then "${config.pname}-${config.version}" else ""; if config.pname != null && config.version != null
then "${config.pname}-${config.version}"
else "";
}; };
}; };
@ -177,9 +308,7 @@
description = "The build platform for the package."; description = "The build platform for the package.";
type = lib.types.string; type = lib.types.string;
default.value = "x86_64-linux"; default.value = "x86_64-linux";
apply = apply = raw: let
raw:
let
system = lib'.systems.from.string raw; system = lib'.systems.from.string raw;
x = lib'.systems.withBuildInfo raw; x = lib'.systems.withBuildInfo raw;
in in
@ -198,9 +327,7 @@
# double = lib'.systems.into.double system; # double = lib'.systems.into.double system;
# triple = lib'.systems.into.triple system; # triple = lib'.systems.into.triple system;
# }; # };
apply = apply = raw: let
raw:
let
system = lib'.systems.from.string raw; system = lib'.systems.from.string raw;
x = lib'.systems.withBuildInfo raw; x = lib'.systems.withBuildInfo raw;
in in
@ -219,9 +346,7 @@
# double = lib'.systems.into.double system; # double = lib'.systems.into.double system;
# triple = lib'.systems.into.triple system; # triple = lib'.systems.into.triple system;
# }; # };
apply = apply = raw: let
raw:
let
system = lib'.systems.from.string raw; system = lib'.systems.from.string raw;
x = lib'.systems.withBuildInfo raw; x = lib'.systems.withBuildInfo raw;
in in
@ -318,4 +443,5 @@
); );
}; };
}; };
};
} }

View file

@ -0,0 +1,33 @@
{
lib',
config,
}: let
inherit (config) builders packages;
in {
config.packages.aux.a = {
versions = {
"latest" = {config}: {
config = {
meta = {
platforms = ["i686-linux"];
};
pname = "a";
version = "1.0.0";
builder = builders.basic;
deps.build.host = {
inherit (packages.aux) b;
};
phases = {
install = ''
echo "a" > $out
'';
};
};
};
};
};
}

View file

@ -0,0 +1,37 @@
{
lib',
config,
}: let
inherit (config) builders packages;
in {
config.packages.aux.b = {
versions = {
"latest" = {config}: {
options = {
custom = lib'.options.create {
type = lib'.types.bool;
};
};
config = {
meta = {
platforms = ["i686-linux"];
};
custom = true;
pname = "b";
version = "1.0.0";
builder = builders.basic;
phases = {
install = ''
echo "b" > $out
'';
};
};
};
};
};
}

View file

@ -2,14 +2,16 @@
lib, lib,
lib', lib',
config, config,
}: }: let
let
doubles = lib'.systems.doubles.all; doubles = lib'.systems.doubles.all;
packages = builtins.removeAttrs config.packages ["cross"]; packages = builtins.removeAttrs config.packages ["cross"];
in in {
{ includes = [
includes = [ ./foundation ]; ./foundation
./aux/a.nix
./aux/b.nix
];
options = { options = {
packages = lib.options.create { packages = lib.options.create {
@ -45,14 +47,12 @@ in
builtins.mapAttrs ( builtins.mapAttrs (
namespace: namespace:
builtins.mapAttrs ( builtins.mapAttrs (
name: alias: name: alias: let
let setHost = package:
setHost = if package != {}
package: then
if package != { } then
(package.extend ( (package.extend (
{ config }: {config}: {
{
config = { config = {
platform = { platform = {
host = lib.modules.overrides.force system; host = lib.modules.overrides.force system;
@ -78,16 +78,19 @@ in
}; };
}; };
} }
)).config ))
else .config
package; else package;
updated = alias // { updated =
alias
// {
versions = builtins.mapAttrs (version: package: setHost package) alias.versions; versions = builtins.mapAttrs (version: package: setHost package) alias.versions;
}; };
in in
updated updated
) )
) packages )
packages
); );
} }

View file

@ -3,22 +3,20 @@
lib', lib',
config, config,
options, options,
}: }: let
let inherit
inherit (config) (config)
mirrors mirrors
builders builders
# These are the upstream foundational packages exported from the Aux Foundation project. # These are the upstream foundational packages exported from the Aux Foundation project.
foundation foundation
packages
; ;
in in {
{
config.packages.foundation.binutils = { config.packages.foundation.binutils = {
versions = { versions = {
"latest" = "latest" = {config}: {
{ config, meta }:
{
options = { options = {
src = lib.options.create { src = lib.options.create {
type = lib.types.derivation; type = lib.types.derivation;
@ -36,9 +34,17 @@ in
builder = builders.basic; builder = builders.basic;
# deps = {
# build = {
# host = {
# inherit (packages.foundation) gcc;
# };
# };
# };
env = { env = {
PATH = lib.paths.bin [ PATH = lib.paths.bin [
foundation.stage2-gcc # foundation.stage2-gcc
foundation.stage2-binutils foundation.stage2-binutils
foundation.stage2-gnumake foundation.stage2-gnumake
foundation.stage2-gnupatch foundation.stage2-gnupatch
@ -52,8 +58,7 @@ in
]; ];
}; };
phases = phases = let
let
patches = [ patches = [
# Make binutils output deterministic by default. # Make binutils output deterministic by default.
./patches/deterministic.patch ./patches/deterministic.patch
@ -84,8 +89,7 @@ in
"--disable-multilib" "--disable-multilib"
]; ];
in in {
{
unpack = lib.dag.entry.before ["patch"] '' unpack = lib.dag.entry.before ["patch"] ''
tar xf ${config.src} tar xf ${config.src}
cd binutils-${config.version} cd binutils-${config.version}