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,76 +1,89 @@
{ 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"] "";
system = package.platform.build.double;
configure = lib.dag.entry.between ["build"] ["patch"] "";
built = builtins.derivation (
package.env
// {
inherit (package) name;
inherit script system;
build = lib.dag.entry.between ["install"] ["configure"] "";
passAsFile = [ "script" ];
install = lib.dag.entry.after ["build"] "";
};
sorted = lib.dag.sort.topographic phases;
SHELL = cfg.executable;
script =
lib.strings.concatMapSep "\n" (
entry:
if builtins.isFunction entry.value
then entry.value package
else entry.value
)
sorted.result;
PATH =
let
bins = lib.paths.bin (
(lib'.packages.dependencies.getPackages package.deps.build.host)
++ [
foundation.stage2-bash
foundation.stage2-coreutils
]
);
in
builtins.concatStringsSep ":" (
[ bins ] ++ (lib.lists.when (package.env ? PATH) [ package.env.PATH ])
);
system = package.platform.build.double;
builder = cfg.executable;
built = builtins.derivation (
package.env
// {
inherit (package) name;
inherit script system;
args = [
"-e"
(builtins.toFile "bash-builder.sh" ''
export CONFIG_SHELL=$SHELL
passAsFile = ["script"];
# Normalize the NIX_BUILD_CORES variable. The value might be 0, which
# means that we're supposed to try and auto-detect the number of
# available CPU cores at run-time.
NIX_BUILD_CORES="''${NIX_BUILD_CORES:-1}"
if ((NIX_BUILD_CORES <= 0)); then
guess=$(nproc 2>/dev/null || true)
((NIX_BUILD_CORES = guess <= 0 ? 1 : guess))
fi
export NIX_BUILD_CORES
SHELL = cfg.executable;
bash -eux $scriptPath
'')
];
}
);
in
built // { inherit (package) meta; };
PATH = let
bins = lib.paths.bin (
(lib'.packages.dependencies.getPackages package.deps.build.host)
++ [
foundation.stage2-bash
foundation.stage2-coreutils
]
);
in
builtins.concatStringsSep ":" (
[bins] ++ (lib.lists.when (package.env ? PATH) [package.env.PATH])
);
builder = cfg.executable;
args = [
"-e"
(builtins.toFile "bash-builder.sh" ''
export CONFIG_SHELL=$SHELL
# Normalize the NIX_BUILD_CORES variable. The value might be 0, which
# means that we're supposed to try and auto-detect the number of
# available CPU cores at run-time.
NIX_BUILD_CORES="''${NIX_BUILD_CORES:-1}"
if ((NIX_BUILD_CORES <= 0)); then
guess=$(nproc 2>/dev/null || true)
((NIX_BUILD_CORES = guess <= 0 ? 1 : guess))
fi
export NIX_BUILD_CORES
bash -eux $scriptPath
'')
];
}
);
in
built // {inherit (package) meta;};
};
};
}

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,76 +2,69 @@
lib,
lib',
config,
}:
{
}: {
config = {
lib.packages = {
dependencies = {
getPackages =
dependencies:
let
available = builtins.filter (dependency: !(builtins.isNull dependency)) (
builtins.attrValues dependencies
);
in
getPackages = dependencies: let
available = builtins.filter (dependency: !(builtins.isNull dependency)) (
builtins.attrValues dependencies
);
in
builtins.map (dependency: dependency.package) available;
};
getLatest =
alias:
let
versions = builtins.attrNames alias.versions;
sorted = builtins.sort (lib.versions.gte) versions;
in
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
package.versions.${config.preferences.packages.version}
or (package.versions.${lib'.packages.getLatest package})
else
package;
resolve = package:
if package ? versions
then
package.versions.${config.preferences.packages.version}
or (package.versions.${lib'.packages.getLatest package})
else package;
buildDependencies =
build': host': target':
builtins.mapAttrs (name: dep: lib'.packages.build dep build' host' target');
build = package: build: host: target: let
resolved = lib'.packages.resolve package;
result = resolved.extend (
{ config }:
{
config = {
platform = {
build = build;
host = host;
target = lib.modules.override 150 target;
};
buildDependencies = build': host': target':
builtins.mapAttrs (name: dep: lib'.packages.build dep build' host' target');
deps = {
build = {
only = buildDependencies build build build resolved.deps.build.only;
build = buildDependencies build build target resolved.deps.build.build;
host = buildDependencies build host target resolved.deps.build.host;
target = buildDependencies build target target resolved.deps.build.target;
};
host = {
only = buildDependencies host host host resolved.deps.host.only;
host = buildDependencies host host target resolved.deps.host.host;
target = buildDependencies host target target resolved.deps.host.target;
};
target = {
only = buildDependencies target target target resolved.deps.target.only;
target = buildDependencies target target target resolved.deps.target.target;
};
};
package = config.builder.build config;
result = resolved.extend (
{config}: {
config = {
platform = {
build = build;
host = host;
target = lib.modules.override 150 target;
};
}
);
in
deps = {
build = {
only = buildDependencies build build build resolved.deps.build.only;
build = buildDependencies build build target resolved.deps.build.build;
host = buildDependencies build host target resolved.deps.build.host;
target = buildDependencies build target target resolved.deps.build.target;
};
host = {
only = buildDependencies host host host resolved.deps.host.only;
host = buildDependencies host host target resolved.deps.host.host;
target = buildDependencies host target target resolved.deps.host.target;
};
target = {
only = buildDependencies target target target resolved.deps.target.only;
target = buildDependencies target target target resolved.deps.target.target;
};
};
package = config.builder.build config;
};
}
);
in
result;
};
};

View file

@ -2,57 +2,54 @@
lib,
lib',
config,
}:
{
}: {
config = {
lib.types = {
license =
let
type = lib.types.submodule (
{ config }:
{
options = {
name = {
full = lib.options.create {
description = "The full name of the license.";
type = lib.types.string;
};
short = lib.options.create {
description = "The short name of the license.";
type = lib.types.string;
};
license = let
type = lib.types.submodule (
{config}: {
options = {
name = {
full = lib.options.create {
description = "The full name of the license.";
type = lib.types.string;
};
spdx = lib.options.create {
description = "The SPDX identifier for the license.";
type = lib.types.nullish lib.types.string;
default.value = null;
};
url = lib.options.create {
description = "The URL for the license.";
type = lib.types.nullish lib.types.string;
};
free = lib.options.create {
description = "Whether the license is free.";
type = lib.types.bool;
default.value = true;
};
redistributable = lib.options.create {
description = "Whether the license is allows redistribution.";
type = lib.types.bool;
default = {
text = "config.free";
value = config.free;
};
short = lib.options.create {
description = "The short name of the license.";
type = lib.types.string;
};
};
}
);
in
spdx = lib.options.create {
description = "The SPDX identifier for the license.";
type = lib.types.nullish lib.types.string;
default.value = null;
};
url = lib.options.create {
description = "The URL for the license.";
type = lib.types.nullish lib.types.string;
};
free = lib.options.create {
description = "Whether the license is free.";
type = lib.types.bool;
default.value = true;
};
redistributable = lib.options.create {
description = "Whether the license is allows redistribution.";
type = lib.types.bool;
default = {
text = "config.free";
value = config.free;
};
};
};
}
);
in
lib.types.either type (lib.types.list.of type);
builder = lib.types.submodule {
@ -73,249 +70,378 @@
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 }:
{
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
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
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;
};
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 "";
result.config;
};
};
pname = lib.options.create {
description = "The program name for the package";
type = lib.types.nullish lib.types.string;
default.value = null;
};
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 "";
};
};
version = lib.options.create {
description = "The version for the package.";
type = lib.types.nullish lib.types.version;
default.value = null;
};
meta = {
description = lib.options.create {
description = "The description for the package.";
pname = lib.options.create {
description = "The program name for the package";
type = lib.types.nullish lib.types.string;
default.value = null;
};
homepage = lib.options.create {
description = "The homepage for the package.";
type = lib.types.nullish lib.types.string;
version = lib.options.create {
description = "The version for the package.";
type = lib.types.nullish lib.types.version;
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 = {
build = lib.options.create {
description = "The build platform for the package.";
type = lib.types.string;
default.value = "x86_64-linux";
apply =
raw:
let
system = lib'.systems.from.string raw;
x = lib'.systems.withBuildInfo raw;
in
x;
};
host = lib.options.create {
description = "The host platform for the package.";
type = lib.types.string;
default.value = "x86_64-linux";
# 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 {
description = "The target platform for the package.";
type = lib.types.string;
default.value = "x86_64-linux";
# 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 {
description = "The phases for the package.";
type = lib.types.dag.of (lib.types.either lib.types.string (lib.types.function 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 = { };
};
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 = { };
meta = {
description = lib.options.create {
description = "The description for the package.";
type = lib.types.nullish lib.types.string;
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 = {
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 = { };
description = "The build platform for the package.";
type = lib.types.string;
default.value = "x86_64-linux";
apply = raw: let
system = lib'.systems.from.string raw;
x = lib'.systems.withBuildInfo raw;
in
x;
};
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 = { };
description = "The host platform for the package.";
type = lib.types.string;
default.value = "x86_64-linux";
# 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 {
description = "Dependencies which are created in the build environment and are executed in the target environment.";
type = lib'.types.dependencies;
default.value = { };
description = "The target platform for the package.";
type = lib.types.string;
default.value = "x86_64-linux";
# 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;
};
};
host = {
only = lib.options.create {
description = "Dependencies which are only used in the host environment.";
type = lib'.types.dependencies;
default.value = { };
phases = lib.options.create {
description = "The phases for the package.";
type = lib.types.dag.of (lib.types.either lib.types.string (lib.types.function 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 = {};
};
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 = lib.options.create {
description = "Dependencies which are executed in the host environment.";
type = lib'.types.dependencies;
default.value = { };
host = {
only = lib.options.create {
description = "Dependencies which are only used in the host environment.";
type = lib'.types.dependencies;
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 = 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 = {
only = lib.options.create {
description = "Dependencies which are only used in the target environment.";
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 = {};
};
};
};
target = {
only = lib.options.create {
description = "Dependencies which are only used in the target environment.";
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 = { };
};
package = lib.options.create {
description = "The built derivation.";
type = lib.types.derivation;
default.value = config.builder.build config;
};
};
package = lib.options.create {
description = "The built derivation.";
type = lib.types.derivation;
default.value = config.builder.build config;
};
};
}
);
}
);
};
};
};
}

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,28 +2,30 @@
lib,
lib',
config,
}:
let
}: let
doubles = lib'.systems.doubles.all;
packages = builtins.removeAttrs config.packages [ "cross" ];
in
{
includes = [ ./foundation ];
packages = builtins.removeAttrs config.packages ["cross"];
in {
includes = [
./foundation
./aux/a.nix
./aux/b.nix
];
options = {
packages = lib.options.create {
description = "The package set.";
type = lib.types.submodule {
freeform = lib.types.attrs.of (lib.types.submodule { freeform = lib'.types.alias; });
freeform = lib.types.attrs.of (lib.types.submodule {freeform = lib'.types.alias;});
options.cross = lib.attrs.generate doubles (
system:
lib.options.create {
description = "The cross-compiled package set for the ${system} target.";
type = lib'.types.packages;
default = { };
}
lib.options.create {
description = "The cross-compiled package set for the ${system} target.";
type = lib'.types.packages;
default = {};
}
);
};
};
@ -42,52 +44,53 @@ in
config.packages.cross = lib.attrs.generate doubles (
system:
builtins.mapAttrs (
namespace:
builtins.mapAttrs (
name: alias:
let
setHost =
package:
if package != { } then
(package.extend (
{ config }:
{
config = {
platform = {
host = lib.modules.overrides.force system;
target = lib.modules.overrides.default system;
};
namespace:
builtins.mapAttrs (
name: alias: let
setHost = package:
if package != {}
then
(package.extend (
{config}: {
config = {
platform = {
host = lib.modules.overrides.force system;
target = lib.modules.overrides.default system;
};
deps = {
build = {
only = setHost package.deps.build.only;
build = setHost package.deps.build.build;
host = setHost package.deps.build.host;
target = setHost package.deps.build.target;
deps = {
build = {
only = setHost package.deps.build.only;
build = setHost package.deps.build.build;
host = setHost package.deps.build.host;
target = setHost package.deps.build.target;
};
host = {
only = setHost package.deps.host.only;
host = setHost package.deps.host.host;
target = setHost package.deps.host.target;
};
target = {
only = setHost package.deps.target.only;
target = setHost package.deps.target.target;
};
};
};
host = {
only = setHost package.deps.host.only;
host = setHost package.deps.host.host;
target = setHost package.deps.host.target;
};
target = {
only = setHost package.deps.target.only;
target = setHost package.deps.target.target;
};
};
};
}
)).config
else
package;
}
))
.config
else package;
updated = alias // {
versions = builtins.mapAttrs (version: package: setHost package) alias.versions;
};
in
updated
updated =
alias
// {
versions = builtins.mapAttrs (version: package: setHost package) alias.versions;
};
in
updated
)
)
) packages
packages
);
}

View file

@ -3,117 +3,121 @@
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 }:
{
options = {
src = lib.options.create {
type = lib.types.derivation;
description = "Source for the package.";
};
};
config = {
meta = {
platforms = [ "i686-linux" ];
};
pname = "binutils";
version = "2.41";
builder = builders.basic;
env = {
PATH = lib.paths.bin [
foundation.stage2-gcc
foundation.stage2-binutils
foundation.stage2-gnumake
foundation.stage2-gnupatch
foundation.stage2-gnused
foundation.stage2-gnugrep
foundation.stage2-gawk
foundation.stage2-diffutils
foundation.stage2-findutils
foundation.stage2-gnutar
foundation.stage1-xz
];
};
phases =
let
patches = [
# Make binutils output deterministic by default.
./patches/deterministic.patch
];
configureFlags = [
# "CC=musl-gcc"
"LDFLAGS=--static"
"--prefix=${builtins.placeholder "out"}"
"--build=${config.platform.build.triple}"
"--host=${config.platform.host.triple}"
"--target=${config.platform.target.triple}"
"--with-sysroot=/"
"--enable-deterministic-archives"
# depends on bison
"--disable-gprofng"
# Turn on --enable-new-dtags by default to make the linker set
# RUNPATH instead of RPATH on binaries. This is important because
# RUNPATH can be overridden using LD_LIBRARY_PATH at runtime.
"--enable-new-dtags"
# By default binutils searches $libdir for libraries. This brings in
# libbfd and libopcodes into a default visibility. Drop default lib
# path to force users to declare their use of these libraries.
"--with-lib-path=:"
"--disable-multilib"
];
in
{
unpack = lib.dag.entry.before [ "patch" ] ''
tar xf ${config.src}
cd binutils-${config.version}
'';
patch = lib.dag.entry.between [ "configure" ] [ "unpack" ] ''
${lib.strings.concatMapSep "\n" (file: "patch -Np1 -i ${file}") patches}
'';
configure = lib.dag.entry.between [ "build" ] [ "patch" ] ''
bash ./configure ${builtins.concatStringsSep " " configureFlags}
'';
build = lib.dag.entry.between [ "install" ] [ "configure" ] ''
make -j $NIX_BUILD_CORES
'';
install = lib.dag.entry.after [ "build" ] ''
make -j $NIX_BUILD_CORES install-strip
'';
};
src = builtins.fetchurl {
url = "${mirrors.gnu}/binutils/binutils-${config.version}.tar.xz";
sha256 = "rppXieI0WeWWBuZxRyPy0//DHAMXQZHvDQFb3wYAdFA=";
};
"latest" = {config}: {
options = {
src = lib.options.create {
type = lib.types.derivation;
description = "Source for the package.";
};
};
config = {
meta = {
platforms = ["i686-linux"];
};
pname = "binutils";
version = "2.41";
builder = builders.basic;
# deps = {
# build = {
# host = {
# inherit (packages.foundation) gcc;
# };
# };
# };
env = {
PATH = lib.paths.bin [
# foundation.stage2-gcc
foundation.stage2-binutils
foundation.stage2-gnumake
foundation.stage2-gnupatch
foundation.stage2-gnused
foundation.stage2-gnugrep
foundation.stage2-gawk
foundation.stage2-diffutils
foundation.stage2-findutils
foundation.stage2-gnutar
foundation.stage1-xz
];
};
phases = let
patches = [
# Make binutils output deterministic by default.
./patches/deterministic.patch
];
configureFlags = [
# "CC=musl-gcc"
"LDFLAGS=--static"
"--prefix=${builtins.placeholder "out"}"
"--build=${config.platform.build.triple}"
"--host=${config.platform.host.triple}"
"--target=${config.platform.target.triple}"
"--with-sysroot=/"
"--enable-deterministic-archives"
# depends on bison
"--disable-gprofng"
# Turn on --enable-new-dtags by default to make the linker set
# RUNPATH instead of RPATH on binaries. This is important because
# RUNPATH can be overridden using LD_LIBRARY_PATH at runtime.
"--enable-new-dtags"
# By default binutils searches $libdir for libraries. This brings in
# libbfd and libopcodes into a default visibility. Drop default lib
# path to force users to declare their use of these libraries.
"--with-lib-path=:"
"--disable-multilib"
];
in {
unpack = lib.dag.entry.before ["patch"] ''
tar xf ${config.src}
cd binutils-${config.version}
'';
patch = lib.dag.entry.between ["configure"] ["unpack"] ''
${lib.strings.concatMapSep "\n" (file: "patch -Np1 -i ${file}") patches}
'';
configure = lib.dag.entry.between ["build"] ["patch"] ''
bash ./configure ${builtins.concatStringsSep " " configureFlags}
'';
build = lib.dag.entry.between ["install"] ["configure"] ''
make -j $NIX_BUILD_CORES
'';
install = lib.dag.entry.after ["build"] ''
make -j $NIX_BUILD_CORES install-strip
'';
};
src = builtins.fetchurl {
url = "${mirrors.gnu}/binutils/binutils-${config.version}.tar.xz";
sha256 = "rppXieI0WeWWBuZxRyPy0//DHAMXQZHvDQFb3wYAdFA=";
};
};
};
};
};
}