wip: working single dependency reference via coercion

This commit is contained in:
Jake Hamilton 2024-06-24 10:51:25 -07:00
parent a707b0f06b
commit 2be3111b2c
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,76 +1,89 @@
{ 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.topographic 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;
system = package.platform.build.double; configure = lib.dag.entry.between ["build"] ["patch"] "";
built = builtins.derivation ( build = lib.dag.entry.between ["install"] ["configure"] "";
package.env
// {
inherit (package) name;
inherit script system;
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 = system = package.platform.build.double;
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; built = builtins.derivation (
package.env
// {
inherit (package) name;
inherit script system;
args = [ passAsFile = ["script"];
"-e"
(builtins.toFile "bash-builder.sh" ''
export CONFIG_SHELL=$SHELL
# Normalize the NIX_BUILD_CORES variable. The value might be 0, which SHELL = cfg.executable;
# 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 PATH = let
'') bins = lib.paths.bin (
]; (lib'.packages.dependencies.getPackages package.deps.build.host)
} ++ [
); foundation.stage2-bash
in foundation.stage2-coreutils
built // { inherit (package) meta; }; ]
);
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 # 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,76 +2,69 @@
lib, lib,
lib', lib',
config, config,
}: }: {
{
config = { config = {
lib.packages = { lib.packages = {
dependencies = { dependencies = {
getPackages = getPackages = dependencies: let
dependencies: available = builtins.filter (dependency: !(builtins.isNull dependency)) (
let builtins.attrValues dependencies
available = builtins.filter (dependency: !(builtins.isNull dependency)) ( );
builtins.attrValues dependencies in
);
in
builtins.map (dependency: dependency.package) available; builtins.map (dependency: dependency.package) available;
}; };
getLatest = getLatest = alias: let
alias: versions = builtins.attrNames alias.versions;
let sorted = builtins.sort (lib.versions.gte) versions;
versions = builtins.attrNames alias.versions; in
sorted = builtins.sort (lib.versions.gte) versions;
in
builtins.head sorted; builtins.head sorted;
build = resolve = package:
package: build: host: target: if package ? versions
let then
resolved = package.versions.${config.preferences.packages.version}
if package ? versions then or (package.versions.${lib'.packages.getLatest package})
package.versions.${config.preferences.packages.version} else package;
or (package.versions.${lib'.packages.getLatest package})
else
package;
buildDependencies = build = package: build: host: target: let
build': host': target': resolved = lib'.packages.resolve package;
builtins.mapAttrs (name: dep: lib'.packages.build dep build' host' target');
result = resolved.extend ( buildDependencies = build': host': target':
{ config }: builtins.mapAttrs (name: dep: lib'.packages.build dep build' host' target');
{
config = {
platform = {
build = build;
host = host;
target = lib.modules.override 150 target;
};
deps = { result = resolved.extend (
build = { {config}: {
only = buildDependencies build build build resolved.deps.build.only; config = {
build = buildDependencies build build target resolved.deps.build.build; platform = {
host = buildDependencies build host target resolved.deps.build.host; build = build;
target = buildDependencies build target target resolved.deps.build.target; host = host;
}; target = lib.modules.override 150 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;
}; };
}
); deps = {
in 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; result;
}; };
}; };

View file

@ -2,57 +2,54 @@
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 = {
{ name = {
options = { full = lib.options.create {
name = { description = "The full name of the license.";
full = lib.options.create { type = lib.types.string;
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;
};
}; };
spdx = lib.options.create { short = lib.options.create {
description = "The SPDX identifier for the license."; description = "The short name of the license.";
type = lib.types.nullish lib.types.string; type = 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;
};
}; };
}; };
}
); spdx = lib.options.create {
in 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); lib.types.either type (lib.types.list.of type);
builder = lib.types.submodule { builder = lib.types.submodule {
@ -73,249 +70,378 @@
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 =
options = { lib.types.raw
extend = lib.options.create { // {
description = "Extend the package's submodules with additional configuration."; check = value:
type = lib.types.function lib.types.raw; !(value ? __merged__)
default.value = && lib.types.raw.check
value: value;
let };
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 { 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;
};
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 { name = lib.options.create {
description = "The program name for the package"; description = "The name of the package.";
type = lib.types.nullish lib.types.string; type = lib.types.string;
default.value = null; default = {
}; text = "\${config.pname}-\${config.version}";
value =
if config.pname != null && config.version != null
then "${config.pname}-${config.version}"
else "";
};
};
version = lib.options.create { pname = lib.options.create {
description = "The version for the package."; description = "The program name for the package";
type = lib.types.nullish lib.types.version;
default.value = null;
};
meta = {
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;
}; };
homepage = lib.options.create { version = lib.options.create {
description = "The homepage for the package."; description = "The version for the package.";
type = lib.types.nullish lib.types.string; type = lib.types.nullish lib.types.version;
default.value = null; default.value = null;
}; };
license = lib.options.create { meta = {
description = "The license for the package."; description = lib.options.create {
type = lib.types.nullish lib'.types.license; description = "The description for the package.";
default.value = null; type = lib.types.nullish lib.types.string;
}; 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 = { };
}; };
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 { build = lib.options.create {
description = "Dependencies which are created in the build environment and are executed in the build environment."; description = "The build platform for the package.";
type = lib'.types.dependencies; type = lib.types.string;
default.value = { }; 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 { host = lib.options.create {
description = "Dependencies which are created in the build environment and are executed in the host environment."; description = "The host platform for the package.";
type = lib'.types.dependencies; type = lib.types.string;
default.value = { }; 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 { target = lib.options.create {
description = "Dependencies which are created in the build environment and are executed in the target environment."; description = "The target platform for the package.";
type = lib'.types.dependencies; type = lib.types.string;
default.value = { }; 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 = { phases = lib.options.create {
only = lib.options.create { description = "The phases for the package.";
description = "Dependencies which are only used in the host environment."; type = lib.types.dag.of (lib.types.either lib.types.string (lib.types.function lib.types.string));
type = lib'.types.dependencies; default.value = {};
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 { host = {
description = "Dependencies which are executed in the host environment."; only = lib.options.create {
type = lib'.types.dependencies; description = "Dependencies which are only used in the host environment.";
default.value = { }; 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 { target = {
description = "Dependencies which are executed in the host environment which produces code for the target environment."; only = lib.options.create {
type = lib'.types.dependencies; description = "Dependencies which are only used in the target environment.";
default.value = { }; 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 = { package = lib.options.create {
only = lib.options.create { description = "The built derivation.";
description = "Dependencies which are only used in the target environment."; type = lib.types.derivation;
type = lib'.types.dependencies; default.value = config.builder.build config;
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;
};
};
}
);
}; };
}; };
} }

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,
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 {
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.attrs.of (lib.types.submodule {freeform = lib'.types.alias;});
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 = {};
} }
); );
}; };
}; };
@ -42,52 +44,53 @@ in
config.packages.cross = lib.attrs.generate doubles ( config.packages.cross = lib.attrs.generate doubles (
system: system:
builtins.mapAttrs (
namespace:
builtins.mapAttrs ( builtins.mapAttrs (
name: alias: namespace:
let builtins.mapAttrs (
setHost = name: alias: let
package: setHost = package:
if package != { } then if package != {}
(package.extend ( then
{ config }: (package.extend (
{ {config}: {
config = { config = {
platform = { platform = {
host = lib.modules.overrides.force system; host = lib.modules.overrides.force system;
target = lib.modules.overrides.default 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 = {
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; .config
target = setHost package.deps.host.target; else package;
};
target = {
only = setHost package.deps.target.only;
target = setHost package.deps.target.target;
};
};
};
}
)).config
else
package;
updated = alias // { updated =
versions = builtins.mapAttrs (version: package: setHost package) alias.versions; alias
}; // {
in versions = builtins.mapAttrs (version: package: setHost package) alias.versions;
updated };
in
updated
)
) )
) packages packages
); );
} }

View file

@ -3,117 +3,121 @@
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 = {
{ src = lib.options.create {
options = { type = lib.types.derivation;
src = lib.options.create { description = "Source for the package.";
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=";
};
}; };
}; };
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=";
};
};
};
}; };
}; };
} }