chore: format code

This commit is contained in:
Jake Hamilton 2025-03-11 22:47:02 -07:00
parent a17ac0ff2b
commit 397419d8ab
Signed by: jakehamilton
GPG key ID: 9762169A1B35EA68
17 changed files with 511 additions and 501 deletions

6
.editorconfig Normal file
View file

@ -0,0 +1,6 @@
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8
indent_style = space
indent_size = 2

View file

@ -30,10 +30,12 @@ lib: {
process currentPath values
);
in
process [ ] [
x
y
];
process
[ ]
[
x
y
];
## Merge two attribute sets recursively. Any values that are _not_ attribute sets
## will be overridden with the value from `y` first if it exists and then `x`

View file

@ -75,10 +75,13 @@ in
"entries.between" =
let
expected = true;
graph = lib.dag.entries.between "example" [ ] [ ] [
null
null
];
graph =
lib.dag.entries.between "example" [ ]
[ ]
[
null
null
];
actual = lib.dag.validate.graph graph;
in
actual == expected;
@ -97,10 +100,13 @@ in
"entries.before" =
let
expected = true;
graph = lib.dag.entries.before "example" [ ] [
null
null
];
graph =
lib.dag.entries.before "example"
[ ]
[
null
null
];
actual = lib.dag.validate.graph graph;
in
actual == expected;
@ -108,10 +114,13 @@ in
"entries.after" =
let
expected = true;
graph = lib.dag.entries.after "example" [ ] [
null
null
];
graph =
lib.dag.entries.after "example"
[ ]
[
null
null
];
actual = lib.dag.validate.graph graph;
in
actual == expected;

View file

@ -56,10 +56,12 @@ let
if isSingleValue || isComplete then builtins.elemAt values 0 else process currentPath values
);
in
process [ ] [
x
y
];
process
[ ]
[
x
y
];
## Merge two attribute sets recursively. Any values that are _not_ attribute sets
## will be overridden with the value from `y` first if it exists and then `x`

View file

@ -299,13 +299,16 @@ in
}
];
};
actual = lib.modules.combine [ ] [
(lib.modules.normalize "/aux/example.nix" "example" {
config = {
x = 1;
};
})
];
actual =
lib.modules.combine
[ ]
[
(lib.modules.normalize "/aux/example.nix" "example" {
config = {
x = 1;
};
})
];
in
actual == expected;
@ -318,22 +321,25 @@ in
value = 2;
}
];
actual = lib.modules.combine [ ] [
(lib.modules.normalize "/aux/example1.nix" "example2" {
options = {
x = lib.options.create { };
};
actual =
lib.modules.combine
[ ]
[
(lib.modules.normalize "/aux/example1.nix" "example2" {
options = {
x = lib.options.create { };
};
config = {
x = 1;
};
})
(lib.modules.normalize "/aux/example2.nix" "example2" {
config = {
y = 2;
};
})
];
config = {
x = 1;
};
})
(lib.modules.normalize "/aux/example2.nix" "example2" {
config = {
y = 2;
};
})
];
in
(actual.unmatched == unmatched) && actual.matched ? x;
};

View file

@ -49,18 +49,18 @@ lib: {
##
## @type Attrs -> Attrs
create =
settings@{ name
, description ? name
, fallback ? { }
, check ? lib.fp.const true
, merge ? lib.options.merge.default
, functor ? lib.types.functor name
, mergeType ? lib.types.merge functor
, getSubOptions ? lib.fp.const { }
, getSubModules ? null
, withSubModules ? lib.fp.const null
, children ? { }
,
settings@{
name,
description ? name,
fallback ? { },
check ? lib.fp.const true,
merge ? lib.options.merge.default,
functor ? lib.types.functor name,
mergeType ? lib.types.merge functor,
getSubOptions ? lib.fp.const { },
getSubModules ? null,
withSubModules ? lib.fp.const null,
children ? { },
}:
{
__type__ = "type";
@ -118,16 +118,13 @@ lib: {
else
builtins.typeOf value;
commonType = builtins.foldl'
(
type: definition:
if getType definition.value != type then
builtins.throw "The option `${identifier}` has conflicting definitions in ${serializedFiles}"
else
type
)
(getType first.value)
definitions;
commonType = builtins.foldl' (
type: definition:
if getType definition.value != type then
builtins.throw "The option `${identifier}` has conflicting definitions in ${serializedFiles}"
else
type
) (getType first.value) definitions;
mergeStringifiableAttrs = lib.options.merge.one;
@ -143,12 +140,10 @@ lib: {
location: definitions: x:
let
resolvedLocation = location ++ [ "<function body>" ];
resolvedDefinitions = builtins.map
(definition: {
__file__ = definition.__file__;
value = definition.value x;
})
definitions;
resolvedDefinitions = builtins.map (definition: {
__file__ = definition.__file__;
value = definition.value x;
}) definitions;
in
lib.types.any.merge resolvedLocation resolvedDefinitions;
@ -205,15 +200,14 @@ lib: {
## @type Int -> Int -> Attrs
between =
start: end:
assert lib.errors.trace
(
start <= end
) "lib.types.ints.between start must be less than or equal to end";
lib.types.withCheck lib.types.int (value: value >= start && value <= end)
// {
name = "IntBetween";
description = "integer between ${description start end}";
};
assert lib.errors.trace (
start <= end
) "lib.types.ints.between start must be less than or equal to end";
lib.types.withCheck lib.types.int (value: value >= start && value <= end)
// {
name = "IntBetween";
description = "integer between ${description start end}";
};
## Create a type that allows an integer value between a given range with a specific
## number of bits.
@ -323,15 +317,14 @@ lib: {
## @type Int -> Int -> Attrs
between =
start: end:
assert lib.errors.trace
(
start <= end
) "lib.types.numbers.between start must be less than or equal to end";
lib.types.withCheck lib.types.number (value: value >= start && value <= end)
// {
name = "NumberBetween";
description = "numbereger between ${description start end}";
};
assert lib.errors.trace (
start <= end
) "lib.types.numbers.between start must be less than or equal to end";
lib.types.withCheck lib.types.number (value: value >= start && value <= end)
// {
name = "NumberBetween";
description = "numbereger between ${description start end}";
};
in
{
inherit between;
@ -486,12 +479,10 @@ lib: {
let
normalize =
definition:
builtins.mapAttrs
(name: value: {
__file__ = definition.__file__;
value = value;
})
definition.value;
builtins.mapAttrs (name: value: {
__file__ = definition.__file__;
value = value;
}) definition.value;
normalized = builtins.map normalize definitions;
zipper =
name: definitions: (lib.options.merge.definitions (location ++ [ name ]) type definitions).optional;
@ -528,19 +519,17 @@ lib: {
let
normalize =
definition:
builtins.mapAttrs
(name: value: {
__file__ = definition.__file__;
value = value;
})
definition.value;
builtins.mapAttrs (name: value: {
__file__ = definition.__file__;
value = value;
}) definition.value;
normalized = builtins.map normalize definitions;
zipper =
name: definitions:
let
merged = lib.options.merge.definitions (location ++ [ name ]) type definitions;
in
merged.optional.value or type.fallback.value or merged.merged;
merged.optional.value or type.fallback.value or merged.merged;
in
builtins.zipAttrsWith zipper normalized;
getSubOptions = prefix: type.getSubOptions (prefix ++ [ "<name>" ]);
@ -616,28 +605,25 @@ lib: {
merge =
location: definitions:
let
result = lib.lists.mapWithIndex1
(
i: definition:
lib.lists.mapWithIndex1
(
j: value:
let
resolved =
lib.options.merge.definitions (location ++ [ "[definition ${builtins.toString i}-entry ${builtins.toString j}]" ])
type
[
{
file = definition.file;
value = value;
}
];
in
resolved.optional
)
definition.value
)
definitions;
result = lib.lists.mapWithIndex1 (
i: definition:
lib.lists.mapWithIndex1 (
j: value:
let
resolved =
lib.options.merge.definitions
(location ++ [ "[definition ${builtins.toString i}-entry ${builtins.toString j}]" ])
type
[
{
file = definition.file;
value = value;
}
];
in
resolved.optional
) definition.value
) definitions;
merged = lib.lists.flatten result;
filtered = builtins.filter (definition: definition ? value) merged;
@ -792,11 +778,11 @@ lib: {
##
## @type { modules :: List Module, args? :: Attrs, description? :: String | Null, shorthand? :: Bool } -> Attrs
of =
settings@{ modules
, args ? { }
, description ? null
, shorthand ? true
,
settings@{
modules,
args ? { },
description ? null,
shorthand ? true,
}:
let
getModules = builtins.map (
@ -805,12 +791,9 @@ lib: {
let
# TODO: Figure out if we can apply additional attributes to the generated module.
# Currently this causes issues to do with redefined options.
rest = builtins.removeAttrs
(lib.attrs.filter
(
name: value: builtins.elem name lib.modules.VALID_KEYS
)
definition.value) [ "freeform" ];
rest = builtins.removeAttrs (lib.attrs.filter (
name: value: builtins.elem name lib.modules.VALID_KEYS
) definition.value) [ "freeform" ];
in
if definition.value ? config then
rest
@ -921,10 +904,10 @@ lib: {
##
## @type { module :: Module, name? :: String, description? :: String } -> Attrs
portable =
{ name ? "PortableSubmodule"
, description ? "portable submodule"
, module
,
{
name ? "PortableSubmodule",
description ? "portable submodule",
module,
}:
let
normalize =
@ -948,44 +931,50 @@ lib: {
builtins.concatLists normalized;
};
base = { config }: {
options = {
__modules__ = lib.options.create {
description = "User specified modules to be evaluated.";
type = lib.types.list.of (initial // { merge = lib.options.merge.one; });
internal = true;
default.value = [ ];
};
base =
{ config }:
{
options = {
__modules__ = lib.options.create {
description = "User specified modules to be evaluated.";
type = lib.types.list.of (initial // { merge = lib.options.merge.one; });
internal = true;
default.value = [ ];
};
extend = lib.options.create {
description = "Extend the submodule configuration.";
type = lib.types.function lib.types.raw;
internal = true;
writable = false;
default.value = module:
let
normalized =
if builtins.isList module then module
else if builtins.isFunction module || module ? config then
[ module ]
else [{ config = module; }];
extend = lib.options.create {
description = "Extend the submodule configuration.";
type = lib.types.function lib.types.raw;
internal = true;
writable = false;
default.value =
module:
let
normalized =
if builtins.isList module then
module
else if builtins.isFunction module || module ? config then
[ module ]
else
[ { config = module; } ];
modules = config.__modules__ ++ normalized;
modules = config.__modules__ ++ normalized;
result = lib.modules.run {
modules = [
module
base
{ config.__modules__ = modules; }
] ++ modules;
};
in
result.config;
result = lib.modules.run {
modules = [
module
base
{ config.__modules__ = modules; }
] ++ modules;
};
in
result.config;
};
};
};
};
transform = location: value:
transform =
location: value:
let
modules = lib.lists.from.any (normalize value);
@ -1001,11 +990,10 @@ lib: {
result.config;
final = lib.types.raw // {
merge = location: definitions:
merge =
location: definitions:
let
modules = lib.lists.flatten (
builtins.map (definition: normalize definition.value) definitions
);
modules = lib.lists.flatten (builtins.map (definition: normalize definition.value) definitions);
result = lib.modules.run {
prefix = location;
@ -1021,7 +1009,8 @@ lib: {
type = lib.types.coerceWithLocation initial transform final;
in
type // {
type
// {
inherit name description;
children = type.children // {
inherit module base;
@ -1051,12 +1040,10 @@ lib: {
merge = location: definitions: {
includes =
modules
++ builtins.map
(definition: {
__file__ = "${definition.__file__}; via ${lib.options.getIdentifier location}";
includes = [ definition.value ];
})
definitions;
++ builtins.map (definition: {
__file__ = "${definition.__file__}; via ${lib.options.getIdentifier location}";
includes = [ definition.value ];
}) definitions;
};
getSubOptions = submodule.getSubOptions;
getSubModules = submodule.getSubModules;
@ -1092,12 +1079,10 @@ lib: {
location: definitions:
let
first = builtins.elemAt definitions 0;
modules = builtins.map
(definition: {
__file__ = definition.__file__;
options = lib.options.create { type = definition.value; };
})
definitions;
modules = builtins.map (definition: {
__file__ = definition.__file__;
options = lib.options.create { type = definition.value; };
}) definitions;
merged = lib.modules.fixup location (lib.options.merge.declarations location modules);
in
if builtins.length definitions == 1 then first.value else merged.type;
@ -1330,12 +1315,10 @@ lib: {
merge =
location: definitions:
submodule.merge location (
builtins.map
(definition: {
__file__ = definition.__file__;
value = normalize definition;
})
definitions
builtins.map (definition: {
__file__ = definition.__file__;
value = normalize definition;
}) definitions
);
};
};

View file

@ -5,19 +5,21 @@ in
"PortableSubmodule" = {
"is portable" =
let
submodule = { config }: {
options = {
primitive = lib.options.create {
type = lib.types.string;
default.value = "<default>";
};
submodule =
{ config }:
{
options = {
primitive = lib.options.create {
type = lib.types.string;
default.value = "<default>";
};
computed = lib.options.create {
type = lib.types.string;
default.value = "computed: ${config.primitive}";
computed = lib.options.create {
type = lib.types.string;
default.value = "computed: ${config.primitive}";
};
};
};
};
option = lib.options.create {
default.value = { };
@ -29,11 +31,13 @@ in
moduleA = {
options.a = option;
};
moduleB = { config }: {
options.b = option;
moduleB =
{ config }:
{
options.b = option;
config.b = config.a;
};
config.b = config.a;
};
moduleC = {
config.b.primitive = "custom";
};

View file

@ -24,8 +24,10 @@ in
cross-foundation-glibc-x86_64-linux = config.packages.cross.x86_64-linux.foundation.glibc;
cross-foundation-binutils-x86_64-linux = config.packages.cross.x86_64-linux.foundation.binutils;
cross-tool-foundation-gcc-newlib-x86_64-linux = config.packages.cross-tools.x86_64-linux.foundation.gcc-newlib;
cross-tool-foundation-gcc-x86_64-linux = config.packages.cross-tools.x86_64-linux.foundation.gcc-cross;
cross-tool-foundation-gcc-newlib-x86_64-linux =
config.packages.cross-tools.x86_64-linux.foundation.gcc-newlib;
cross-tool-foundation-gcc-x86_64-linux =
config.packages.cross-tools.x86_64-linux.foundation.gcc-cross;
cross-foundation-gcc-x86_64-linux = config.packages.cross.x86_64-linux.foundation.gcc-bootstrap;
example-a = config.packages.foundation.gcc.versions.latest.extend {

View file

@ -211,15 +211,13 @@ in
path:
let
dependencies = lib.attrs.selectOrThrow path collected;
hooks = builtins.map
(
dependency:
let
getHooks = dependency.hooks or (lib.fp.const { });
in
getHooks ctx
)
dependencies;
hooks = builtins.map (
dependency:
let
getHooks = dependency.hooks or (lib.fp.const { });
in
getHooks ctx
) dependencies;
in
hooks;
in

View file

@ -263,7 +263,8 @@ in
type = lib.types.function lib.types.raw;
internal = true;
writable = false;
default.value = module:
default.value =
module:
let
normalized =
if builtins.isList module then
@ -271,17 +272,19 @@ in
else if builtins.isFunction module || module ? config then
[ module ]
else
[{
config = module;
}];
[
{
config = module;
}
];
modules = config.__modules__ ++ normalized;
modules = config.__modules__ ++ normalized;
result = lib.modules.run {
modules = [
submodule
{ config.__modules__ = modules; }
] ++ modules;
submodule
{ config.__modules__ = modules; }
] ++ modules;
};
in
result.config;

View file

@ -4,7 +4,10 @@ let
doubles = lib.systems.doubles.all;
packages = builtins.removeAttrs config.packages [ "cross" "cross-tools" ];
packages = builtins.removeAttrs config.packages [
"cross"
"cross-tools"
];
in
{
includes = [
@ -64,64 +67,60 @@ in
config = {
packages.cross-tools = lib.attrs.generate doubles (
system:
builtins.mapAttrs
(
namespace:
builtins.mapAttrs (
name: alias:
let
setTarget =
package:
package
// {
__modules__ = package.__modules__ ++ [
{
config.platform = {
target = lib.modules.override 5 system;
};
}
];
};
builtins.mapAttrs (
namespace:
builtins.mapAttrs (
name: alias:
let
setTarget =
package:
package
// {
__modules__ = package.__modules__ ++ [
{
config.platform = {
target = lib.modules.override 5 system;
};
}
];
};
updated = alias // {
versions = builtins.mapAttrs (version: package: setTarget package) alias.versions;
};
in
updated
)
updated = alias // {
versions = builtins.mapAttrs (version: package: setTarget package) alias.versions;
};
in
updated
)
packages
) packages
);
packages.cross = lib.attrs.generate doubles (
system:
builtins.mapAttrs
(
namespace:
builtins.mapAttrs (
name: alias:
let
setPlatform =
package:
package
// {
__modules__ = package.__modules__ ++ [
{
config.platform = {
host = lib.modules.override 5 system;
target = lib.modules.override 5 system;
};
}
];
};
builtins.mapAttrs (
namespace:
builtins.mapAttrs (
name: alias:
let
setPlatform =
package:
package
// {
__modules__ = package.__modules__ ++ [
{
config.platform = {
host = lib.modules.override 5 system;
target = lib.modules.override 5 system;
};
}
];
};
updated = alias // {
versions = builtins.mapAttrs (version: package: setPlatform package) alias.versions;
};
in
updated
)
updated = alias // {
versions = builtins.mapAttrs (version: package: setPlatform package) alias.versions;
};
in
updated
)
packages
) packages
);
};
}

View file

@ -1,8 +1,8 @@
{ lib
, lib'
, config
, options
,
{
lib,
lib',
config,
options,
}:
let
inherit (config)
@ -56,13 +56,12 @@ in
only = {
gcc = lib.modules.when (!isBootstrapped) (
if isCross then
packages.foundation.gcc-cross.versions.latest.extend
{
platform = lib.modules.override 0 {
inherit (config.platform) build target;
host = config.platform.build;
};
}
packages.foundation.gcc-cross.versions.latest.extend {
platform = lib.modules.override 0 {
inherit (config.platform) build target;
host = config.platform.build;
};
}
else
packages.foundation.gcc.versions.latest
);
@ -85,26 +84,28 @@ in
};
};
env = {
PATH = lib.paths.bin (
lib.lists.when (isBootstrapped) [ foundation.stage2-gcc ]
env =
{
PATH = lib.paths.bin (
lib.lists.when (isBootstrapped) [ foundation.stage2-gcc ]
++ [
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
]
);
} // (lib.attrs.when (isCross) {
LDFLAGS_FOR_TARGET = "-B${config.deps.build.only.glibc.package}/lib -L${config.deps.build.only.glibc.package}/lib -I${config.deps.build.only.glibc.package}/include";
});
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
]
);
}
// (lib.attrs.when (isCross) {
LDFLAGS_FOR_TARGET = "-B${config.deps.build.only.glibc.package}/lib -L${config.deps.build.only.glibc.package}/lib -I${config.deps.build.only.glibc.package}/include";
});
phases =
let

View file

@ -8,77 +8,74 @@ in
{
config.packages.foundation.gcc-bootstrap = {
versions = {
"latest" = config.packages.foundation.gcc.versions.latest.extend
(
{ config }:
{
config = {
meta = {
platforms = lib.modules.override 0 [
"i686-linux"
];
};
deps = {
build = {
build = {
gcc = lib.modules.override 0 (
packages.foundation.gcc-cross.versions.latest.extend {
platform = lib.modules.override 0 {
build = "i686-linux";
target = config.platform.target;
host = "i686-linux";
};
}
);
binutils = lib.modules.override 0 (
packages.foundation.binutils.versions.latest.extend {
platform = lib.modules.override 0 {
build = "i686-linux";
target = config.platform.target;
host = config.platform.host;
};
}
);
glibc = lib.modules.override 0 (
packages.foundation.glibc.versions.latest.extend {
platform = lib.modules.override 0 {
build = "i686-linux";
target = config.platform.target;
host = config.platform.host;
};
}
);
};
};
};
env = {
LIBRARY_PATH = lib.modules.override 0 "${config.deps.build.build.glibc.package}/lib";
LDFLAGS_FOR_TARGET =
lib.modules.override 0
"-L$(pwd)/${config.platform.target.triple}/libgcc -L${config.deps.build.build.glibc.package}/lib";
};
configureFlags = lib.modules.override 0 [
"--prefix=${builtins.placeholder "out"}"
# Pretend we're native even though we're not
"--build=${config.platform.target.triple}"
"--host=${config.platform.host.triple}"
"--target=${config.platform.target.triple}"
"--with-as=${config.deps.build.build.binutils.package}/bin/as"
"--with-ld=${config.deps.build.build.binutils.package}/bin/ld"
"--enable-languages=c,c++"
"--disable-bootstrap"
"--disable-libsanitizer"
"--disable-multilib"
"--with-native-system-header-dir=${config.deps.build.build.glibc.package}/include"
"--with-gxx-include-dir=${placeholder "out"}/include/c++/${config.version}/"
"--with-build-sysroot=/"
"latest" = config.packages.foundation.gcc.versions.latest.extend (
{ config }:
{
config = {
meta = {
platforms = lib.modules.override 0 [
"i686-linux"
];
};
}
);
deps = {
build = {
build = {
gcc = lib.modules.override 0 (
packages.foundation.gcc-cross.versions.latest.extend {
platform = lib.modules.override 0 {
build = "i686-linux";
target = config.platform.target;
host = "i686-linux";
};
}
);
binutils = lib.modules.override 0 (
packages.foundation.binutils.versions.latest.extend {
platform = lib.modules.override 0 {
build = "i686-linux";
target = config.platform.target;
host = config.platform.host;
};
}
);
glibc = lib.modules.override 0 (
packages.foundation.glibc.versions.latest.extend {
platform = lib.modules.override 0 {
build = "i686-linux";
target = config.platform.target;
host = config.platform.host;
};
}
);
};
};
};
env = {
LIBRARY_PATH = lib.modules.override 0 "${config.deps.build.build.glibc.package}/lib";
LDFLAGS_FOR_TARGET = lib.modules.override 0 "-L$(pwd)/${config.platform.target.triple}/libgcc -L${config.deps.build.build.glibc.package}/lib";
};
configureFlags = lib.modules.override 0 [
"--prefix=${builtins.placeholder "out"}"
# Pretend we're native even though we're not
"--build=${config.platform.target.triple}"
"--host=${config.platform.host.triple}"
"--target=${config.platform.target.triple}"
"--with-as=${config.deps.build.build.binutils.package}/bin/as"
"--with-ld=${config.deps.build.build.binutils.package}/bin/ld"
"--enable-languages=c,c++"
"--disable-bootstrap"
"--disable-libsanitizer"
"--disable-multilib"
"--with-native-system-header-dir=${config.deps.build.build.glibc.package}/include"
"--with-gxx-include-dir=${placeholder "out"}/include/c++/${config.version}/"
"--with-build-sysroot=/"
];
};
}
);
};
};
}

View file

@ -9,96 +9,90 @@ in
{
config.packages.foundation.gcc-cross = {
versions = {
"latest" = config.packages.foundation.gcc.versions.latest.extend
(
{ config }:
{
config =
let
programPrefix = lib.strings.when
(
config.platform.build.triple != config.platform.target.triple
) "${config.platform.target.triple}-";
in
{
meta = {
platforms = lib.modules.override 0 [
"i686-linux"
];
};
"latest" = config.packages.foundation.gcc.versions.latest.extend (
{ config }:
{
config =
let
programPrefix = lib.strings.when (
config.platform.build.triple != config.platform.target.triple
) "${config.platform.target.triple}-";
in
{
meta = {
platforms = lib.modules.override 0 [
"i686-linux"
];
};
deps = {
deps = {
build = {
build = {
build = {
binutils = (
packages.foundation.binutils.versions.latest.extend {
platform = lib.modules.override 0 config.platform;
}
);
glibc = (
packages.foundation.glibc.versions.latest.extend {
platform = lib.modules.override 0 {
inherit (config.platform) build target;
host = config.platform.target;
};
}
);
linux-headers = (
packages.foundation.linux-headers.versions.latest.extend {
platform.target = lib.modules.override 0 config.platform.target;
}
);
};
binutils = (
packages.foundation.binutils.versions.latest.extend {
platform = lib.modules.override 0 config.platform;
}
);
glibc = (
packages.foundation.glibc.versions.latest.extend {
platform = lib.modules.override 0 {
inherit (config.platform) build target;
host = config.platform.target;
};
}
);
linux-headers = (
packages.foundation.linux-headers.versions.latest.extend {
platform.target = lib.modules.override 0 config.platform.target;
}
);
};
};
env = {
# LIBRARY_PATH = lib.modules.override 0 "${foundation.stage1-musl}/lib";
CC = lib.modules.override 0 "gcc -Wl,-dynamic-linker -Wl,${foundation.stage1-musl}/lib/libc.so -idirafter ${foundation.stage1-musl}/include";
CXX = lib.modules.override 0 "g++ -Wl,-dynamic-linker -Wl,${foundation.stage1-musl}/lib/libc.so -idirafter ${foundation.stage1-musl}/include";
CFLAGS_FOR_TARGET =
lib.modules.override 0
"-Wl,-dynamic-linker -Wl,${config.deps.build.build.glibc.package}/lib/ld-linux-x86-64.so.2 -B${config.deps.build.build.glibc.package}/lib";
LDFLAGS_FOR_TARGET =
lib.modules.override 0
"-L$(pwd)/${config.platform.target.triple}/libgcc -L${config.deps.build.build.glibc.package}/lib";
};
configureFlags = lib.modules.override 0 [
"--prefix=${builtins.placeholder "out"}"
"--build=${config.platform.build.triple}"
"--host=${config.platform.host.triple}"
"--target=${config.platform.target.triple}"
"--with-as=${config.deps.build.build.binutils.package}/bin/${programPrefix}as"
"--with-ld=${config.deps.build.build.binutils.package}/bin/${programPrefix}ld"
"--enable-languages=c,c++"
"--disable-libsanitizer"
"--disable-lto"
"--disable-multilib"
"--with-headers=${config.deps.build.build.glibc.package}/include"
"--with-build-sysroot=/"
# "--with-sysroot=${config.deps.build.build.glibc.package}"
"--with-native-system-header-dir=${config.deps.build.build.glibc.package}/include"
];
phases.configure = lib.modules.override 0 ''
# Configure
mkdir build
cd build
echo PATH=$PATH
# TODO(vlinkz) Hack to fix missing crti.o and crtn.o. Figure out how to properly find their paths.
mkdir gcc
ln -sv ${config.deps.build.build.glibc.package}/lib/{crti.o,crtn.o} gcc
mkdir -p x86_64-unknown-linux-gnu/libstdc++-v3/src
ln -sv ${config.deps.build.build.glibc.package}/lib/{crti.o,crtn.o} x86_64-unknown-linux-gnu/libstdc++-v3/src
bash ../configure ${builtins.concatStringsSep " " config.configureFlags}
'';
};
}
);
env = {
# LIBRARY_PATH = lib.modules.override 0 "${foundation.stage1-musl}/lib";
CC = lib.modules.override 0 "gcc -Wl,-dynamic-linker -Wl,${foundation.stage1-musl}/lib/libc.so -idirafter ${foundation.stage1-musl}/include";
CXX = lib.modules.override 0 "g++ -Wl,-dynamic-linker -Wl,${foundation.stage1-musl}/lib/libc.so -idirafter ${foundation.stage1-musl}/include";
CFLAGS_FOR_TARGET = lib.modules.override 0 "-Wl,-dynamic-linker -Wl,${config.deps.build.build.glibc.package}/lib/ld-linux-x86-64.so.2 -B${config.deps.build.build.glibc.package}/lib";
LDFLAGS_FOR_TARGET = lib.modules.override 0 "-L$(pwd)/${config.platform.target.triple}/libgcc -L${config.deps.build.build.glibc.package}/lib";
};
configureFlags = lib.modules.override 0 [
"--prefix=${builtins.placeholder "out"}"
"--build=${config.platform.build.triple}"
"--host=${config.platform.host.triple}"
"--target=${config.platform.target.triple}"
"--with-as=${config.deps.build.build.binutils.package}/bin/${programPrefix}as"
"--with-ld=${config.deps.build.build.binutils.package}/bin/${programPrefix}ld"
"--enable-languages=c,c++"
"--disable-libsanitizer"
"--disable-lto"
"--disable-multilib"
"--with-headers=${config.deps.build.build.glibc.package}/include"
"--with-build-sysroot=/"
# "--with-sysroot=${config.deps.build.build.glibc.package}"
"--with-native-system-header-dir=${config.deps.build.build.glibc.package}/include"
];
phases.configure = lib.modules.override 0 ''
# Configure
mkdir build
cd build
echo PATH=$PATH
# TODO(vlinkz) Hack to fix missing crti.o and crtn.o. Figure out how to properly find their paths.
mkdir gcc
ln -sv ${config.deps.build.build.glibc.package}/lib/{crti.o,crtn.o} gcc
mkdir -p x86_64-unknown-linux-gnu/libstdc++-v3/src
ln -sv ${config.deps.build.build.glibc.package}/lib/{crti.o,crtn.o} x86_64-unknown-linux-gnu/libstdc++-v3/src
bash ../configure ${builtins.concatStringsSep " " config.configureFlags}
'';
};
}
);
};
};
}

View file

@ -107,10 +107,9 @@ in
(config.platform.target.triple != config.platform.host.triple)
&& (config.platform.host.triple == config.platform.target.triple);
programPrefix = lib.strings.when
(
config.platform.build.triple != config.platform.target.triple
) "${config.platform.target.triple}-";
programPrefix = lib.strings.when (
config.platform.build.triple != config.platform.target.triple
) "${config.platform.target.triple}-";
libc = if isBootstrapped then foundation.stage1-musl else config.deps.build.build.glibc.package;
libcLd =
@ -148,22 +147,25 @@ in
env =
{
PATH = lib.modules.when (isBuildBootstrapped) (
lib.paths.bin ([
foundation.stage2-gnumake
foundation.stage2-gnused
foundation.stage2-gnugrep
foundation.stage2-gnupatch
foundation.stage2-gawk
foundation.stage2-diffutils
foundation.stage2-findutils
foundation.stage2-gnutar
foundation.stage2-gzip
foundation.stage2-bzip2
foundation.stage1-xz
] ++ (lib.lists.when (isBootstrapped) [
foundation.stage2-gcc
foundation.stage2-binutils
]))
lib.paths.bin (
[
foundation.stage2-gnumake
foundation.stage2-gnused
foundation.stage2-gnugrep
foundation.stage2-gnupatch
foundation.stage2-gawk
foundation.stage2-diffutils
foundation.stage2-findutils
foundation.stage2-gnutar
foundation.stage2-gzip
foundation.stage2-bzip2
foundation.stage1-xz
]
++ (lib.lists.when (isBootstrapped) [
foundation.stage2-gcc
foundation.stage2-binutils
])
)
);
CFLAGS_FOR_TARGET = "-Wl,-dynamic-linker -Wl,${libcLd}";
}
@ -186,7 +188,9 @@ in
else
[
"-Wl,-dynamic-linker"
"-Wl,${config.deps.build.build.glibc.package}/lib/ld-linux${lib.strings.when (target.isx86 && target.is64bit) "-x86-64"}.so.2"
"-Wl,${config.deps.build.build.glibc.package}/lib/ld-linux${
lib.strings.when (target.isx86 && target.is64bit) "-x86-64"
}.so.2"
"-B${config.deps.build.build.glibc.package}/lib"
# "-idirafter ${config.deps.build.build.glibc.package}/include"
];
@ -246,7 +250,7 @@ in
patch = ''
${lib.strings.concatMapSep "\n" (file: "patch -Np1 -i ${file}") patches}
${lib.strings.when (isBootstrapped && !(crossTool || cross))''
${lib.strings.when (isBootstrapped && !(crossTool || cross)) ''
# force musl even if host triple is gnu
sed -i 's|"os/gnu-linux"|"os/generic"|' libstdc++-v3/configure.host
''}
@ -267,12 +271,10 @@ in
install = ''
# Install
${
lib.strings.when (host.is64bit) ''
mkdir -p $out/lib
ln -s lib $out/lib64
''
}
${lib.strings.when (host.is64bit) ''
mkdir -p $out/lib
ln -s lib $out/lib64
''}
make -j $NIX_BUILD_CORES install
'';
};

View file

@ -13,10 +13,9 @@ in
{
config =
let
programPrefix = lib.strings.when
(
config.platform.build.triple != config.platform.target.triple
) "${config.platform.target.triple}-";
programPrefix = lib.strings.when (
config.platform.build.triple != config.platform.target.triple
) "${config.platform.target.triple}-";
in
{
meta = {

View file

@ -1,8 +1,8 @@
{ lib
, lib'
, config
, options
,
{
lib,
lib',
config,
options,
}:
let
inherit (config)
@ -28,7 +28,10 @@ in
config = {
meta = {
platforms = [ "x86_64-linux" "i686-linux" ];
platforms = [
"x86_64-linux"
"i686-linux"
];
};
pname = "linux-headers";