Compare commits

..

5 commits

151 changed files with 8442 additions and 7554 deletions

6
format.sh Executable file
View file

@ -0,0 +1,6 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -I "nixpkgs=https://github.com/nixos/nixpkgs/archive/nixos-24.05.tar.gz" -p nixfmt-rfc-style
files=$(find . -name "*.nix" -type f)
nixfmt ${1:-"--verify"} ${files}

View file

@ -1,4 +1,7 @@
{system ? builtins.currentSystem}: let
{
system ? builtins.currentSystem,
}:
let
lib = import ./../lib;
modules = import ./src;

View file

@ -7,23 +7,28 @@
};
};
outputs = inputs: let
outputs =
inputs:
let
inherit (inputs.lib) lib;
modules = import ./src;
forEachSystem = lib.attrs.generate [
"i686-linux"
"x86_64-linux"
"x86-64_linux"
];
in {
extras = let
in
{
extras =
let
result = lib.modules.run { modules = builtins.attrValues modules; };
in
result.config.exports.resolved.extras;
packages = forEachSystem (
system: let
system:
let
result = lib.modules.run {
modules = (builtins.attrValues modules) ++ [ { config.aux.system = system; } ];
};

View file

@ -1,13 +1,12 @@
{
lib,
config,
}: let
{ lib, config }:
let
system = config.aux.system;
builders = config.aux.foundation.builders;
stage0 = config.aux.foundation.stages.stage0;
stage1 = config.aux.foundation.stages.stage1;
in {
in
{
options.aux.foundation.builders.bash.boot = {
build = lib.options.create {
type = lib.types.function lib.types.derivation;
@ -17,7 +16,8 @@ in {
config = {
aux.foundation.builders.bash.boot = {
build = settings @ {
build =
settings@{
name,
script,
meta ? { },
@ -25,9 +25,17 @@ in {
env ? { },
deps ? { },
...
}: let
}:
let
package = builtins.derivation (
(builtins.removeAttrs settings ["meta" "extras" "executable" "env" "deps" "script"])
(builtins.removeAttrs settings [
"meta"
"extras"
"executable"
"env"
"deps"
"script"
])
// env
// {
inherit name system script;
@ -68,10 +76,7 @@ in {
}
);
in
package
// {
inherit meta extras;
};
package // { inherit meta extras; };
};
};
}

View file

@ -1,15 +1,12 @@
{
lib,
config,
}: let
{ lib, config }:
let
system = config.aux.system;
builders = config.aux.foundation.builders;
stage1 = config.aux.foundation.stages.stage1;
in {
includes = [
./boot.nix
];
in
{
includes = [ ./boot.nix ];
options.aux.foundation.builders.bash = {
build = lib.options.create {
@ -20,7 +17,8 @@ in {
config = {
aux.foundation.builders.bash = {
build = settings @ {
build =
settings@{
name,
script,
meta ? { },
@ -28,9 +26,17 @@ in {
env ? { },
deps ? { },
...
}: let
}:
let
package = builtins.derivation (
(builtins.removeAttrs settings ["meta" "extras" "executable" "env" "deps" "script"])
(builtins.removeAttrs settings [
"meta"
"extras"
"executable"
"env"
"deps"
"script"
])
// env
// {
inherit name system script;
@ -70,10 +76,7 @@ in {
}
);
in
package
// {
inherit meta extras;
};
package // { inherit meta extras; };
};
};
}

View file

@ -1,11 +1,10 @@
{
lib,
config,
}: let
{ lib, config }:
let
system = config.aux.system;
stage0 = config.aux.foundation.stages.stage0;
in {
in
{
options.aux.foundation.builders.file.text = {
build = lib.options.create {
type = lib.types.function lib.types.derivation;
@ -15,7 +14,8 @@ in {
config = {
aux.foundation.builders.file.text = {
build = settings @ {
build =
settings@{
name,
contents,
isExecutable ? false,
@ -23,7 +23,8 @@ in {
meta ? { },
extras ? { },
...
}: let
}:
let
script =
''
target=''${out}''${destination}
@ -38,9 +39,19 @@ in {
chmod 555 ''${target}
'';
package = builtins.derivation (
(builtins.removeAttrs settings ["meta" "extras" "executable" "isExecutable"])
(builtins.removeAttrs settings [
"meta"
"extras"
"executable"
"isExecutable"
])
// {
inherit name system destination contents;
inherit
name
system
destination
contents
;
destinationDir = builtins.dirOf destination;
passAsFile = [ "contents" ];
@ -54,16 +65,11 @@ in {
(builtins.toFile "write-text-to-file.kaem" script)
];
PATH = lib.paths.bin [
stage0.mescc-tools-extra.package
];
PATH = lib.paths.bin [ stage0.mescc-tools-extra.package ];
}
);
in
package
// {
inherit meta extras;
};
package // { inherit meta extras; };
};
};
}

View file

@ -1,12 +1,11 @@
{
lib,
config,
}: let
{ lib, config }:
let
system = config.aux.system;
builders = config.aux.foundation.builders;
stage0 = config.aux.foundation.stages.stage0;
in {
in
{
options.aux.foundation.builders.kaem = {
build = lib.options.create {
type = lib.types.function lib.types.derivation;
@ -16,7 +15,8 @@ in {
config = {
aux.foundation.builders.kaem = {
build = settings @ {
build =
settings@{
name,
script,
meta ? { },
@ -24,9 +24,17 @@ in {
env ? { },
deps ? { },
...
}: let
}:
let
package = builtins.derivation (
(builtins.removeAttrs settings ["meta" "extras" "executable" "env" "deps" "script"])
(builtins.removeAttrs settings [
"meta"
"extras"
"executable"
"env"
"deps"
"script"
])
// env
// {
inherit name system;
@ -37,12 +45,10 @@ in {
"--verbose"
"--strict"
"--file"
(
builders.file.text.build {
(builders.file.text.build {
name = "${name}-builder";
contents = script;
}
)
})
];
PATH = lib.paths.bin (
@ -56,10 +62,7 @@ in {
}
);
in
package
// {
inherit meta extras;
};
package // { inherit meta extras; };
};
};
}

View file

@ -1,9 +1,8 @@
{
lib,
config,
}: let
{ lib, config }:
let
system = config.aux.system;
in {
in
{
options.aux.foundation.builders.raw = {
build = lib.options.create {
type = lib.types.function lib.types.derivation;
@ -13,7 +12,8 @@ in {
config = {
aux.foundation.builders.raw = {
build = settings @ {
build =
settings@{
pname,
version,
executable,
@ -21,11 +21,21 @@ in {
meta ? { },
extras ? { },
...
}: let
}:
let
package = builtins.derivation (
(builtins.removeAttrs settings ["meta" "extras" "executable"])
(builtins.removeAttrs settings [
"meta"
"extras"
"executable"
])
// {
inherit version pname system args;
inherit
version
pname
system
args
;
name = "${pname}-${version}";
@ -33,10 +43,7 @@ in {
}
);
in
package
// {
inherit meta extras;
};
package // { inherit meta extras; };
};
};
}

View file

@ -1,7 +1,5 @@
{
lib,
config,
}: let
{ lib, config }:
let
options = {
packages = lib.options.create {
default.value = { };
@ -14,7 +12,8 @@
type = lib.types.attrs.any;
};
};
in {
in
{
options = {
exports = {
inherit (options) packages extras;
@ -27,19 +26,16 @@ in {
config = {
exports.resolved = {
packages =
builtins.mapAttrs (
packages = builtins.mapAttrs (
name: value:
lib.attrs.filter
(
lib.attrs.filter (
name: value:
if value ? meta && value.meta ? platforms
then builtins.elem config.aux.system value.meta.platforms
else true
)
value
)
config.exports.packages;
if value ? meta && value.meta ? platforms then
builtins.elem config.aux.system value.meta.platforms
else
true
) value
) config.exports.packages;
extras = config.exports.extras;
};

View file

@ -1,4 +1,5 @@
{lib}: {
{ lib }:
{
options.aux.mirrors = {
gnu = lib.options.create {
type = lib.types.string;

View file

@ -1,7 +1,5 @@
{
lib,
config,
}: let
{ lib, config }:
let
system = config.aux.system;
parts = lib.strings.split "-" system;
@ -285,7 +283,8 @@
family = "javascript";
};
};
in {
in
{
options.aux.platform = {
name = lib.options.create {
type = lib.types.string;
@ -303,7 +302,10 @@ in {
};
endian = lib.options.create {
type = lib.types.enum ["little" "big"];
type = lib.types.enum [
"little"
"big"
];
default.value = "big";
description = "Endianess of the platform";
};
@ -332,12 +334,7 @@ in {
};
config = {
aux.platform =
(
platforms.${platform}
or (builtins.throw "Unsupported platform: ${system}")
)
// {
aux.platform = (platforms.${platform} or (builtins.throw "Unsupported platform: ${system}")) // {
name = platform;
# These will only ever have `linux` as the target since we

View file

@ -1,18 +1,18 @@
{
lib,
config,
}: let
inherit (config.aux) system;
{ lib, config }:
let
system = config.aux.system;
architecture =
if system == "x86_64-linux"
then "AMD64"
else if system == "aarch64-linux"
then "AArch64"
else if system == "i686-linux"
then "x86"
else builtins.throw "Unsupported system for stage0: ${system}";
in {
if system == "x86_64-linux" then
"AMD64"
else if system == "aarch64-linux" then
"AArch64"
else if system == "i686-linux" then
"x86"
else
builtins.throw "Unsupported system for stage0: ${system}";
in
{
options.aux.foundation.stages.stage0.architecture = {
base = lib.options.create {
type = lib.types.string;

View file

@ -1,21 +1,21 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage0;
system = config.aux.system;
builders = config.aux.foundation.builders;
architecture =
if system == "x86_64-linux"
then "AMD64"
else if system == "aarch64-linux"
then "AArch64"
else if system == "i686-linux"
then "x86"
else builtins.throw "Unsupported system for stage0: ${system}";
in {
if system == "x86_64-linux" then
"AMD64"
else if system == "aarch64-linux" then
"AArch64"
else if system == "i686-linux" then
"x86"
else
builtins.throw "Unsupported system for stage0: ${system}";
in
{
includes = [
./sources
./architecture

View file

@ -1,7 +1,5 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage0.kaem;
system = config.aux.system;
@ -10,7 +8,8 @@
kaem-unwrapped = config.aux.foundation.stages.stage0.kaem-unwrapped;
mescc-tools = config.aux.foundation.stages.stage0.mescc-tools;
mescc-tools-extra = config.aux.foundation.stages.stage0.mescc-tools-extra;
in {
in
{
options.aux.foundation.stages.stage0.kaem = {
meta = {
description = lib.options.create {
@ -36,8 +35,8 @@ in {
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};
};

View file

@ -1,7 +1,5 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage0.mescc-tools-extra;
hex0 = config.aux.foundation.stages.stage0.hex0;
catm = config.aux.foundation.stages.stage0.catm;
@ -18,7 +16,8 @@
builders = config.aux.foundation.builders;
sources = config.aux.foundation.stages.stage0.sources;
architecture = config.aux.foundation.stages.stage0.architecture;
in {
in
{
options.aux.foundation.stages.stage0.mescc-tools-extra = {
meta = {
description = lib.options.create {
@ -44,8 +43,8 @@ in {
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};
};

View file

@ -1,7 +1,5 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage0.mescc-tools;
hex0 = config.aux.foundation.stages.stage0.hex0;
catm = config.aux.foundation.stages.stage0.catm;
@ -18,24 +16,21 @@
sources = config.aux.foundation.stages.stage0.sources;
architecture = config.aux.foundation.stages.stage0.architecture;
bloodFlag =
if config.aux.platform.bits == 64
then "--64"
else " ";
endianFlag =
if config.aux.platform.endian == "little"
then "--little-endian"
else "--big-endian";
bloodFlag = if config.aux.platform.bits == 64 then "--64" else " ";
endianFlag = if config.aux.platform.endian == "little" then "--little-endian" else "--big-endian";
baseAddress =
if config.aux.system == "x86_64-linux"
then "0x00600000"
else if config.aux.system == "aarch64-linux"
then "0x00600000"
else if config.aux.system == "i686-linux"
then "0x08048000"
else builtins.throw "Unsupported system: ${config.aux.system}";
if config.aux.system == "x86_64-linux" then
"0x00600000"
else if config.aux.system == "aarch64-linux" then
"0x00600000"
else if config.aux.system == "i686-linux" then
"0x08048000"
else
builtins.throw "Unsupported system: ${config.aux.system}";
getExtraUtil = name: let
getExtraUtil =
name:
let
script = builtins.toFile "build-${name}.kaem" ''
''${M2} --architecture ${architecture.m2libc} \
-f ''${m2libc}/sys/types.h \
@ -104,7 +99,8 @@
endianFlag = endianFlag;
baseAddress = baseAddress;
};
in {
in
{
options.aux.foundation.stages.stage0.mescc-tools = {
meta = {
description = lib.options.create {
@ -130,8 +126,8 @@ in {
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};
};

View file

@ -1,7 +1,5 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage0.hex0;
system = config.aux.system;
@ -9,14 +7,16 @@
sources = config.aux.foundation.stages.stage0.sources;
architecture =
if system == "x86_64-linux"
then "AMD64"
else if system == "aarch64-linux"
then "AArch64"
else if system == "i686-linux"
then "x86"
else builtins.throw "Unsupported system for stage0: ${system}";
in {
if system == "x86_64-linux" then
"AMD64"
else if system == "aarch64-linux" then
"AArch64"
else if system == "i686-linux" then
"x86"
else
builtins.throw "Unsupported system for stage0: ${system}";
in
{
options.aux.foundation.stages.stage0.hex0 = {
meta = {
description = lib.options.create {
@ -42,8 +42,8 @@ in {
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};
};
@ -90,13 +90,14 @@ in {
);
hash = lib.modules.overrides.default (
if system == "x86_64-linux"
then "sha256-RCgK9oZRDQUiWLVkcIBSR2HeoB+Bh0czthrpjFEkCaY="
else if system == "aarch64-linux"
then "sha256-XTPsoKeI6wTZAF0UwEJPzuHelWOJe//wXg4HYO0dEJo="
else if system == "i686-linux"
then "sha256-QU3RPGy51W7M2xnfFY1IqruKzusrSLU+L190ztN6JW8="
else null
if system == "x86_64-linux" then
"sha256-RCgK9oZRDQUiWLVkcIBSR2HeoB+Bh0czthrpjFEkCaY="
else if system == "aarch64-linux" then
"sha256-XTPsoKeI6wTZAF0UwEJPzuHelWOJe//wXg4HYO0dEJo="
else if system == "i686-linux" then
"sha256-QU3RPGy51W7M2xnfFY1IqruKzusrSLU+L190ztN6JW8="
else
null
);
executable = lib.modules.overrides.default (

View file

@ -1,7 +1,5 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage0.hex1;
hex0 = config.aux.foundation.stages.stage0.hex0;
@ -9,7 +7,8 @@
builders = config.aux.foundation.builders;
sources = config.aux.foundation.stages.stage0.sources;
architecture = config.aux.foundation.stages.stage0.architecture;
in {
in
{
options.aux.foundation.stages.stage0.hex1 = {
meta = {
description = lib.options.create {
@ -35,8 +34,8 @@ in {
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};
};

View file

@ -1,7 +1,5 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage0.hex2-0;
hex0 = config.aux.foundation.stages.stage0.hex0;
hex1 = config.aux.foundation.stages.stage0.hex1;
@ -10,7 +8,8 @@
builders = config.aux.foundation.builders;
sources = config.aux.foundation.stages.stage0.sources;
architecture = config.aux.foundation.stages.stage0.architecture;
in {
in
{
options.aux.foundation.stages.stage0.hex2-0 = {
meta = {
description = lib.options.create {
@ -36,8 +35,8 @@ in {
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};
};

View file

@ -1,7 +1,5 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage0.catm;
hex0 = config.aux.foundation.stages.stage0.hex0;
hex1 = config.aux.foundation.stages.stage0.hex1;
@ -11,7 +9,8 @@
builders = config.aux.foundation.builders;
sources = config.aux.foundation.stages.stage0.sources;
architecture = config.aux.foundation.stages.stage0.architecture;
in {
in
{
options.aux.foundation.stages.stage0.catm = {
meta = {
description = lib.options.create {
@ -37,8 +36,8 @@ in {
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};
};
@ -58,18 +57,16 @@ in {
meta = cfg.meta;
executable =
if architecture.base == "AArch64"
then hex1.package
else hex2-0.package;
executable = if architecture.base == "AArch64" then hex1.package else hex2-0.package;
args =
if architecture.base == "AArch64"
then [
if architecture.base == "AArch64" then
[
"${sources.base}/catm_${architecture.base}.hex1"
(builtins.placeholder "out")
]
else [
else
[
"${sources.base}/catm_${architecture.base}.hex2"
(builtins.placeholder "out")
];

View file

@ -1,7 +1,5 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage0.M0;
hex0 = config.aux.foundation.stages.stage0.hex0;
hex2-0 = config.aux.foundation.stages.stage0.hex2-0;
@ -11,7 +9,8 @@
builders = config.aux.foundation.builders;
sources = config.aux.foundation.stages.stage0.sources;
architecture = config.aux.foundation.stages.stage0.architecture;
in {
in
{
options.aux.foundation.stages.stage0.M0 = {
meta = {
description = lib.options.create {
@ -37,8 +36,8 @@ in {
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};
};
@ -60,7 +59,8 @@ in {
executable = hex2-0.package;
args = let
args =
let
M0_hex2-0 = builders.raw.build {
pname = "M0_hex2-0";
version = "1.6.0";
@ -75,7 +75,8 @@ in {
"${sources.base}/M0_${architecture.base}.hex2"
];
};
in [
in
[
M0_hex2-0
(builtins.placeholder "out")
];

View file

@ -1,7 +1,5 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage0.cc_arch;
hex0 = config.aux.foundation.stages.stage0.hex0;
hex2-0 = config.aux.foundation.stages.stage0.hex2-0;
@ -12,7 +10,8 @@
builders = config.aux.foundation.builders;
sources = config.aux.foundation.stages.stage0.sources;
architecture = config.aux.foundation.stages.stage0.architecture;
in {
in
{
options.aux.foundation.stages.stage0.cc_arch = {
meta = {
description = lib.options.create {
@ -38,8 +37,8 @@ in {
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};
};
@ -61,7 +60,8 @@ in {
executable = hex2-0.package;
args = let
args =
let
cc_arch0_hex2-0 = builders.raw.build {
pname = "cc_arch0_hex2-0";
version = "1.6.0";
@ -89,7 +89,8 @@ in {
cc_arch0_hex2-0
];
};
in [
in
[
cc_arch1_hex2-0
(builtins.placeholder "out")
];

View file

@ -1,7 +1,5 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage0.M2;
hex0 = config.aux.foundation.stages.stage0.hex0;
hex2-0 = config.aux.foundation.stages.stage0.hex2-0;
@ -13,7 +11,8 @@
builders = config.aux.foundation.builders;
sources = config.aux.foundation.stages.stage0.sources;
architecture = config.aux.foundation.stages.stage0.architecture;
in {
in
{
options.aux.foundation.stages.stage0.M2 = {
meta = {
description = lib.options.create {
@ -39,8 +38,8 @@ in {
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};
};
@ -62,7 +61,8 @@ in {
executable = hex2-0.package;
args = let
args =
let
M2_c = builders.raw.build {
pname = "M2_c";
version = "1.6.0";
@ -140,7 +140,8 @@ in {
M2_hex2-0
];
};
in [
in
[
M2_hex2-0'
(builtins.placeholder "out")
];

View file

@ -1,7 +1,5 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage0.blood-elf;
hex0 = config.aux.foundation.stages.stage0.hex0;
hex2-0 = config.aux.foundation.stages.stage0.hex2-0;
@ -14,7 +12,8 @@
builders = config.aux.foundation.builders;
sources = config.aux.foundation.stages.stage0.sources;
architecture = config.aux.foundation.stages.stage0.architecture;
in {
in
{
options.aux.foundation.stages.stage0.blood-elf = {
meta = {
description = lib.options.create {
@ -40,8 +39,8 @@ in {
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};
};
@ -63,7 +62,8 @@ in {
executable = hex2-0.package;
args = let
args =
let
blood-elf_M1 = builders.raw.build {
pname = "blood-elf_M1";
version = "1.6.0";
@ -130,7 +130,8 @@ in {
blood-elf_hex2-0
];
};
in [
in
[
blood-elf_hex2-0'
(builtins.placeholder "out")
];

View file

@ -1,7 +1,5 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage0.M1-0;
hex0 = config.aux.foundation.stages.stage0.hex0;
hex2-0 = config.aux.foundation.stages.stage0.hex2-0;
@ -15,7 +13,8 @@
builders = config.aux.foundation.builders;
sources = config.aux.foundation.stages.stage0.sources;
architecture = config.aux.foundation.stages.stage0.architecture;
in {
in
{
options.aux.foundation.stages.stage0.M1-0 = {
meta = {
description = lib.options.create {
@ -41,8 +40,8 @@ in {
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};
};
@ -64,7 +63,8 @@ in {
executable = hex2-0.package;
args = let
args =
let
M1-macro-0_M1 = builders.raw.build {
pname = "M1-macro-0_M1";
version = "1.6.0";
@ -98,16 +98,10 @@ in {
executable = blood-elf.package;
args =
(lib.lists.when (config.aux.platform.bits == 64) "--64")
++ [
args = (lib.lists.when (config.aux.platform.bits == 64) "--64") ++ [
"-f"
M1-macro-0_M1
(
if config.aux.platform.endian == "little"
then "--little-endian"
else "--big-endian"
)
(if config.aux.platform.endian == "little" then "--little-endian" else "--big-endian")
"-o"
(builtins.placeholder "out")
];
@ -155,7 +149,8 @@ in {
M1-macro-0_hex2-0
];
};
in [
in
[
M1-macro-0_hex2-0'
(builtins.placeholder "out")
];

View file

@ -1,7 +1,5 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage0.hex2-1;
hex0 = config.aux.foundation.stages.stage0.hex0;
hex2-0 = config.aux.foundation.stages.stage0.hex2-0;
@ -16,7 +14,8 @@
builders = config.aux.foundation.builders;
sources = config.aux.foundation.stages.stage0.sources;
architecture = config.aux.foundation.stages.stage0.architecture;
in {
in
{
options.aux.foundation.stages.stage0.hex2-1 = {
meta = {
description = lib.options.create {
@ -42,8 +41,8 @@ in {
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};
};
@ -65,7 +64,8 @@ in {
executable = hex2-0.package;
args = let
args =
let
hex2_linker_M1 = builders.raw.build {
pname = "hex2_linker_M1";
version = "1.6.0";
@ -118,16 +118,10 @@ in {
executable = blood-elf.package;
args =
(lib.lists.when (config.aux.platform.bits == 64) "--64")
++ [
args = (lib.lists.when (config.aux.platform.bits == 64) "--64") ++ [
"-f"
hex2_linker_M1
(
if config.aux.platform.endian == "little"
then "--little-endian"
else "--big-endian"
)
(if config.aux.platform.endian == "little" then "--little-endian" else "--big-endian")
"-o"
(builtins.placeholder "out")
];
@ -143,11 +137,7 @@ in {
args = [
"--architecture"
architecture.m2libc
(
if config.aux.platform.endian == "little"
then "--little-endian"
else "--big-endian"
)
(if config.aux.platform.endian == "little" then "--little-endian" else "--big-endian")
"-f"
"${sources.m2libc}/${architecture.m2libc}/${architecture.m2libc}_defs.M1"
"-f"
@ -174,7 +164,8 @@ in {
hex2_linker_hex2
];
};
in [
in
[
hex2_linker_hex2'
(builtins.placeholder "out")
];

View file

@ -1,7 +1,5 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage0.M1;
hex0 = config.aux.foundation.stages.stage0.hex0;
hex2-0 = config.aux.foundation.stages.stage0.hex2-0;
@ -17,7 +15,8 @@
builders = config.aux.foundation.builders;
sources = config.aux.foundation.stages.stage0.sources;
architecture = config.aux.foundation.stages.stage0.architecture;
in {
in
{
options.aux.foundation.stages.stage0.M1 = {
meta = {
description = lib.options.create {
@ -43,8 +42,8 @@ in {
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};
};
@ -66,7 +65,8 @@ in {
executable = hex2-1.package;
args = let
args =
let
M1-macro_M1 = builders.raw.build {
pname = "M1-macro_M1";
version = "1.6.0";
@ -117,16 +117,10 @@ in {
executable = blood-elf.package;
args =
(lib.lists.when (config.aux.platform.bits == 64) "--64")
++ [
args = (lib.lists.when (config.aux.platform.bits == 64) "--64") ++ [
"-f"
M1-macro_M1
(
if config.aux.platform.endian == "little"
then "--little-endian"
else "--big-endian"
)
(if config.aux.platform.endian == "little" then "--little-endian" else "--big-endian")
"-o"
(builtins.placeholder "out")
];
@ -142,11 +136,7 @@ in {
args = [
"--architecture"
architecture.m2libc
(
if config.aux.platform.endian == "little"
then "--little-endian"
else "--big-endian"
)
(if config.aux.platform.endian == "little" then "--little-endian" else "--big-endian")
"-f"
"${sources.m2libc}/${architecture.m2libc}/${architecture.m2libc}_defs.M1"
"-f"
@ -159,23 +149,21 @@ in {
(builtins.placeholder "out")
];
};
in [
in
[
"--architecture"
architecture.m2libc
(
if config.aux.platform.endian == "little"
then "--little-endian"
else "--big-endian"
)
(if config.aux.platform.endian == "little" then "--little-endian" else "--big-endian")
"--base-address"
(
if config.aux.system == "x86_64-linux"
then "0x00600000"
else if config.aux.system == "aarch64-linux"
then "0x00600000"
else if config.aux.system == "i686-linux"
then "0x08048000"
else builtins.throw "Unsupported system: ${config.aux.system}"
if config.aux.system == "x86_64-linux" then
"0x00600000"
else if config.aux.system == "aarch64-linux" then
"0x00600000"
else if config.aux.system == "i686-linux" then
"0x08048000"
else
builtins.throw "Unsupported system: ${config.aux.system}"
)
"-f"
"${sources.m2libc}/${architecture.m2libc}/ELF-${architecture.m2libc}-debug.hex2"

View file

@ -1,7 +1,5 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage0.hex2;
hex0 = config.aux.foundation.stages.stage0.hex0;
catm = config.aux.foundation.stages.stage0.catm;
@ -16,7 +14,8 @@
builders = config.aux.foundation.builders;
sources = config.aux.foundation.stages.stage0.sources;
architecture = config.aux.foundation.stages.stage0.architecture;
in {
in
{
options.aux.foundation.stages.stage0.hex2 = {
meta = {
description = lib.options.create {
@ -42,8 +41,8 @@ in {
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};
};
@ -65,7 +64,8 @@ in {
executable = hex2-1.package;
args = let
args =
let
hex2_linker_M1 = builders.raw.build {
pname = "hex2_linker_M1";
version = "1.6.0";
@ -118,16 +118,10 @@ in {
executable = blood-elf.package;
args =
(lib.lists.when (config.aux.platform.bits == 64) "--64")
++ [
args = (lib.lists.when (config.aux.platform.bits == 64) "--64") ++ [
"-f"
hex2_linker_M1
(
if config.aux.platform.endian == "little"
then "--little-endian"
else "--big-endian"
)
(if config.aux.platform.endian == "little" then "--little-endian" else "--big-endian")
"-o"
(builtins.placeholder "out")
];
@ -143,11 +137,7 @@ in {
args = [
"--architecture"
architecture.m2libc
(
if config.aux.platform.endian == "little"
then "--little-endian"
else "--big-endian"
)
(if config.aux.platform.endian == "little" then "--little-endian" else "--big-endian")
"-f"
"${sources.m2libc}/${architecture.m2libc}/${architecture.m2libc}_defs.M1"
"-f"
@ -160,23 +150,21 @@ in {
(builtins.placeholder "out")
];
};
in [
in
[
"--architecture"
architecture.m2libc
(
if config.aux.platform.endian == "little"
then "--little-endian"
else "--big-endian"
)
(if config.aux.platform.endian == "little" then "--little-endian" else "--big-endian")
"--base-address"
(
if config.aux.system == "x86_64-linux"
then "0x00600000"
else if config.aux.system == "aarch64-linux"
then "0x00600000"
else if config.aux.system == "i686-linux"
then "0x08048000"
else builtins.throw "Unsupported system: ${config.aux.system}"
if config.aux.system == "x86_64-linux" then
"0x00600000"
else if config.aux.system == "aarch64-linux" then
"0x00600000"
else if config.aux.system == "i686-linux" then
"0x08048000"
else
builtins.throw "Unsupported system: ${config.aux.system}"
)
"-f"
"${sources.m2libc}/${architecture.m2libc}/ELF-${architecture.m2libc}-debug.hex2"

View file

@ -1,7 +1,5 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage0.kaem-unwrapped;
hex0 = config.aux.foundation.stages.stage0.hex0;
catm = config.aux.foundation.stages.stage0.catm;
@ -16,7 +14,8 @@
builders = config.aux.foundation.builders;
sources = config.aux.foundation.stages.stage0.sources;
architecture = config.aux.foundation.stages.stage0.architecture;
in {
in
{
options.aux.foundation.stages.stage0.kaem-unwrapped = {
meta = {
description = lib.options.create {
@ -42,8 +41,8 @@ in {
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};
};
@ -65,7 +64,8 @@ in {
executable = hex2.package;
args = let
args =
let
kaem_M1 = builders.raw.build {
pname = "kaem_M1";
version = "1.6.0";
@ -120,16 +120,10 @@ in {
executable = blood-elf.package;
args =
(lib.lists.when (config.aux.platform.bits == 64) "--64")
++ [
args = (lib.lists.when (config.aux.platform.bits == 64) "--64") ++ [
"-f"
kaem_M1
(
if config.aux.platform.endian == "little"
then "--little-endian"
else "--big-endian"
)
(if config.aux.platform.endian == "little" then "--little-endian" else "--big-endian")
"-o"
(builtins.placeholder "out")
];
@ -145,11 +139,7 @@ in {
args = [
"--architecture"
architecture.m2libc
(
if config.aux.platform.endian == "little"
then "--little-endian"
else "--big-endian"
)
(if config.aux.platform.endian == "little" then "--little-endian" else "--big-endian")
"-f"
"${sources.m2libc}/${architecture.m2libc}/${architecture.m2libc}_defs.M1"
"-f"
@ -162,23 +152,21 @@ in {
(builtins.placeholder "out")
];
};
in [
in
[
"--architecture"
architecture.m2libc
(
if config.aux.platform.endian == "little"
then "--little-endian"
else "--big-endian"
)
(if config.aux.platform.endian == "little" then "--little-endian" else "--big-endian")
"--base-address"
(
if config.aux.system == "x86_64-linux"
then "0x00600000"
else if config.aux.system == "aarch64-linux"
then "0x00600000"
else if config.aux.system == "i686-linux"
then "0x08048000"
else builtins.throw "Unsupported system: ${config.aux.system}"
if config.aux.system == "x86_64-linux" then
"0x00600000"
else if config.aux.system == "aarch64-linux" then
"0x00600000"
else if config.aux.system == "i686-linux" then
"0x08048000"
else
builtins.throw "Unsupported system: ${config.aux.system}"
)
"-f"
"${sources.m2libc}/${architecture.m2libc}/ELF-${architecture.m2libc}-debug.hex2"

View file

@ -1,11 +1,10 @@
{
lib,
config,
}: let
{ lib, config }:
let
system = config.aux.system;
architecture = config.aux.foundation.stages.stage0.architecture.base;
in {
in
{
options.aux.foundation.stages.stage0.sources = {
base = lib.options.create {
type = lib.types.string;
@ -44,27 +43,25 @@ in {
# fetching that, we are instead fetching each submodule directly. The central repository is located
# here: https://github.com/oriansj/stage0-posix
base =
if architecture == "AMD64"
then
if architecture == "AMD64" then
builtins.fetchTarball {
url = "https://github.com/oriansj/stage0-posix-amd64/archive/93fbe4c08772d8df1412e2554668e24cf604088c.tar.gz";
sha256 = "10d1xnjzqplpfip3pm89bydd501x1bcgkg7lkkadyq5bqpad5flp";
}
else if architecture == "AArch64"
then
else if architecture == "AArch64" then
# FIXME: We may need to patch the aarch64 variant.
# https://github.com/oriansj/M2libc/pull/17
builtins.fetchTarball {
url = "https://github.com/oriansj/stage0-posix-aarch64/archive/39a43f803d572b53f95d42507202152eeda18361.tar.gz";
sha256 = "1x607hr3n5j89394d156r23igpx8hifjd14ygksx7902rlwrrry2";
}
else if architecture == "x86"
then
else if architecture == "x86" then
builtins.fetchTarball {
url = "https://github.com/oriansj/stage0-posix-x86/archive/e86bf7d304bae5ce5ccc88454bb60cf0837e941f.tar.gz";
sha256 = "1c1fk793yzq8zbg60n2zd22fsmirc3zr26fj0iskap456g84nxv8";
}
else builtins.throw "Unsupported architecture for stage0: ${architecture}";
else
builtins.throw "Unsupported architecture for stage0: ${architecture}";
m2libc = builtins.fetchTarball {
url = "https://github.com/oriansj/M2libc/archive/de7c75f144176c3b9be77695d9bf94440445aeae.tar.gz";

View file

@ -1,13 +1,12 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage1.bash.boot;
builders = config.aux.foundation.builders;
stage1 = config.aux.foundation.stages.stage1;
in {
in
{
options.aux.foundation.stages.stage1.bash.boot = {
meta = {
description = lib.options.create {
@ -34,7 +33,7 @@ in {
description = "Platforms the package supports.";
default.value = [
"i686-linux"
"x86_64-linux"
"x86-64_linux"
];
};
};
@ -64,7 +63,8 @@ in {
sha256 = "1r1z2qdw3rz668nxrzwa14vk2zcn00hw7mpjn384picck49d80xs";
};
package = let
package =
let
# Thanks to the live-bootstrap project!
# See https://github.com/fosslinux/live-bootstrap/blob/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/bash-2.05b/bash-2.05b.kaem
liveBootstrap = "https://github.com/fosslinux/live-bootstrap/raw/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/bash-2.05b";

View file

@ -36,7 +36,7 @@ in
description = "Platforms the package supports.";
default.value = [
"i686-linux"
"x86_64-linux"
"x86-64_linux"
];
};

View file

@ -34,7 +34,7 @@ in
description = "Platforms the package supports.";
default.value = [
"i686-linux"
"x86_64-linux"
"x86-64_linux"
];
};
};

View file

@ -34,7 +34,7 @@ in
description = "Platforms the package supports.";
default.value = [
"i686-linux"
"x86_64-linux"
"x86-64_linux"
];
};
};

View file

@ -1,14 +1,13 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage1.bzip2;
platform = config.aux.platform;
builders = config.aux.foundation.builders;
stage1 = config.aux.foundation.stages.stage1;
in {
in
{
options.aux.foundation.stages.stage1.bzip2 = {
meta = {
description = lib.options.create {
@ -36,7 +35,7 @@ in {
# TODO: Support more platforms.
default.value = [
"i686-linux"
"x86_64-linux"
"x86-64_linux"
];
};
};

View file

@ -1,13 +1,12 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage1.coreutils.boot;
builders = config.aux.foundation.builders;
stage1 = config.aux.foundation.stages.stage1;
in {
in
{
options.aux.foundation.stages.stage1.coreutils.boot = {
package = lib.options.create {
type = lib.types.derivation;
@ -34,7 +33,8 @@ in {
sha256 = "10wq6k66i8adr4k08p0xmg87ff4ypiazvwzlmi7myib27xgffz62";
};
package = let
package =
let
# Thanks to the live-bootstrap project!
# See https://github.com/fosslinux/live-bootstrap/blob/a8752029f60217a5c41c548b16f5cdd2a1a0e0db/sysa/coreutils-5.0/coreutils-5.0.kaem
liveBootstrap = "https://github.com/fosslinux/live-bootstrap/raw/a8752029f60217a5c41c548b16f5cdd2a1a0e0db/sysa/coreutils-5.0";

View file

@ -36,7 +36,7 @@ in
description = "Platforms the package supports.";
default.value = [
"i686-linux"
"x86_64-linux"
"x86-64_linux"
];
};
};

View file

@ -1,11 +1,10 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage1;
stage1 = config.aux.foundation.stages.stage1;
in {
in
{
includes = [
./nyacc
./mes

View file

@ -34,7 +34,7 @@ in
description = "Platforms the package supports.";
default.value = [
"i686-linux"
"x86_64-linux"
"x86-64_linux"
];
};
};

View file

@ -34,7 +34,7 @@ in
description = "Platforms the package supports.";
default.value = [
"i686-linux"
"x86_64-linux"
"x86-64_linux"
];
};
};

View file

@ -36,7 +36,7 @@ in
description = "Platforms the package supports.";
default.value = [
"i686-linux"
"x86_64-linux"
"x86-64_linux"
];
};

View file

@ -40,7 +40,7 @@ in
description = "Platforms the package supports.";
default.value = [
"i686-linux"
"x86_64-linux"
"x86-64_linux"
];
};
};

View file

@ -1,13 +1,12 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage1.gnugrep;
builders = config.aux.foundation.builders;
stage1 = config.aux.foundation.stages.stage1;
in {
in
{
options.aux.foundation.stages.stage1.gnugrep = {
meta = {
description = lib.options.create {
@ -34,7 +33,7 @@ in {
description = "Platforms the package supports.";
default.value = [
"i686-linux"
"x86_64-linux"
"x86-64_linux"
];
};
@ -70,7 +69,8 @@ in {
sha256 = "05iayw5sfclc476vpviz67hdy03na0pz2kb5csa50232nfx34853";
};
package = let
package =
let
# Thanks to the live-bootstrap project!
# See https://github.com/fosslinux/live-bootstrap/blob/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/grep-2.4
makefile = builtins.fetchurl {

View file

@ -34,7 +34,7 @@ in
description = "Platforms the package supports.";
default.value = [
"i686-linux"
"x86_64-linux"
"x86-64_linux"
];
};
};

View file

@ -1,13 +1,12 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage1.gnumake.boot;
builders = config.aux.foundation.builders;
stage1 = config.aux.foundation.stages.stage1;
in {
in
{
options.aux.foundation.stages.stage1.gnumake.boot = {
package = lib.options.create {
type = lib.types.derivation;
@ -34,7 +33,8 @@ in {
sha256 = "1cwgcmwdn7gqn5da2ia91gkyiqs9birr10sy5ykpkaxzcwfzn5nx";
};
package = let
package =
let
patches = [
# Replaces /bin/sh with sh, see patch file for reasoning
./patches/0001-No-impure-bin-sh.patch
@ -114,8 +114,7 @@ in {
"-Dvfork=fork"
];
cflags =
[
cflags = [
"-I./src"
"-I./lib"
"-DHAVE_CONFIG_H"
@ -127,8 +126,7 @@ in {
"-DNO_OUTPUT_SYNC=1"
# mes-libc doesn't define O_TMPFILE
"-DO_TMPFILE=020000000"
]
++ config;
] ++ config;
sources = {
# Maintenance note: list of source files derived from Basic.mk
@ -166,27 +164,14 @@ in {
"lib/fnmatch.c"
"lib/glob.c"
];
remote = [
"src/remote-stub.c"
];
remote = [ "src/remote-stub.c" ];
};
files =
sources.make
++ sources.glob
++ sources.remote
++ [
"src/posixos.c"
];
files = sources.make ++ sources.glob ++ sources.remote ++ [ "src/posixos.c" ];
objects =
builtins.map
(
value:
builtins.replaceStrings [".c"] [".o"]
(builtins.baseNameOf value)
)
files;
objects = builtins.map (
value: builtins.replaceStrings [ ".c" ] [ ".o" ] (builtins.baseNameOf value)
) files;
in
builders.kaem.build {
name = "gnumake-${cfg.version}";

View file

@ -36,7 +36,7 @@ in
description = "Platforms the package supports.";
default.value = [
"i686-linux"
"x86_64-linux"
"x86-64_linux"
];
};
};

View file

@ -1,13 +1,12 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage1.gnupatch;
builders = config.aux.foundation.builders;
stage1 = config.aux.foundation.stages.stage1;
in {
in
{
options.aux.foundation.stages.stage1.gnupatch = {
meta = {
description = lib.options.create {
@ -34,7 +33,7 @@ in {
description = "Platforms the package supports.";
default.value = [
"i686-linux"
"x86_64-linux"
"x86-64_linux"
];
};
};
@ -64,7 +63,8 @@ in {
sha256 = "12nv7jx3gxfp50y11nxzlnmqqrpicjggw6pcsq0wyavkkm3cddgc";
};
package = let
package =
let
# Thanks to the live-bootstrap project!
# https://github.com/fosslinux/live-bootstrap/blob/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/patch-2.5.9/mk/main.mk
cflags = [
@ -113,18 +113,14 @@ in {
"xmalloc.c"
];
sources =
files
++ [
sources = files ++ [
# mes-libc doesn't implement `error()`
"error.c"
];
objects =
builtins.map (
objects = builtins.map (
value: builtins.replaceStrings [ ".c" ] [ ".o" ] (builtins.baseNameOf value)
)
sources;
) sources;
in
builders.kaem.build {
name = "gnupatch-${cfg.version}";

View file

@ -1,13 +1,12 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage1.gnused.boot;
builders = config.aux.foundation.builders;
stage1 = config.aux.foundation.stages.stage1;
in {
in
{
options.aux.foundation.stages.stage1.gnused.boot = {
package = lib.options.create {
type = lib.types.derivation;
@ -34,7 +33,8 @@ in {
sha256 = "0006gk1dw2582xsvgx6y6rzs9zw8b36rhafjwm288zqqji3qfrf3";
};
package = let
package =
let
# Thanks to the live-bootstrap project!
# See https://github.com/fosslinux/live-bootstrap/blob/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/sed-4.0.9/sed-4.0.9.kaem
makefile = builtins.fetchurl {

View file

@ -1,14 +1,13 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage1.gnused;
platform = config.aux.platform;
builders = config.aux.foundation.builders;
stage1 = config.aux.foundation.stages.stage1;
in {
in
{
includes = [ ./boot.nix ];
options.aux.foundation.stages.stage1.gnused = {
@ -37,7 +36,7 @@ in {
description = "Platforms the package supports.";
default.value = [
"i686-linux"
"x86_64-linux"
"x86-64_linux"
];
};

View file

@ -39,7 +39,7 @@ in
description = "Platforms the package supports.";
default.value = [
"i686-linux"
"x86_64-linux"
"x86-64_linux"
];
};

View file

@ -33,7 +33,7 @@ in
description = "Platforms the package supports.";
default.value = [
"i686-linux"
"x86_64-linux"
"x86-64_linux"
];
};
};

View file

@ -1,7 +1,5 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage1.heirloom;
platform = config.aux.platform;
@ -9,7 +7,8 @@
stage1 = config.aux.foundation.stages.stage1;
stage2 = config.aux.foundation.stages.stage2;
in {
in
{
includes = [ ./devtools.nix ];
options.aux.foundation.stages.stage1.heirloom = {
@ -48,7 +47,7 @@ in {
description = "Platforms the package supports.";
default.value = [
"i686-linux"
"x86_64-linux"
"x86-64_linux"
];
};
};
@ -78,7 +77,8 @@ in {
sha256 = "6zP3C8wBmx0OCkHx11UtRcV6FicuThxIY07D5ESWow8=";
};
package = let
package =
let
patches = [
# we pre-generate nawk's proctab.c as meslibc is not capable of running maketab
# during build time (insufficient sscanf support)

View file

@ -1,7 +1,5 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage1.heirloom.devtools;
platform = config.aux.platform;
@ -10,7 +8,8 @@
stage0 = config.aux.foundation.stages.stage0;
stage1 = config.aux.foundation.stages.stage1;
stage2 = config.aux.foundation.stages.stage2;
in {
in
{
options.aux.foundation.stages.stage1.heirloom.devtools = {
package = lib.options.create {
type = lib.types.derivation;
@ -56,7 +55,7 @@ in {
description = "Platforms the package supports.";
default.value = [
"i686-linux"
"x86_64-linux"
"x86-64_linux"
];
};
};
@ -71,7 +70,8 @@ in {
sha256 = "9f233d8b78e4351fe9dd2d50d83958a0e5af36f54e9818521458a08e058691ba";
};
package = let
package =
let
# Thanks to the live-bootstrap project!
# See https://github.com/fosslinux/live-bootstrap/blob/d918b984ad6fe4fc7680f3be060fd82f8c9fddd9/sysa/heirloom-devtools-070527/heirloom-devtools-070527.kaem
liveBootstrap = "https://github.com/fosslinux/live-bootstrap/raw/d918b984ad6fe4fc7680f3be060fd82f8c9fddd9/sysa/heirloom-devtools-070527";

View file

@ -1,14 +1,13 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage1.linux-headers;
platform = config.aux.platform;
builders = config.aux.foundation.builders;
stage1 = config.aux.foundation.stages.stage1;
in {
in
{
options.aux.foundation.stages.stage1.linux-headers = {
meta = {
description = lib.options.create {
@ -29,7 +28,7 @@ in {
description = "Platforms the package supports.";
default.value = [
"i686-linux"
"x86_64-linux"
"x86-64_linux"
];
};
};

View file

@ -1,14 +1,13 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage1.ln-boot;
builders = config.aux.foundation.builders;
stage0 = config.aux.foundation.stages.stage0;
stage1 = config.aux.foundation.stages.stage1;
in {
in
{
options.aux.foundation.stages.stage1.ln-boot = {
meta = {
description = lib.options.create {
@ -35,7 +34,7 @@ in {
description = "Platforms the package supports.";
default.value = [
"i686-linux"
"x86_64-linux"
"x86-64_linux"
];
};
};

View file

@ -1,7 +1,5 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage1.mes.compiler;
system = config.aux.system;
@ -9,7 +7,8 @@
stage0 = config.aux.foundation.stages.stage0;
stage1 = config.aux.foundation.stages.stage1;
in {
in
{
options.aux.foundation.stages.stage1.mes.compiler = {
meta = {
description = lib.options.create {
@ -36,7 +35,7 @@ in {
description = "Platforms the package supports.";
default.value = [
"i686-linux"
"x86_64-linux"
"x86-64_linux"
];
};
};
@ -49,8 +48,11 @@ in {
config = {
aux.foundation.stages.stage1.mes.compiler = {
package = let
compile = path: let
package =
let
compile =
path:
let
file = builtins.baseNameOf path;
fileWithoutExtension = builtins.replaceStrings [ ".c" ] [ "" ] file;

View file

@ -1,12 +1,11 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage1.mes;
system = config.aux.system;
builders = config.aux.foundation.builders;
in {
in
{
includes = [
./compiler.nix
./libs.nix

View file

@ -1,13 +1,12 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage1.mes.libc;
builders = config.aux.foundation.builders;
stage1 = config.aux.foundation.stages.stage1;
in {
in
{
options.aux.foundation.stages.stage1.mes.libc = {
meta = {
description = lib.options.create {
@ -34,7 +33,7 @@ in {
description = "Platforms the package supports.";
default.value = [
"i686-linux"
"x86_64-linux"
"x86-64_linux"
];
};
};
@ -47,7 +46,8 @@ in {
config = {
aux.foundation.stages.stage1.mes.libc = {
package = let
package =
let
sources = import ./sources.nix;
libtcc1 = sources.x86.linux.gcc.libtcc1;

View file

@ -1,7 +1,5 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage1.mes.libs;
system = config.aux.system;
@ -9,7 +7,8 @@
stage0 = config.aux.foundation.stages.stage0;
stage1 = config.aux.foundation.stages.stage1;
in {
in
{
options.aux.foundation.stages.stage1.mes.libs = {
meta = {
description = lib.options.create {
@ -36,7 +35,7 @@ in {
description = "Platforms the package supports.";
default.value = [
"i686-linux"
"x86_64-linux"
"x86-64_linux"
];
};
};
@ -61,7 +60,8 @@ in {
aux.foundation.stages.stage1.mes.libs = {
prefix = "${cfg.src.out}/mes-${stage1.mes.version}";
src = let
src =
let
config_h = builtins.toFile "config.h" ''
#undef SYSTEM_LIBC
#define MES_VERSION "${stage1.mes.version}"
@ -143,8 +143,11 @@ in {
'';
};
package = let
compile = path: let
package =
let
compile =
path:
let
file = builtins.baseNameOf path;
fileWithoutExtension = builtins.replaceStrings [ ".c" ] [ "" ] file;
@ -174,10 +177,16 @@ in {
getSourcePath = suffix: source: "${source}/${source.name}${suffix}";
archive = destination: sources: "catm ${destination} ${lib.strings.concatMapSep " " (getSourcePath ".o") sources}";
source = destination: sources: "catm ${destination} ${lib.strings.concatMapSep " " (getSourcePath ".s") sources}";
archive =
destination: sources:
"catm ${destination} ${lib.strings.concatMapSep " " (getSourcePath ".o") sources}";
source =
destination: sources:
"catm ${destination} ${lib.strings.concatMapSep " " (getSourcePath ".s") sources}";
createLib = name: sources: let
createLib =
name: sources:
let
compiled = builtins.map compile sources;
in
builders.kaem.build {

View file

@ -18,9 +18,7 @@
"lib/mes/globals.c"
"lib/linux/x86-mes-mescc/syscall-internal.c"
];
libtcc1 = [
"lib/libtcc1.c"
];
libtcc1 = [ "lib/libtcc1.c" ];
libc = [
"lib/mes/__init_io.c"
"lib/mes/eputs.c"
@ -546,9 +544,7 @@
"lib/mes/globals.c"
"lib/linux/x86-mes-gcc/syscall-internal.c"
];
libtcc1 = [
"lib/libtcc1.c"
];
libtcc1 = [ "lib/libtcc1.c" ];
libc = [
"lib/mes/__init_io.c"
"lib/mes/eputs.c"

View file

@ -1,7 +1,5 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage1.nyacc;
builders = config.aux.foundation.builders;
@ -10,7 +8,8 @@
pname = "nyacc";
version = "1.00.2";
in {
in
{
options.aux.foundation.stages.stage1.nyacc = {
meta = {
description = lib.options.create {
@ -37,7 +36,7 @@ in {
description = "Platforms the package supports.";
default.value = [
"i686-linux"
"x86_64-linux"
"x86-64_linux"
];
};
};

View file

@ -34,7 +34,7 @@ in
description = "Platforms the package supports.";
default.value = [
"i686-linux"
"x86_64-linux"
"x86-64_linux"
];
};
};

View file

@ -1,7 +1,5 @@
args @ {
lib,
config,
}: let
args@{ lib, config }:
let
cfg = config.aux.foundation.stages.stage1.tinycc.boot;
builders = config.aux.foundation.builders;
@ -11,7 +9,8 @@ args @ {
pname = "tinycc-boot";
helpers = lib.fp.withDynamicArgs (import ./helpers.nix) args;
in {
in
{
options.aux.foundation.stages.stage1.tinycc.boot = {
meta = {
description = lib.options.create {
@ -36,7 +35,11 @@ in {
platforms = lib.options.create {
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = ["x86_64-linux" "i686-linux"];
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};
};
@ -66,8 +69,10 @@ in {
};
config = {
aux.foundation.stages.stage1.tinycc.boot = let
tinycc-boot = let
aux.foundation.stages.stage1.tinycc.boot =
let
tinycc-boot =
let
tinycc-mes-bootstrappable = helpers.createBoot {
pname = "tinycc-mes-bootstrappable";
version = stage1.tinycc.version;
@ -82,9 +87,7 @@ in {
"-D HAVE_LONG_LONG_STUB=1"
"-D HAVE_SETJMP=1"
];
lib.args = [
"-D HAVE_LONG_LONG_STUB=1"
];
lib.args = [ "-D HAVE_LONG_LONG_STUB=1" ];
boot = tinycc-mes-bootstrappable;
meta = cfg.meta;
};
@ -98,9 +101,7 @@ in {
"-D HAVE_LONG_LONG=1"
"-D HAVE_SETJMP=1"
];
lib.args = [
"-D HAVE_LONG_LONG=1"
];
lib.args = [ "-D HAVE_LONG_LONG=1" ];
boot = tinycc-boot0;
meta = cfg.meta;
};
@ -158,13 +159,15 @@ in {
boot = tinycc-boot3;
meta = cfg.meta;
};
in {
in
{
revision = "80114c4da6b17fbaabb399cc29f427e368309bc8";
libs.package = tinycc-boot.libs;
compiler.package = tinycc-boot.compiler;
src = let
src =
let
tarball = builtins.fetchurl {
url = "https://gitlab.com/janneke/tinycc/-/archive/${cfg.revision}/tinycc-${cfg.revision}.tar.gz";
sha256 = "1a0cw9a62qc76qqn5sjmp3xrbbvsz2dxrw21lrnx9q0s74mwaxbq";
@ -188,7 +191,8 @@ in {
replace --file libtcc.c --output libtcc.c --match-on "s->ms_extensions = 1;" --replace-with "s->ms_extensions = 1; s->static_link = 1;"
'';
};
in "${patched}/tinycc-${cfg.revision}";
in
"${patched}/tinycc-${cfg.revision}";
};
};
}

View file

@ -1,13 +1,12 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage1.tinycc;
builders = config.aux.foundation.builders;
stage1 = config.aux.foundation.stages.stage1;
in {
in
{
includes = [
./boot.nix
./mes.nix
@ -39,8 +38,8 @@ in {
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};
};

View file

@ -1,7 +1,5 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage1.tinycc.boot;
builders = config.aux.foundation.builders;
@ -9,11 +7,13 @@
stage1 = config.aux.foundation.stages.stage1;
cflags = stage1.mes.libc.package.extras.CFLAGS;
createBoot = {
createBoot =
{
pname,
version,
src,
}: let
}:
let
compiler = builders.kaem.build {
name = "${pname}-${version}";
@ -57,9 +57,13 @@
args = cflags;
tinycc = compiler;
};
in {inherit compiler libs;};
in
{
inherit compiler libs;
};
createTinyccMes = {
createTinyccMes =
{
pname,
version,
src,
@ -67,7 +71,8 @@
boot,
lib ? { },
meta,
}: let
}:
let
compiler = builders.kaem.build {
name = "${pname}-${version}";
@ -108,28 +113,33 @@
libs = createLibc {
inherit pname version src;
args =
builtins.concatStringsSep
" "
(
["-c" "-D" "TCC_TARGET_I386=1"]
args = builtins.concatStringsSep " " (
[
"-c"
"-D"
"TCC_TARGET_I386=1"
]
++ (lib.args or [ ])
);
tinycc = compiler;
};
in {
in
{
inherit compiler libs boot;
};
createLibc = {
createLibc =
{
pname,
version,
src,
args,
tinycc,
}: let
createLibrary = name: args: source:
}:
let
createLibrary =
name: args: source:
builders.kaem.build {
name = "${name}.a";
@ -167,10 +177,7 @@
cp ${libgetopt} ''${out}/lib/libgetopt.a
'';
};
in {
inherit
createBoot
createTinyccMes
createLibc
;
in
{
inherit createBoot createTinyccMes createLibc;
}

View file

@ -1,7 +1,5 @@
args @ {
lib,
config,
}: let
args@{ lib, config }:
let
cfg = config.aux.foundation.stages.stage1.tinycc.mes;
builders = config.aux.foundation.builders;
@ -11,7 +9,8 @@ args @ {
pname = "tinycc-mes";
helpers = lib.fp.withDynamicArgs (import ./helpers.nix) args;
in {
in
{
options.aux.foundation.stages.stage1.tinycc.mes = {
compiler = {
package = lib.options.create {
@ -39,8 +38,10 @@ in {
};
config = {
aux.foundation.stages.stage1.tinycc.mes = let
tinycc-mes = let
aux.foundation.stages.stage1.tinycc.mes =
let
tinycc-mes =
let
tccdefs = builders.kaem.build {
name = "tccdefs-${stage1.tinycc.version}";
@ -106,13 +107,15 @@ in {
boot = tinycc-mes-boot;
meta = stage1.tinycc.meta;
};
in {
in
{
revision = "86f3d8e33105435946383aee52487b5ddf918140";
libs.package = tinycc-mes.libs;
compiler.package = tinycc-mes.compiler;
src = let
src =
let
tarball = builtins.fetchurl {
url = "https://repo.or.cz/tinycc.git/snapshot/${cfg.revision}.tar.gz";
sha256 = "11idrvbwfgj1d03crv994mpbbbyg63j1k64lw1gjy7mkiifw2xap";
@ -136,7 +139,8 @@ in {
replace --file libtcc.c --output libtcc.c --match-on "s->ms_extensions = 1;" --replace-with "s->ms_extensions = 1; s->static_link = 1;"
'';
};
in "${patched}/tinycc-${builtins.substring 0 7 cfg.revision}";
in
"${patched}/tinycc-${builtins.substring 0 7 cfg.revision}";
};
};
}

View file

@ -1,7 +1,5 @@
args @ {
lib,
config,
}: let
args@{ lib, config }:
let
cfg = config.aux.foundation.stages.stage1.tinycc.musl;
builders = config.aux.foundation.builders;
@ -11,7 +9,8 @@ args @ {
pname = "tinycc-musl";
helpers = lib.fp.withDynamicArgs (import ./helpers.nix) args;
in {
in
{
options.aux.foundation.stages.stage1.tinycc.musl = {
compiler = {
package = lib.options.create {
@ -39,7 +38,8 @@ in {
};
config = {
aux.foundation.stages.stage1.tinycc.musl = let
aux.foundation.stages.stage1.tinycc.musl =
let
patches = [
./patches/ignore-duplicate-symbols.patch
./patches/ignore-static-inside-array.patch
@ -141,7 +141,8 @@ in {
install -Dm444 libtcc1.a $out/lib/libtcc1.a
'';
};
in {
in
{
revision = "fd6d2180c5c801bb0b4c5dde27d61503059fc97d";
src = builtins.fetchurl {

View file

@ -36,8 +36,8 @@ in
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};
};

View file

@ -33,8 +33,8 @@ in
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};
};

View file

@ -33,8 +33,8 @@ in
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};

View file

@ -33,8 +33,8 @@ in
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};
};

View file

@ -1,7 +1,5 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage2.busybox;
platform = config.aux.platform;
@ -9,7 +7,8 @@
stage1 = config.aux.foundation.stages.stage1;
stage2 = config.aux.foundation.stages.stage2;
in {
in
{
options.aux.foundation.stages.stage2.busybox = {
meta = {
description = lib.options.create {
@ -35,8 +34,8 @@ in {
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};
};
@ -66,7 +65,8 @@ in {
sha256 = "uMwkyVdNgJ5yecO+NJeVxdXOtv3xnKcJ+AzeUOR94xQ=";
};
package = let
package =
let
patches = [ ./patches/busybox-in-store.patch ];
busyboxConfig = [

View file

@ -1,14 +1,13 @@
{
lib,
config,
}: let
{ lib, config }:
let
cfg = config.aux.foundation.stages.stage2.bzip2;
platform = config.aux.platform;
builders = config.aux.foundation.builders;
stage1 = config.aux.foundation.stages.stage1;
in {
in
{
options.aux.foundation.stages.stage2.bzip2 = {
meta = {
description = lib.options.create {
@ -35,8 +34,8 @@ in {
description = "Platforms the package supports.";
# TODO: Support more platforms.
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};
};

View file

@ -33,8 +33,8 @@ in
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};
};

View file

@ -1,9 +1,8 @@
{
lib,
config,
}: let
{ lib, config }:
let
stage2 = config.aux.foundation.stages.stage2;
in {
in
{
includes = [
./bash
./binutils

View file

@ -33,8 +33,8 @@ in
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};
};

View file

@ -33,8 +33,8 @@ in
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};
};

View file

@ -33,8 +33,8 @@ in
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};

View file

@ -33,8 +33,8 @@ in
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};
};

View file

@ -34,8 +34,8 @@ in
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};
};

View file

@ -33,8 +33,8 @@ in
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};

View file

@ -34,8 +34,8 @@ in
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};
};

View file

@ -33,8 +33,8 @@ in
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};
};

View file

@ -33,8 +33,8 @@ in
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};

View file

@ -33,8 +33,8 @@ in
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};

View file

@ -33,8 +33,8 @@ in
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};
};

View file

@ -34,8 +34,8 @@ in
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = [
"x86_64-linux"
"i686-linux"
"x86-64_linux"
];
};
};

View file

@ -1,4 +1,5 @@
{lib}: {
{ lib }:
{
options.aux = {
system = lib.options.create {
type = lib.types.string;

View file

@ -25,53 +25,50 @@ let
./src/versions/default.test.nix
];
resolve = file: let
resolve =
file:
let
imported = import file;
value =
if builtins.isFunction imported
then imported {inherit lib;}
else imported;
value = if builtins.isFunction imported then imported { inherit lib; } else imported;
relative = lib.strings.removePrefix (builtins.toString root) (builtins.toString file);
in {
in
{
inherit file value;
relative =
if lib.strings.hasPrefix "/" relative
then "." + relative
else relative;
relative = if lib.strings.hasPrefix "/" relative then "." + relative else relative;
namespace = getNamespace file;
};
resolved = builtins.map resolve files;
getNamespace = path: let
getNamespace =
path:
let
relative = lib.strings.removePrefix (builtins.toString root) (builtins.toString path);
parts = lib.strings.split "/" relative;
in
if builtins.length parts > 2
then builtins.elemAt parts 2
else relative;
if builtins.length parts > 2 then builtins.elemAt parts 2 else relative;
results = let
getTests = file: prefix: suite: let
results =
let
getTests =
file: prefix: suite:
let
nested = lib.attrs.mapToList (name: value: getTests file (prefix ++ [ name ]) value) suite;
relative = lib.strings.removePrefix (builtins.toString root) (builtins.toString file);
in
if builtins.isAttrs suite
then builtins.concatLists nested
else [
if builtins.isAttrs suite then
builtins.concatLists nested
else
[
{
inherit prefix file;
name = builtins.concatStringsSep " > " prefix;
value = suite;
relative =
if lib.strings.hasPrefix "/" relative
then "." + relative
else relative;
relative = if lib.strings.hasPrefix "/" relative then "." + relative else relative;
}
];
base =
builtins.map (entry: getTests entry.file [entry.namespace] entry.value) resolved;
base = builtins.map (entry: getTests entry.file [ entry.namespace ] entry.value) resolved;
in
builtins.concatLists base;
@ -80,29 +77,23 @@ let
total = "${builtins.toString (builtins.length successes)} / ${builtins.toString (builtins.length results)}";
in
if failures == []
then let
message =
lib.strings.concatMapSep "\n"
(test: " ${test.name}")
successes;
in ''
if failures == [ ] then
let
message = lib.strings.concatMapSep "\n" (test: " ${test.name}") successes;
in
''
SUCCESS (${total})
${message}
''
else let
successMessage =
lib.strings.concatMapSep "\n"
(test: " ${test.name}")
successes;
failureMessage =
lib.strings.concatMapSep "\n\n"
(test:
" ${test.name}\n"
+ " -> ${test.relative}")
failures;
in ''
else
let
successMessage = lib.strings.concatMapSep "\n" (test: " ${test.name}") successes;
failureMessage = lib.strings.concatMapSep "\n\n" (
test: " ${test.name}\n" + " -> ${test.relative}"
) failures;
in
''
FAILURE (${total})
${failureMessage}

View file

@ -1,7 +1,5 @@
{
description = "A NixPkgs library replacement containing helper functions and a module system.";
outputs = _: {
lib = import ./src;
};
outputs = _: { lib = import ./src; };
}

View file

@ -10,66 +10,76 @@ lib: {
## from `y` first if it exists and then `x` otherwise.
##
## @type Attrs a b c => (String -> Any -> Any -> Bool) -> a -> b -> c
mergeRecursiveUntil = predicate: x: y: let
process = path:
mergeRecursiveUntil =
predicate: x: y:
let
process =
path:
builtins.zipAttrsWith (
name: values: let
name: values:
let
currentPath = path ++ [ name ];
isSingleValue = builtins.length values == 1;
isComplete =
predicate currentPath
(builtins.elemAt values 1)
(builtins.elemAt values 0);
isComplete = predicate currentPath (builtins.elemAt values 1) (builtins.elemAt values 0);
in
if isSingleValue
then builtins.elemAt values 0
else if isComplete
then builtins.elemAt values 1
else process currentPath values
if isSingleValue then
builtins.elemAt values 0
else if isComplete then
builtins.elemAt values 1
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`
## otherwise.
##
## @type Attrs a b c => a -> b -> c
mergeRecursive =
lib.attrs.mergeRecursiveUntil
(path: x: y:
!(builtins.isAttrs x && builtins.isAttrs y));
mergeRecursive = lib.attrs.mergeRecursiveUntil (
path: x: y:
!(builtins.isAttrs x && builtins.isAttrs y)
);
## Get a value from an attribute set by a path. If the path does not exist,
## a fallback value will be returned instead.
##
## @type (List String) -> a -> Attrs -> a | b
select = path: fallback: target: let
select =
path: fallback: target:
let
name = builtins.head path;
rest = builtins.tail path;
in
if path == []
then target
else if target ? ${name}
then lib.attrs.select rest fallback target.${name}
else fallback;
if path == [ ] then
target
else if target ? ${name} then
lib.attrs.select rest fallback target.${name}
else
fallback;
## Get a value from an attribute set by a path. If the path does not exist,
## an error will be thrown.
##
## @type (List String) -> Attrs -> a
selectOrThrow = path: target: let
selectOrThrow =
path: target:
let
pathAsString = builtins.concatStringsSep "." path;
error = builtins.throw "Path not found in attribute set: ${pathAsString}";
in
if lib.attrs.has path target
then lib.attrs.select path null target
else error;
if lib.attrs.has path target then lib.attrs.select path null target else error;
## Zip specific attributes from a list of attribute sets.
##
## @type List String -> (List Any -> Any) -> List Attrs -> Attrs
zipWithNames = names: f: list: let
zipWithNames =
names: f: list:
let
transform = name: {
inherit name;
value = f name (builtins.catAttrs name list);
@ -81,18 +91,26 @@ lib: {
## Match an attribute set against a pattern.
##
## @type Attrs -> Attrs -> Bool
match = pattern: value: let
process = name: values: let
match =
pattern: value:
let
process =
name: values:
let
first = builtins.elemAt values 0;
second = builtins.elemAt values 1;
in
if builtins.length values == 1
then false
else if builtins.isAttrs first
then builtins.isAttrs second && lib.attrs.match first second
else first == second;
if builtins.length values == 1 then
false
else if builtins.isAttrs first then
builtins.isAttrs second && lib.attrs.match first second
else
first == second;
result = lib.attrs.zipWithNames (builtins.attrNames pattern) process [pattern value];
result = lib.attrs.zipWithNames (builtins.attrNames pattern) process [
pattern
value
];
in
assert lib.errors.trace (builtins.isAttrs pattern) "Pattern must be an attribute set";
assert lib.errors.trace (builtins.isAttrs value) "Value must be an attribute set";
@ -101,62 +119,62 @@ lib: {
## Create a nested attribute set with a value as the leaf node.
##
## @type (List String) -> a -> Attrs
set = path: value: let
set =
path: value:
let
length = builtins.length path;
process = depth:
if depth == length
then value
else {
${builtins.elemAt path depth} = process (depth + 1);
};
process =
depth: if depth == length then value else { ${builtins.elemAt path depth} = process (depth + 1); };
in
process 0;
## Check if a path exists in an attribute set.
##
## @type (List String) -> Attrs -> Bool
has = path: target: let
has =
path: target:
let
name = builtins.head path;
rest = builtins.tail path;
in
if path == []
then true
else if target ? ${name}
then lib.attrs.has rest target.${name}
else false;
if path == [ ] then
true
else if target ? ${name} then
lib.attrs.has rest target.${name}
else
false;
## Depending on a given condition, either use the given value or an empty
## attribute set.
##
## @type Attrs a b => Bool -> a -> a | b
when = condition: value:
if condition
then value
else {};
when = condition: value: if condition then value else { };
## Map an attribute set's names and values to a list.
##
## @type Any a => (String -> Any -> a) -> Attrs -> List a
mapToList = f: target:
builtins.map (name: f name target.${name}) (builtins.attrNames target);
mapToList = f: target: builtins.map (name: f name target.${name}) (builtins.attrNames target);
## Map an attribute set recursively. Only non-set leaf nodes will be mapped.
##
## @type (List String -> Any -> Any) -> Attrs -> Attrs
mapRecursive = f: target:
lib.attrs.mapRecursiveWhen (lib.fp.const true) f target;
mapRecursive = f: target: lib.attrs.mapRecursiveWhen (lib.fp.const true) f target;
## Map an attribute set recursively when a given predicate returns true.
## Only leaf nodes according to the predicate will be mapped.
##
## @type (Attrs -> Bool) -> (List String -> Any -> Any) -> Attrs -> Attrs
mapRecursiveWhen = predicate: f: target: let
process = path:
mapRecursiveWhen =
predicate: f: target:
let
process =
path:
builtins.mapAttrs (
name: value:
if builtins.isAttrs value && predicate value
then process (path ++ [name]) value
else f (path ++ [name]) value
if builtins.isAttrs value && predicate value then
process (path ++ [ name ]) value
else
f (path ++ [ name ]) value
);
in
process [ ] target;
@ -165,14 +183,16 @@ lib: {
## on the base level of the attribute set.
##
## @type (String -> Any -> Bool) -> Attrs -> Attrs
filter = predicate: target: let
filter =
predicate: target:
let
names = builtins.attrNames target;
process = name: let
process =
name:
let
value = target.${name};
in
if predicate name value
then [{inherit name value;}]
else [];
if predicate name value then [ { inherit name value; } ] else [ ];
valid = builtins.concatMap process names;
in
builtins.listToAttrs valid;
@ -181,13 +201,13 @@ lib: {
## applied to each name.
##
## @type (List String) -> (String -> Any) -> Attrs
generate = names: f: let
pairs =
builtins.map (name: {
generate =
names: f:
let
pairs = builtins.map (name: {
inherit name;
value = f name;
})
names;
}) names;
in
builtins.listToAttrs pairs;
};

View file

@ -1,8 +1,10 @@
let
lib = import ./../default.nix;
in {
in
{
"merge" = {
"merges two shallow sets" = let
"merges two shallow sets" =
let
expected = {
x = 1;
y = 2;
@ -12,7 +14,8 @@ in {
in
expected == actual;
"overwrites values from the first set" = let
"overwrites values from the first set" =
let
expected = {
x = 2;
};
@ -20,7 +23,8 @@ in {
in
actual == expected;
"does not merge nested sets" = let
"does not merge nested sets" =
let
expected = {
x.y = 2;
};
@ -30,25 +34,29 @@ in {
};
"mergeRecursiveUntil" = {
"merges with predicate" = let
"merges with predicate" =
let
expected = {
x.y.z = 1;
};
actual =
lib.attrs.mergeRecursiveUntil
(path: x: y: lib.lists.last path == "z")
{x.y.z = 2;}
{x.y.z = 1;};
actual = lib.attrs.mergeRecursiveUntil (
path: x: y:
lib.lists.last path == "z"
) { x.y.z = 2; } { x.y.z = 1; };
in
actual == expected;
"handles shallow merges" = let
"handles shallow merges" =
let
expected = {
x.y.z = 1;
};
actual =
lib.attrs.mergeRecursiveUntil
(path: x: y: true)
(
path: x: y:
true
)
{
x = {
y.z = 2;
@ -62,32 +70,30 @@ in {
};
"mergeRecursive" = {
"merges two sets deeply" = let
"merges two sets deeply" =
let
expected = {
x.y.z = 1;
};
actual =
lib.attrs.mergeRecursive
{x.y.z = 2;}
{x.y.z = 1;};
actual = lib.attrs.mergeRecursive { x.y.z = 2; } { x.y.z = 1; };
in
actual == expected;
};
"select" = {
"selects a nested value" = let
"selects a nested value" =
let
expected = "value";
actual =
lib.attrs.select
["x" "y" "z"]
null
{
x.y.z = expected;
};
actual = lib.attrs.select [
"x"
"y"
"z"
] null { x.y.z = expected; };
in
actual == expected;
"handles empty path" = let
"handles empty path" =
let
expected = {
x = {
y = {
@ -95,11 +101,7 @@ in {
};
};
};
actual =
lib.attrs.select
[]
null
{
actual = lib.attrs.select [ ] null {
x = {
y = {
z = 1;
@ -109,30 +111,32 @@ in {
in
actual == expected;
"handles fallback value" = let
"handles fallback value" =
let
expected = "fallback";
actual =
lib.attrs.select
["x" "y" "z"]
expected
{};
actual = lib.attrs.select [
"x"
"y"
"z"
] expected { };
in
actual == expected;
};
"selectOrThrow" = {
"selects a nested value" = let
"selects a nested value" =
let
expected = "value";
actual =
lib.attrs.selectOrThrow
["x" "y" "z"]
{
x.y.z = expected;
};
actual = lib.attrs.selectOrThrow [
"x"
"y"
"z"
] { x.y.z = expected; };
in
actual == expected;
"handles empty path" = let
"handles empty path" =
let
expected = {
x = {
y = {
@ -140,10 +144,7 @@ in {
};
};
};
actual =
lib.attrs.selectOrThrow
[]
{
actual = lib.attrs.selectOrThrow [ ] {
x = {
y = {
z = 1;
@ -153,11 +154,13 @@ in {
in
actual == expected;
"throws on nonexistent path" = let
actual =
lib.attrs.selectOrThrow
["x" "y" "z"]
{};
"throws on nonexistent path" =
let
actual = lib.attrs.selectOrThrow [
"x"
"y"
"z"
] { };
evaluated = builtins.tryEval (builtins.deepSeq actual actual);
in
@ -165,7 +168,8 @@ in {
};
"set" = {
"creates a nested set" = let
"creates a nested set" =
let
expected = {
x = {
y = {
@ -173,11 +177,16 @@ in {
};
};
};
actual = lib.attrs.set ["x" "y" "z"] 1;
actual = lib.attrs.set [
"x"
"y"
"z"
] 1;
in
actual == expected;
"handles empty path" = let
"handles empty path" =
let
expected = 1;
actual = lib.attrs.set [ ] 1;
in
@ -185,30 +194,43 @@ in {
};
"has" = {
"returns true for a nested value" = let
exists = lib.attrs.has ["x" "y" "z"] {x.y.z = 1;};
"returns true for a nested value" =
let
exists = lib.attrs.has [
"x"
"y"
"z"
] { x.y.z = 1; };
in
exists;
"returns false for a nonexistent value" = let
exists = lib.attrs.has ["x" "y" "z"] {};
"returns false for a nonexistent value" =
let
exists = lib.attrs.has [
"x"
"y"
"z"
] { };
in
!exists;
"handles empty path" = let
"handles empty path" =
let
exists = lib.attrs.has [ ] { };
in
exists;
};
"when" = {
"returns the value when condition is true" = let
"returns the value when condition is true" =
let
expected = "value";
actual = lib.attrs.when true expected;
in
actual == expected;
"returns an empty set when condition is false" = let
"returns an empty set when condition is false" =
let
expected = { };
actual = lib.attrs.when false "value";
in
@ -216,7 +238,8 @@ in {
};
"mapToList" = {
"converts a set to a list" = let
"converts a set to a list" =
let
expected = [
{
name = "x";
@ -227,10 +250,7 @@ in {
value = 2;
}
];
actual =
lib.attrs.mapToList
(name: value: {inherit name value;})
{
actual = lib.attrs.mapToList (name: value: { inherit name value; }) {
x = 1;
y = 2;
};
@ -239,7 +259,8 @@ in {
};
"mapRecursiveWhen" = {
"maps a set recursively" = let
"maps a set recursively" =
let
expected = {
x = {
y = {
@ -247,11 +268,7 @@ in {
};
};
};
actual =
lib.attrs.mapRecursiveWhen
(value: true)
(path: value: value + 1)
{
actual = lib.attrs.mapRecursiveWhen (value: true) (path: value: value + 1) {
x = {
y = {
z = 1;
@ -261,7 +278,8 @@ in {
in
actual == expected;
"maps a set given a condition" = let
"maps a set given a condition" =
let
expected = {
x = {
y = {
@ -270,13 +288,12 @@ in {
};
};
actual =
lib.attrs.mapRecursiveWhen
(value: !(value ? z))
(path: value:
lib.attrs.mapRecursiveWhen (value: !(value ? z))
(
path: value:
# We map before we get to a non-set value
if builtins.isAttrs value
then value
else value + 1)
if builtins.isAttrs value then value else value + 1
)
{
x = {
y = {
@ -289,7 +306,8 @@ in {
};
"mapRecursive" = {
"maps a set recursively" = let
"maps a set recursively" =
let
expected = {
x = {
y = {
@ -297,10 +315,7 @@ in {
};
};
};
actual =
lib.attrs.mapRecursive
(path: value: value + 1)
{
actual = lib.attrs.mapRecursive (path: value: value + 1) {
x = {
y = {
z = 1;
@ -312,14 +327,12 @@ in {
};
"filter" = {
"filters a set" = let
"filters a set" =
let
expected = {
y = 2;
};
actual =
lib.attrs.filter
(name: value: name == "y")
{
actual = lib.attrs.filter (name: value: name == "y") {
x = 1;
y = 2;
};

View file

@ -4,28 +4,21 @@ lib: {
## Convert a boolean value into a string.
##
## @type Bool -> String
string = value:
if value
then "true"
else "false";
string = value: if value then "true" else "false";
## Convert a boolean into either the string "yes" or "no".
##
## @type Bool -> String
yesno = value:
if value
then "yes"
else "no";
yesno = value: if value then "yes" else "no";
};
## Choose between two values based on a condition. When true, the first value
## is returned, otherwise the second value is returned.
##
## @type Bool -> a -> b -> a | b
when = condition: x: y:
if condition
then x
else y;
when =
condition: x: y:
if condition then x else y;
## Perform a logical AND operation on two values.
##
@ -35,9 +28,7 @@ lib: {
## Perform a logical AND operation on two functions being applied to a value.
##
## @type (a -> Bool) -> (a -> Bool) -> a -> Bool
and' = f: g: (
x: (f x) && (g x)
);
and' = f: g: (x: (f x) && (g x));
## Perform a logical OR operation on two values.
##
@ -47,9 +38,7 @@ lib: {
## Perform a logical OR operation on two functions being applied to a value.
##
## @type (a -> Bool) -> (a -> Bool) -> a -> Bool
or' = f: g: (
x: (f x) || (g x)
);
or' = f: g: (x: (f x) || (g x));
## Perform a logical NOT operation on a value.
##

View file

@ -1,15 +1,18 @@
let
lib = import ./../default.nix;
in {
in
{
"into" = {
"string" = {
"handles true" = let
"handles true" =
let
expected = "true";
actual = lib.bools.into.string true;
in
actual == expected;
"handles false" = let
"handles false" =
let
expected = "false";
actual = lib.bools.into.string false;
in
@ -17,12 +20,14 @@ in {
};
"yesno" = {
"handles true" = let
"handles true" =
let
expected = "yes";
actual = lib.bools.into.yesno true;
in
actual == expected;
"handles false" = let
"handles false" =
let
expected = "no";
actual = lib.bools.into.yesno false;
in
@ -31,13 +36,15 @@ in {
};
"when" = {
"returns first value when true" = let
"returns first value when true" =
let
expected = "foo";
actual = lib.bools.when true expected "bar";
in
actual == expected;
"returns second value when false" = let
"returns second value when false" =
let
expected = "bar";
actual = lib.bools.when false "foo" expected;
in
@ -45,51 +52,61 @@ in {
};
"and" = {
"returns true when both are true" = let
"returns true when both are true" =
let
expected = true;
actual = lib.bools.and true true;
in
actual == expected;
"returns false when first is false" = let
"returns false when first is false" =
let
expected = false;
actual = lib.bools.and false true;
in
actual == expected;
"returns false when second is false" = let
"returns false when second is false" =
let
expected = false;
actual = lib.bools.and true false;
in
actual == expected;
"returns false when both are false" = let
"returns false when both are false" =
let
expected = false;
actual = lib.bools.and false false;
in
actual == expected;
};
"and'" = let
"and'" =
let
getTrue = _: true;
getFalse = _: false;
in {
"returns true when both are true" = let
in
{
"returns true when both are true" =
let
expected = true;
actual = lib.bools.and' getTrue getTrue null;
in
actual == expected;
"returns false when first is false" = let
"returns false when first is false" =
let
expected = false;
actual = lib.bools.and' getFalse getTrue null;
in
actual == expected;
"returns false when second is false" = let
"returns false when second is false" =
let
expected = false;
actual = lib.bools.and' getTrue getFalse null;
in
actual == expected;
"returns false when both are false" = let
"returns false when both are false" =
let
expected = false;
actual = lib.bools.and' getFalse getFalse null;
in
@ -97,48 +114,58 @@ in {
};
"or" = {
"returns true when both are true" = let
"returns true when both are true" =
let
expected = true;
actual = lib.bools.or true true;
in
actual == expected;
"returns true when first is true" = let
"returns true when first is true" =
let
expected = true;
actual = lib.bools.or true false;
in
actual == expected;
"returns true when second is true" = let
"returns true when second is true" =
let
expected = true;
actual = lib.bools.or false true;
in
actual == expected;
"returns false when both are false" = let
"returns false when both are false" =
let
expected = false;
actual = lib.bools.or false false;
in
actual == expected;
};
"or'" = let
"or'" =
let
getTrue = _: true;
getFalse = _: false;
in {
"returns true when both are true" = let
in
{
"returns true when both are true" =
let
expected = true;
actual = lib.bools.or' getTrue getTrue null;
in
actual == expected;
"returns true when first is true" = let
"returns true when first is true" =
let
expected = true;
actual = lib.bools.or' getTrue getFalse null;
in
actual == expected;
"returns true when second is true" = let
"returns true when second is true" =
let
expected = true;
actual = lib.bools.or' getFalse getTrue null;
in
actual == expected;
"returns false when both are false" = let
"returns false when both are false" =
let
expected = false;
actual = lib.bools.or' getFalse getFalse null;
in
@ -146,13 +173,15 @@ in {
};
"not" = {
"returns false when true" = let
"returns false when true" =
let
expected = false;
actual = lib.bools.not true;
in
actual == expected;
"returns true when false" = let
"returns true when false" =
let
expected = true;
actual = lib.bools.not false;
in

View file

@ -4,31 +4,30 @@ lib: {
## Check that a value is a DAG entry.
##
## @type a -> Bool
entry = value:
(value ? value)
&& (value ? before)
&& (value ? after);
entry = value: (value ? value) && (value ? before) && (value ? after);
## Check that a value is a DAG.
##
## @type a -> Bool
graph = value: let
graph =
value:
let
isContentsValid = builtins.all lib.dag.validate.entry (builtins.attrValues value);
in
builtins.isAttrs value
&& isContentsValid;
builtins.isAttrs value && isContentsValid;
};
sort = {
## Apply a topological sort to a DAG.
##
## @type Dag a -> { result :: List a } | { cycle :: List a, loops :: List a }
topographic = graph: let
getEntriesBefore = graph: name: let
before =
lib.attrs.filter
(key: value: builtins.elem name value.before)
graph;
topographic =
graph:
let
getEntriesBefore =
graph: name:
let
before = lib.attrs.filter (key: value: builtins.elem name value.before) graph;
in
builtins.attrNames before;
@ -46,16 +45,15 @@ lib: {
sorted = lib.lists.sort.topographic isBefore entries;
in
if sorted ? result
then {
result =
builtins.map (value: {
if sorted ? result then
{
result = builtins.map (value: {
name = value.name;
value = value.value;
})
sorted.result;
}) sorted.result;
}
else sorted;
else
sorted;
};
apply = {
@ -63,15 +61,14 @@ lib: {
## and any entries that do exist are given the appropriate `before` and `after` values.
##
## @type Dag a -> Dag a -> Dag a
defaults = graph: defaults: let
result =
builtins.mapAttrs
(
defaults =
graph: defaults:
let
result = builtins.mapAttrs (
name: entry:
if defaults ? ${name}
then
if builtins.isString entry
then {
if defaults ? ${name} then
if builtins.isString entry then
{
value = entry;
before = defaults.${name}.before or [ ];
after = defaults.${name}.after or [ ];
@ -82,9 +79,9 @@ lib: {
before = (entry.before or [ ]) ++ (defaults.${name}.before or [ ]);
after = (entry.after or [ ]) ++ (defaults.${name}.after or [ ]);
}
else entry
)
graph;
else
entry
) graph;
in
defaults // result;
};
@ -92,21 +89,13 @@ lib: {
## Map over the entries in a DAG and modify their values.
##
## @type (String -> a -> b) -> Dag a -> Dag b
map = f:
builtins.mapAttrs
(name: value:
value
// {
value = f name value.value;
});
map = f: builtins.mapAttrs (name: value: value // { value = f name value.value; });
entry = {
## Create a new DAG entry.
##
## @type List String -> List String -> a -> { before :: List String, after :: List String, value :: a }
between = before: after: value: {
inherit before after value;
};
between = before: after: value: { inherit before after value; };
## Create a new DAG entry with no dependencies.
##
@ -128,25 +117,22 @@ lib: {
## Create a DAG from a list of entries, prefixed with a tag.
##
## @type String -> List String -> List String -> List a -> Dag a
between = tag: let
process = i: before: after: entries: let
between =
tag:
let
process =
i: before: after: entries:
let
name = "${tag}-${builtins.toString i}";
entry = builtins.head entries;
rest = builtins.tail entries;
in
if builtins.length entries == 0
then {}
else if builtins.length entries == 1
then {
"${name}" = lib.dag.entry.between before after entry;
}
if builtins.length entries == 0 then
{ }
else if builtins.length entries == 1 then
{ "${name}" = lib.dag.entry.between before after entry; }
else
{
"${name}" = lib.dag.entry.after after entry;
}
// (
process (i + 1) before [name] rest
);
{ "${name}" = lib.dag.entry.after after entry; } // (process (i + 1) before [ name ] rest);
in
process 0;

View file

@ -1,15 +1,18 @@
let
lib = import ./../default.nix;
in {
in
{
"validate" = {
"entry" = {
"invalid value" = let
"invalid value" =
let
expected = false;
actual = lib.dag.validate.entry { };
in
actual == expected;
"a manually created value" = let
"a manually created value" =
let
expected = true;
actual = lib.dag.validate.entry {
value = null;
@ -19,25 +22,29 @@ in {
in
actual == expected;
"entry.between" = let
"entry.between" =
let
expected = true;
actual = lib.dag.validate.entry (lib.dag.entry.between [ ] [ ] null);
in
actual == expected;
"entry.anywhere" = let
"entry.anywhere" =
let
expected = true;
actual = lib.dag.validate.entry (lib.dag.entry.anywhere null);
in
actual == expected;
"entry.before" = let
"entry.before" =
let
expected = true;
actual = lib.dag.validate.entry (lib.dag.entry.before [ ] null);
in
actual == expected;
"entry.after" = let
"entry.after" =
let
expected = true;
actual = lib.dag.validate.entry (lib.dag.entry.after [ ] null);
in
@ -45,15 +52,15 @@ in {
};
"graph" = {
"invalid value" = let
"invalid value" =
let
expected = false;
actual = lib.dag.validate.graph {
x = {};
};
actual = lib.dag.validate.graph { x = { }; };
in
actual == expected;
"a manually created value" = let
"a manually created value" =
let
expected = true;
actual = lib.dag.validate.graph {
x = {
@ -65,30 +72,46 @@ in {
in
actual == expected;
"entries.between" = let
"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;
"entries.anywhere" = let
"entries.anywhere" =
let
expected = true;
graph = lib.dag.entries.anywhere "example" [null null];
graph = lib.dag.entries.anywhere "example" [
null
null
];
actual = lib.dag.validate.graph graph;
in
actual == expected;
"entries.before" = let
"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;
"entries.after" = let
"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;
@ -97,13 +120,15 @@ in {
"sort" = {
"topographic" = {
"handles an empty graph" = let
"handles an empty graph" =
let
expected = [ ];
actual = lib.dag.sort.topographic { };
in
actual.result == expected;
"sorts a graph" = let
"sorts a graph" =
let
expected = [
{
name = "a";

View file

@ -29,7 +29,9 @@ let
## definitions.
##
## @type (a -> a) -> a
fix = f: let
fix =
f:
let
x = f x;
in
x;
@ -39,38 +41,40 @@ let
## from `y` first if it exists and then `x` otherwise.
##
## @type Attrs a b c => (String -> Any -> Any -> Bool) -> a -> b -> c
mergeAttrsRecursiveUntil = predicate: x: y: let
process = path:
mergeAttrsRecursiveUntil =
predicate: x: y:
let
process =
path:
builtins.zipAttrsWith (
name: values: let
name: values:
let
currentPath = path ++ [ name ];
isSingleValue = builtins.length values == 1;
isComplete =
predicate currentPath
(builtins.elemAt values 1)
(builtins.elemAt values 0);
isComplete = predicate currentPath (builtins.elemAt values 1) (builtins.elemAt values 0);
in
if isSingleValue || isComplete
then builtins.elemAt values 0
else process currentPath values
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`
## otherwise.
##
## @type Attrs a b c => a -> b -> c
mergeAttrsRecursive =
mergeAttrsRecursiveUntil
(path: x: y:
!(builtins.isAttrs x && builtins.isAttrs y));
mergeAttrsRecursive = mergeAttrsRecursiveUntil (
path: x: y:
!(builtins.isAttrs x && builtins.isAttrs y)
);
lib = fix (
self: let
merge = acc: create:
mergeAttrsRecursive acc (create self);
self:
let
merge = acc: create: mergeAttrsRecursive acc (create self);
in
builtins.foldl' merge { } libs
);

View file

@ -1,18 +1,22 @@
let
lib = import ./../default.nix;
in {
in
{
"extend" = {
"lib is extensible" = let
result = lib.extend (final: prev: prev // {
"lib is extensible" =
let
result = lib.extend (
final: prev:
prev
// {
__injected__ = true;
fp = prev.fp // {
__injected__ = true;
};
});
}
);
in
result ? __injected__
&& result.fp ? __injected__
&& result.fp ? const;
result ? __injected__ && result.fp ? __injected__ && result.fp ? const;
};
}

View file

@ -5,9 +5,6 @@ lib: {
##
## @notest
## @type Bool -> String -> Bool
trace = condition: message:
if condition
then true
else builtins.trace message false;
trace = condition: message: if condition then true else builtins.trace message false;
};
}

View file

@ -1,3 +1,4 @@
let
lib = import ./../default.nix;
in {}
in
{ }

Some files were not shown because too many files have changed in this diff Show more