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

File diff suppressed because it is too large Load diff

View file

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

View file

@ -1,25 +1,39 @@
{ lib, config }:
let
{
lib,
config,
}: let
cfg = config.builders.basic;
lib' = config.lib;
inherit (config) foundation;
in
{
in {
config.builders = {
basic = {
executable = "${foundation.stage2-bash}/bin/bash";
build =
package:
let
phases = package.phases;
sorted = lib.dag.sort.topological phases;
build = package: let
phases = lib.dag.apply.defaults package.phases {
unpack = lib.dag.entry.before ["patch"] "";
script = lib.strings.concatMapSep "\n" (
entry: if builtins.isFunction entry.value then entry.value package else entry.value
) sorted.result;
patch = lib.dag.entry.between ["configure"] ["unpack"] "";
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;
@ -33,8 +47,7 @@ in
SHELL = cfg.executable;
PATH =
let
PATH = let
bins = lib.paths.bin (
(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
# exported itself.
{ lib, config }:
let
lib' = config.lib;
in
{
lib,
config,
}: let
lib' = config.lib;
in {
freeform = lib.types.any;
config = {
@ -13,6 +14,8 @@ in
modules = import ./modules.nix;
packages = {
aux-a = config.packages.aux.a;
# foundation-gcc-x86_64 =
# (config.packages.foundation.gcc.versions."13.2.0".extend (args: {
# config = {
@ -22,11 +25,11 @@ in
# };
# }))
# .config;
foundation-gcc = config.packages.foundation.gcc;
foundation-binutils = config.packages.foundation.binutils;
foundation-linux-headers = config.packages.foundation.linux-headers.versions.latest.extend {
platform.host = lib.modules.overrides.force "x86_64-linux";
};
# foundation-gcc = config.packages.foundation.gcc;
# foundation-binutils = config.packages.foundation.binutils;
# foundation-linux-headers = config.packages.foundation.linux-headers.versions.latest.extend {
# platform.host = lib.modules.overrides.force "x86_64-linux";
# };
# example-x = config.packages.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 = {
lib.options = {
package = lib.options.create {
type = config.lib.types.package;
type = config.lib.types.package.base;
description = "A package definition.";
};
};

View file

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

View file

@ -2,15 +2,12 @@
lib,
lib',
config,
}:
{
}: {
config = {
lib.types = {
license =
let
license = let
type = lib.types.submodule (
{ config }:
{
{config}: {
options = {
name = {
full = lib.options.create {
@ -73,28 +70,160 @@
options = {
versions = lib.options.create {
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 (
lib.types.nullish (lib.types.either lib'.types.alias lib'.types.package)
lib.types.nullish (lib'.types.package.resolved)
);
package = lib.types.submodule (
{ config, meta }:
package = {
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 = {
extend = lib.options.create {
description = "Extend the package's submodules with additional configuration.";
type = lib.types.function lib.types.raw;
default.value =
value:
let
default.value = value: let
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
result.config;
@ -106,7 +235,9 @@
default = {
text = "\${config.pname}-\${config.version}";
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.";
type = lib.types.string;
default.value = "x86_64-linux";
apply =
raw:
let
apply = raw: let
system = lib'.systems.from.string raw;
x = lib'.systems.withBuildInfo raw;
in
@ -198,9 +327,7 @@
# double = lib'.systems.into.double system;
# triple = lib'.systems.into.triple system;
# };
apply =
raw:
let
apply = raw: let
system = lib'.systems.from.string raw;
x = lib'.systems.withBuildInfo raw;
in
@ -219,9 +346,7 @@
# double = lib'.systems.into.double system;
# triple = lib'.systems.into.triple system;
# };
apply =
raw:
let
apply = raw: let
system = lib'.systems.from.string raw;
x = lib'.systems.withBuildInfo raw;
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',
config,
}:
let
}: let
doubles = lib'.systems.doubles.all;
packages = builtins.removeAttrs config.packages ["cross"];
in
{
includes = [ ./foundation ];
in {
includes = [
./foundation
./aux/a.nix
./aux/b.nix
];
options = {
packages = lib.options.create {
@ -45,14 +47,12 @@ in
builtins.mapAttrs (
namespace:
builtins.mapAttrs (
name: alias:
let
setHost =
package:
if package != { } then
name: alias: let
setHost = package:
if package != {}
then
(package.extend (
{ config }:
{
{config}: {
config = {
platform = {
host = lib.modules.overrides.force system;
@ -78,16 +78,19 @@ in
};
};
}
)).config
else
package;
))
.config
else package;
updated = alias // {
updated =
alias
// {
versions = builtins.mapAttrs (version: package: setHost package) alias.versions;
};
in
updated
)
) packages
)
packages
);
}

View file

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