refactor: code cleanup, move sources to separate module

This commit is contained in:
Jake Hamilton 2024-06-05 04:10:35 -07:00
parent d104903c16
commit 1642b2173b
Signed by: jakehamilton
GPG key ID: 9762169A1B35EA68
23 changed files with 314 additions and 277 deletions

View file

@ -3,7 +3,7 @@
"lib": {
"locked": {
"lastModified": 1,
"narHash": "sha256-303zkU+ntdAF6JLE9gA3k5piX5RvKtQp6JXovZWzDdQ=",
"narHash": "sha256-wgO96O9ALMMXtfBKuh9rYo3KIVq4nk8V7Cke4dg0MOk=",
"path": "../lib",
"type": "path"
},

View file

@ -19,8 +19,6 @@
# "aarch64-darwin"
];
in {
modules.aux = modules;
packages = forEachSystem (
system: let
result = lib.modules.run {

View file

@ -0,0 +1,35 @@
{
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 {
options.aux.foundation.stages.stage0.architecture = {
base = lib.options.create {
type = lib.types.string;
description = "The architecture to use for the source.";
default = {
value = architecture;
text = ''"AMD64" or "AArch64" or "x86"'';
};
};
m2libc = lib.options.create {
type = lib.types.string;
description = "The architecture to use for the M2libc source.";
default = {
value = lib.strings.lower architecture;
text = ''"amd64" or "aarch64" or "x86"'';
};
};
};
}

View file

@ -17,6 +17,9 @@
else builtins.throw "Unsupported system for stage0: ${system}";
in {
includes = [
./sources
./architecture
./phases/phase00.nix
./phases/phase01.nix
./phases/phase02.nix

View file

@ -3,20 +3,13 @@
config,
}: let
cfg = config.aux.foundation.stages.stage0.kaem;
hex0 = config.aux.foundation.stages.stage0.hex0;
catm = config.aux.foundation.stages.stage0.catm;
M0 = config.aux.foundation.stages.stage0.M0;
cc_arch = config.aux.foundation.stages.stage0.cc_arch;
M2 = config.aux.foundation.stages.stage0.M2;
blood-elf = config.aux.foundation.stages.stage0.blood-elf;
M1 = config.aux.foundation.stages.stage0.M1;
hex2 = config.aux.foundation.stages.stage0.hex2;
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;
system = config.aux.system;
builders = config.aux.foundation.builders;
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 {
options.aux.foundation.stages.stage0.kaem = {
package = lib.options.create {

View file

@ -16,6 +16,8 @@
system = config.aux.system;
builders = config.aux.foundation.builders;
sources = config.aux.foundation.stages.stage0.sources;
architecture = config.aux.foundation.stages.stage0.architecture;
in {
options.aux.foundation.stages.stage0.mescc-tools-extra = {
package = lib.options.create {
@ -68,10 +70,10 @@ in {
./build.kaem
];
src = hex0.mescc-tools-extra.src;
src = sources.mescc-tools-extra;
m2libcOS = "linux";
m2libcArch = hex0.m2libc.architecture;
m2libcArch = architecture.m2libc;
mesccTools = mescc-tools.package;
});
};

View file

@ -15,6 +15,8 @@
system = config.aux.system;
builders = config.aux.foundation.builders;
sources = config.aux.foundation.stages.stage0.sources;
architecture = config.aux.foundation.stages.stage0.architecture;
bloodFlag =
if config.aux.platform.bits == 64
@ -35,13 +37,13 @@
getExtraUtil = name: let
script = builtins.toFile "build-${name}.kaem" ''
''${M2} --architecture ${hex0.m2libc.architecture} \
''${M2} --architecture ${architecture.m2libc} \
-f ''${m2libc}/sys/types.h \
-f ''${m2libc}/stddef.h \
-f ''${m2libc}/${hex0.m2libc.architecture}/linux/fcntl.c \
-f ''${m2libc}/${architecture.m2libc}/linux/fcntl.c \
-f ''${m2libc}/fcntl.c \
-f ''${m2libc}/${hex0.m2libc.architecture}/linux/unistd.c \
-f ''${m2libc}/${hex0.m2libc.architecture}/linux/sys/stat.c \
-f ''${m2libc}/${architecture.m2libc}/linux/unistd.c \
-f ''${m2libc}/${architecture.m2libc}/linux/sys/stat.c \
-f ''${m2libc}/stdlib.c \
-f ''${m2libc}/stdio.h \
-f ''${m2libc}/stdio.c \
@ -53,17 +55,17 @@
''${blood-elf-0} ${endianFlag} ${bloodFlag} -f ${name}.M1 -o ${name}-footer.M1
''${M1} --architecture ${hex0.m2libc.architecture} \
''${M1} --architecture ${architecture.m2libc} \
${endianFlag} \
-f ''${m2libc}/${hex0.m2libc.architecture}/${hex0.m2libc.architecture}_defs.M1 \
-f ''${m2libc}/${hex0.m2libc.architecture}/libc-full.M1 \
-f ''${m2libc}/${architecture.m2libc}/${architecture.m2libc}_defs.M1 \
-f ''${m2libc}/${architecture.m2libc}/libc-full.M1 \
-f ${name}.M1 \
-f ${name}-footer.M1 \
-o ${name}.hex2
''${hex2} --architecture ${hex0.m2libc.architecture} \
''${hex2} --architecture ${architecture.m2libc} \
${endianFlag} \
-f ''${m2libc}/${hex0.m2libc.architecture}/ELF-${hex0.m2libc.architecture}-debug.hex2 \
-f ''${m2libc}/${architecture.m2libc}/ELF-${architecture.m2libc}-debug.hex2 \
-f ${name}.hex2 \
--base-address ${baseAddress} \
-o ''${out}
@ -85,16 +87,18 @@
script
];
src = hex0.src;
src = sources.base;
M1 = M1.package;
M2 = M2.package;
blood-elf-0 = blood-elf.package;
hex2 = hex2.package;
m2libc = hex0.m2libc.src;
m2planet = hex0.m2planet.src;
m2mesoplanet = hex0.m2mesoplanet.src;
mesccTools = hex0.mescc-tools.src;
mesccToolsExtra = hex0.mescc-tools-extra.src;
m2libc = sources.m2libc;
m2planet = sources.m2planet;
m2mesoplanet = sources.m2mesoplanet;
mesccTools = sources.mescc-tools;
mesccToolsExtra = sources.mescc-tools-extra;
bloodFlag = bloodFlag;
endianFlag = endianFlag;
@ -157,12 +161,12 @@ in {
blood-elf-0 = blood-elf.package;
hex2 = hex2.package;
m2libc = hex0.m2libc.src;
m2libcArch = hex0.m2libc.architecture;
m2planet = hex0.m2planet.src;
m2mesoplanet = hex0.m2mesoplanet.src;
mesccTools = hex0.mescc-tools.src;
mesccToolsExtra = hex0.mescc-tools-extra.src;
m2libc = sources.m2libc;
m2libcArch = architecture.m2libc;
m2planet = sources.m2planet;
m2mesoplanet = sources.m2mesoplanet;
mesccTools = sources.mescc-tools;
mesccToolsExtra = sources.mescc-tools-extra;
bloodFlag = bloodFlag;
endianFlag = endianFlag;

View file

@ -6,6 +6,7 @@
system = config.aux.system;
builders = config.aux.foundation.builders;
sources = config.aux.foundation.stages.stage0.sources;
architecture =
if system == "x86_64-linux"
@ -61,64 +62,6 @@ in {
type = lib.types.package;
description = "The derivation to use to build hex0.";
};
src = lib.options.create {
type = lib.types.string;
description = "The source for the hex0 build files.";
};
m2libc = {
src = lib.options.create {
type = lib.types.string;
description = "The source for the M2libc build files.";
};
architecture = lib.options.create {
type = lib.types.string;
description = "The architecture to use for the M2libc source.";
default = {
value = lib.strings.lower architecture;
text = ''"amd64" or "aarch64" or "x86"'';
};
};
};
m2planet = {
src = lib.options.create {
type = lib.types.string;
description = "The source for the M2-Planet build files.";
};
};
m2mesoplanet = {
src = lib.options.create {
type = lib.types.string;
description = "The source for the M2-MesoPlanet build files.";
};
};
mescc-tools = {
src = lib.options.create {
type = lib.types.string;
description = "The source for the mescc-tools build files.";
};
};
mescc-tools-extra = {
src = lib.options.create {
type = lib.types.string;
description = "The source for the mescc-tools-extra build files.";
};
};
architecture = lib.options.create {
type = lib.types.string;
description = "The architecture to use for the source.";
default = {
value = architecture;
text = ''"AMD64" or "AArch64" or "x86"'';
};
};
};
config = {
@ -132,7 +75,7 @@ in {
executable = cfg.executable;
args = [
"${cfg.src}/hex0_${architecture}.hex0"
"${sources.base}/hex0_${architecture}.hex0"
(builtins.placeholder "out")
];
@ -157,67 +100,6 @@ in {
executable = true;
hash = cfg.hash;
});
# All sources are combined a central repository via submodules. Due to potential quirks surrounding
# fetching that, we are instead fetching each submodule directly. The central repository is located
# here: https://github.com/oriansj/stage0-posix
src =
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
# 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
builtins.fetchTarball {
url = "https://github.com/oriansj/stage0-posix-x86/archive/e86bf7d304bae5ce5ccc88454bb60cf0837e941f.tar.gz";
sha256 = "1c1fk793yzq8zbg60n2zd22fsmirc3zr26fj0iskap456g84nxv8";
}
else builtins.throw "Unsupported architecture for stage0: ${architecture}";
m2libc = {
src = builtins.fetchTarball {
url = "https://github.com/oriansj/M2libc/archive/de7c75f144176c3b9be77695d9bf94440445aeae.tar.gz";
sha256 = "01k81zn8yx4jg6fbcjgkrf9rp074yikkmwqykdgi9143yfb2k3yv";
};
};
m2planet = {
src = builtins.fetchTarball {
url = "https://github.com/oriansj/M2-Planet/archive/51dc63b349ca13fa57b345964254cf26930c0a7d.tar.gz";
sha256 = "1kksk260dh6qd0dzgl9vgs67fs0lsxs9w0gniy0ii5fgmqxi8p65";
};
};
m2mesoplanet = {
src = builtins.fetchTarball {
url = "https://github.com/oriansj/M2-Mesoplanet/archive/c80645f06b035debaa08e95da3206346a9f61b97.tar.gz";
sha256 = "02vzqln38ylfnd88p87935yf26i60gkbv93ns5j7parqgyyz2kl4";
};
};
mescc-tools = {
src = builtins.fetchTarball {
url = "https://github.com/oriansj/mescc-tools/archive/5d37991e22d1e4147411a766f4410508ba872962.tar.gz";
sha256 = "1xgpqhc5diim3rr9a00939976svrbhfp4v5970548a137fdynl4c";
};
};
mescc-tools-extra = {
src = builtins.fetchTarball {
url = "https://github.com/oriansj/mescc-tools-extra/archive/c1bd4ab4c5b994d8167c1e6dfc14050dc151a911.tar.gz";
sha256 = "0v8vxn3a8rxbgi6vcw73jqkw9j5vg3qlvd4sxk2w0fpybjml8brd";
};
};
};
};
}

View file

@ -7,6 +7,8 @@
system = config.aux.system;
builders = config.aux.foundation.builders;
sources = config.aux.foundation.stages.stage0.sources;
architecture = config.aux.foundation.stages.stage0.architecture;
in {
options.aux.foundation.stages.stage0.hex1 = {
package = lib.options.create {
@ -53,7 +55,7 @@ in {
executable = hex0.package;
args = [
"${hex0.src}/hex1_${hex0.architecture}.hex0"
"${sources.base}/hex1_${architecture.base}.hex0"
(builtins.placeholder "out")
];
});

View file

@ -8,6 +8,8 @@
system = config.aux.system;
builders = config.aux.foundation.builders;
sources = config.aux.foundation.stages.stage0.sources;
architecture = config.aux.foundation.stages.stage0.architecture;
in {
options.aux.foundation.stages.stage0.hex2-0 = {
package = lib.options.create {
@ -54,7 +56,7 @@ in {
executable = hex1.package;
args = [
"${hex0.src}/hex2_${hex0.architecture}.hex1"
"${sources.base}/hex2_${architecture.base}.hex1"
(builtins.placeholder "out")
];
});

View file

@ -9,6 +9,8 @@
system = config.aux.system;
builders = config.aux.foundation.builders;
sources = config.aux.foundation.stages.stage0.sources;
architecture = config.aux.foundation.stages.stage0.architecture;
in {
options.aux.foundation.stages.stage0.catm = {
package = lib.options.create {
@ -53,18 +55,18 @@ in {
meta = cfg.meta;
executable =
if hex0.architecture == "AArch64"
if architecture.base == "AArch64"
then hex1.package
else hex2-0.package;
args =
if hex0.architecture == "AArch64"
if architecture.base == "AArch64"
then [
"${hex0.src}/catm_${hex0.architecture}.hex1"
"${sources.base}/catm_${architecture.base}.hex1"
(builtins.placeholder "out")
]
else [
"${hex0.src}/catm_${hex0.architecture}.hex2"
"${sources.base}/catm_${architecture.base}.hex2"
(builtins.placeholder "out")
];
});

View file

@ -9,6 +9,8 @@
system = config.aux.system;
builders = config.aux.foundation.builders;
sources = config.aux.foundation.stages.stage0.sources;
architecture = config.aux.foundation.stages.stage0.architecture;
in {
options.aux.foundation.stages.stage0.M0 = {
package = lib.options.create {
@ -65,8 +67,8 @@ in {
args = [
(builtins.placeholder "out")
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/ELF-${hex0.m2libc.architecture}.hex2"
"${hex0.src}/M0_${hex0.architecture}.hex2"
"${sources.m2libc}/${architecture.m2libc}/ELF-${architecture.m2libc}.hex2"
"${sources.base}/M0_${architecture.base}.hex2"
];
};
in [

View file

@ -10,6 +10,8 @@
system = config.aux.system;
builders = config.aux.foundation.builders;
sources = config.aux.foundation.stages.stage0.sources;
architecture = config.aux.foundation.stages.stage0.architecture;
in {
options.aux.foundation.stages.stage0.cc_arch = {
package = lib.options.create {
@ -65,7 +67,7 @@ in {
executable = M0.package;
args = [
"${hex0.src}/cc_${hex0.m2libc.architecture}.M1"
"${sources.base}/cc_${architecture.m2libc}.M1"
(builtins.placeholder "out")
];
};
@ -79,7 +81,7 @@ in {
args = [
(builtins.placeholder "out")
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/ELF-${hex0.m2libc.architecture}.hex2"
"${sources.m2libc}/${architecture.m2libc}/ELF-${architecture.m2libc}.hex2"
cc_arch0_hex2-0
];
};

View file

@ -11,6 +11,8 @@
system = config.aux.system;
builders = config.aux.foundation.builders;
sources = config.aux.foundation.stages.stage0.sources;
architecture = config.aux.foundation.stages.stage0.architecture;
in {
options.aux.foundation.stages.stage0.M2 = {
package = lib.options.create {
@ -67,16 +69,16 @@ in {
args = [
(builtins.placeholder "out")
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/bootstrap.c"
"${hex0.m2planet.src}/cc.h"
"${hex0.m2libc.src}/bootstrappable.c"
"${hex0.m2planet.src}/cc_globals.c"
"${hex0.m2planet.src}/cc_reader.c"
"${hex0.m2planet.src}/cc_strings.c"
"${hex0.m2planet.src}/cc_types.c"
"${hex0.m2planet.src}/cc_core.c"
"${hex0.m2planet.src}/cc_macro.c"
"${hex0.m2planet.src}/cc.c"
"${sources.m2libc}/${architecture.m2libc}/linux/bootstrap.c"
"${sources.m2planet}/cc.h"
"${sources.m2libc}/bootstrappable.c"
"${sources.m2planet}/cc_globals.c"
"${sources.m2planet}/cc_reader.c"
"${sources.m2planet}/cc_strings.c"
"${sources.m2planet}/cc_types.c"
"${sources.m2planet}/cc_core.c"
"${sources.m2planet}/cc_macro.c"
"${sources.m2planet}/cc.c"
];
};
M2_M1 = builders.raw.build {
@ -102,8 +104,8 @@ in {
args = [
(builtins.placeholder "out")
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/${hex0.m2libc.architecture}_defs.M1"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/libc-core.M1"
"${sources.m2libc}/${architecture.m2libc}/${architecture.m2libc}_defs.M1"
"${sources.m2libc}/${architecture.m2libc}/libc-core.M1"
M2_M1
];
};
@ -130,7 +132,7 @@ in {
args = [
(builtins.placeholder "out")
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/ELF-${hex0.m2libc.architecture}.hex2"
"${sources.m2libc}/${architecture.m2libc}/ELF-${architecture.m2libc}.hex2"
M2_hex2-0
];
};

View file

@ -12,6 +12,8 @@
system = config.aux.system;
builders = config.aux.foundation.builders;
sources = config.aux.foundation.stages.stage0.sources;
architecture = config.aux.foundation.stages.stage0.architecture;
in {
options.aux.foundation.stages.stage0.blood-elf = {
package = lib.options.create {
@ -68,15 +70,15 @@ in {
args = [
"--architecture"
hex0.m2libc.architecture
architecture.m2libc
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/bootstrap.c"
"${sources.m2libc}/${architecture.m2libc}/linux/bootstrap.c"
"-f"
"${hex0.m2libc.src}/bootstrappable.c"
"${sources.m2libc}/bootstrappable.c"
"-f"
"${hex0.mescc-tools.src}/stringify.c"
"${sources.mescc-tools}/stringify.c"
"-f"
"${hex0.mescc-tools.src}/blood-elf.c"
"${sources.mescc-tools}/blood-elf.c"
"--bootstrap-mode"
"-o"
(builtins.placeholder "out")
@ -92,8 +94,8 @@ in {
args = [
(builtins.placeholder "out")
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/${hex0.m2libc.architecture}_defs.M1"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/libc-core.M1"
"${sources.m2libc}/${architecture.m2libc}/${architecture.m2libc}_defs.M1"
"${sources.m2libc}/${architecture.m2libc}/libc-core.M1"
blood-elf_M1
];
};
@ -120,7 +122,7 @@ in {
args = [
(builtins.placeholder "out")
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/ELF-${hex0.m2libc.architecture}.hex2"
"${sources.m2libc}/${architecture.m2libc}/ELF-${architecture.m2libc}.hex2"
blood-elf_hex2-0
];
};

View file

@ -13,6 +13,8 @@
system = config.aux.system;
builders = config.aux.foundation.builders;
sources = config.aux.foundation.stages.stage0.sources;
architecture = config.aux.foundation.stages.stage0.architecture;
in {
options.aux.foundation.stages.stage0.M1-0 = {
package = lib.options.create {
@ -69,15 +71,15 @@ in {
args = [
"--architecture"
hex0.m2libc.architecture
architecture.m2libc
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/bootstrap.c"
"${sources.m2libc}/${architecture.m2libc}/linux/bootstrap.c"
"-f"
"${hex0.m2libc.src}/bootstrappable.c"
"${sources.m2libc}/bootstrappable.c"
"-f"
"${hex0.mescc-tools.src}/stringify.c"
"${sources.mescc-tools}/stringify.c"
"-f"
"${hex0.mescc-tools.src}/M1-macro.c"
"${sources.mescc-tools}/M1-macro.c"
"--bootstrap-mode"
"--debug"
"-o"
@ -116,8 +118,8 @@ in {
args = [
(builtins.placeholder "out")
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/${hex0.m2libc.architecture}_defs.M1"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/libc-core.M1"
"${sources.m2libc}/${architecture.m2libc}/${architecture.m2libc}_defs.M1"
"${sources.m2libc}/${architecture.m2libc}/libc-core.M1"
M1-macro-0_M1
M1-macro-0-footer_M1
];
@ -145,7 +147,7 @@ in {
args = [
(builtins.placeholder "out")
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/ELF-${hex0.m2libc.architecture}-debug.hex2"
"${sources.m2libc}/${architecture.m2libc}/ELF-${architecture.m2libc}-debug.hex2"
M1-macro-0_hex2-0
];
};

View file

@ -14,6 +14,8 @@
system = config.aux.system;
builders = config.aux.foundation.builders;
sources = config.aux.foundation.stages.stage0.sources;
architecture = config.aux.foundation.stages.stage0.architecture;
in {
options.aux.foundation.stages.stage0.hex2-1 = {
package = lib.options.create {
@ -70,35 +72,35 @@ in {
args = [
"--architecture"
hex0.m2libc.architecture
architecture.m2libc
"-f"
"${hex0.m2libc.src}/sys/types.h"
"${sources.m2libc}/sys/types.h"
"-f"
"${hex0.m2libc.src}/stddef.h"
"${sources.m2libc}/stddef.h"
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/unistd.c"
"${sources.m2libc}/${architecture.m2libc}/linux/unistd.c"
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/fcntl.c"
"${sources.m2libc}/${architecture.m2libc}/linux/fcntl.c"
"-f"
"${hex0.m2libc.src}/fcntl.c"
"${sources.m2libc}/fcntl.c"
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/sys/stat.c"
"${sources.m2libc}/${architecture.m2libc}/linux/sys/stat.c"
"-f"
"${hex0.m2libc.src}/stdlib.c"
"${sources.m2libc}/stdlib.c"
"-f"
"${hex0.m2libc.src}/stdio.h"
"${sources.m2libc}/stdio.h"
"-f"
"${hex0.m2libc.src}/stdio.c"
"${sources.m2libc}/stdio.c"
"-f"
"${hex0.m2libc.src}/bootstrappable.c"
"${sources.m2libc}/bootstrappable.c"
"-f"
"${hex0.mescc-tools.src}/hex2.h"
"${sources.mescc-tools}/hex2.h"
"-f"
"${hex0.mescc-tools.src}/hex2_linker.c"
"${sources.mescc-tools}/hex2_linker.c"
"-f"
"${hex0.mescc-tools.src}/hex2_word.c"
"${sources.mescc-tools}/hex2_word.c"
"-f"
"${hex0.mescc-tools.src}/hex2.c"
"${sources.mescc-tools}/hex2.c"
"--debug"
"-o"
(builtins.placeholder "out")
@ -136,16 +138,16 @@ in {
args = [
"--architecture"
hex0.m2libc.architecture
architecture.m2libc
(
if config.aux.platform.endian == "little"
then "--little-endian"
else "--big-endian"
)
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/${hex0.m2libc.architecture}_defs.M1"
"${sources.m2libc}/${architecture.m2libc}/${architecture.m2libc}_defs.M1"
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/libc-full.M1"
"${sources.m2libc}/${architecture.m2libc}/libc-full.M1"
"-f"
hex2_linker_M1
"-f"
@ -164,7 +166,7 @@ in {
args = [
(builtins.placeholder "out")
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/ELF-${hex0.m2libc.architecture}-debug.hex2"
"${sources.m2libc}/${architecture.m2libc}/ELF-${architecture.m2libc}-debug.hex2"
hex2_linker_hex2
];
};

View file

@ -15,6 +15,8 @@
system = config.aux.system;
builders = config.aux.foundation.builders;
sources = config.aux.foundation.stages.stage0.sources;
architecture = config.aux.foundation.stages.stage0.architecture;
in {
options.aux.foundation.stages.stage0.M1 = {
package = lib.options.create {
@ -71,33 +73,33 @@ in {
args = [
"--architecture"
hex0.m2libc.architecture
architecture.m2libc
"-f"
"${hex0.m2libc.src}/sys/types.h"
"${sources.m2libc}/sys/types.h"
"-f"
"${hex0.m2libc.src}/stddef.h"
"${sources.m2libc}/stddef.h"
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/unistd.c"
"${sources.m2libc}/${architecture.m2libc}/linux/unistd.c"
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/fcntl.c"
"${sources.m2libc}/${architecture.m2libc}/linux/fcntl.c"
"-f"
"${hex0.m2libc.src}/fcntl.c"
"${sources.m2libc}/fcntl.c"
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/sys/stat.c"
"${sources.m2libc}/${architecture.m2libc}/linux/sys/stat.c"
"-f"
"${hex0.m2libc.src}/string.c"
"${sources.m2libc}/string.c"
"-f"
"${hex0.m2libc.src}/stdlib.c"
"${sources.m2libc}/stdlib.c"
"-f"
"${hex0.m2libc.src}/stdio.h"
"${sources.m2libc}/stdio.h"
"-f"
"${hex0.m2libc.src}/stdio.c"
"${sources.m2libc}/stdio.c"
"-f"
"${hex0.m2libc.src}/bootstrappable.c"
"${sources.m2libc}/bootstrappable.c"
"-f"
"${hex0.mescc-tools.src}/stringify.c"
"${sources.mescc-tools}/stringify.c"
"-f"
"${hex0.mescc-tools.src}/M1-macro.c"
"${sources.mescc-tools}/M1-macro.c"
"--debug"
"-o"
(builtins.placeholder "out")
@ -135,16 +137,16 @@ in {
args = [
"--architecture"
hex0.m2libc.architecture
architecture.m2libc
(
if config.aux.platform.endian == "little"
then "--little-endian"
else "--big-endian"
)
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/${hex0.m2libc.architecture}_defs.M1"
"${sources.m2libc}/${architecture.m2libc}/${architecture.m2libc}_defs.M1"
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/libc-full.M1"
"${sources.m2libc}/${architecture.m2libc}/libc-full.M1"
"-f"
M1-macro_M1
"-f"
@ -155,7 +157,7 @@ in {
};
in [
"--architecture"
hex0.m2libc.architecture
architecture.m2libc
(
if config.aux.platform.endian == "little"
then "--little-endian"
@ -172,7 +174,7 @@ in {
else builtins.throw "Unsupported system: ${config.aux.system}"
)
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/ELF-${hex0.m2libc.architecture}-debug.hex2"
"${sources.m2libc}/${architecture.m2libc}/ELF-${architecture.m2libc}-debug.hex2"
"-f"
M1-macro_hex2
"-o"

View file

@ -14,6 +14,8 @@
system = config.aux.system;
builders = config.aux.foundation.builders;
sources = config.aux.foundation.stages.stage0.sources;
architecture = config.aux.foundation.stages.stage0.architecture;
in {
options.aux.foundation.stages.stage0.hex2 = {
package = lib.options.create {
@ -70,35 +72,35 @@ in {
args = [
"--architecture"
hex0.m2libc.architecture
architecture.m2libc
"-f"
"${hex0.m2libc.src}/sys/types.h"
"${sources.m2libc}/sys/types.h"
"-f"
"${hex0.m2libc.src}/stddef.h"
"${sources.m2libc}/stddef.h"
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/unistd.c"
"${sources.m2libc}/${architecture.m2libc}/linux/unistd.c"
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/fcntl.c"
"${sources.m2libc}/${architecture.m2libc}/linux/fcntl.c"
"-f"
"${hex0.m2libc.src}/fcntl.c"
"${sources.m2libc}/fcntl.c"
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/sys/stat.c"
"${sources.m2libc}/${architecture.m2libc}/linux/sys/stat.c"
"-f"
"${hex0.m2libc.src}/stdlib.c"
"${sources.m2libc}/stdlib.c"
"-f"
"${hex0.m2libc.src}/stdio.h"
"${sources.m2libc}/stdio.h"
"-f"
"${hex0.m2libc.src}/stdio.c"
"${sources.m2libc}/stdio.c"
"-f"
"${hex0.m2libc.src}/bootstrappable.c"
"${sources.m2libc}/bootstrappable.c"
"-f"
"${hex0.mescc-tools.src}/hex2.h"
"${sources.mescc-tools}/hex2.h"
"-f"
"${hex0.mescc-tools.src}/hex2_linker.c"
"${sources.mescc-tools}/hex2_linker.c"
"-f"
"${hex0.mescc-tools.src}/hex2_word.c"
"${sources.mescc-tools}/hex2_word.c"
"-f"
"${hex0.mescc-tools.src}/hex2.c"
"${sources.mescc-tools}/hex2.c"
"--debug"
"-o"
(builtins.placeholder "out")
@ -135,16 +137,16 @@ in {
args = [
"--architecture"
hex0.m2libc.architecture
architecture.m2libc
(
if config.aux.platform.endian == "little"
then "--little-endian"
else "--big-endian"
)
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/${hex0.m2libc.architecture}_defs.M1"
"${sources.m2libc}/${architecture.m2libc}/${architecture.m2libc}_defs.M1"
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/libc-full.M1"
"${sources.m2libc}/${architecture.m2libc}/libc-full.M1"
"-f"
hex2_linker_M1
"-f"
@ -155,7 +157,7 @@ in {
};
in [
"--architecture"
hex0.m2libc.architecture
architecture.m2libc
(
if config.aux.platform.endian == "little"
then "--little-endian"
@ -172,7 +174,7 @@ in {
else builtins.throw "Unsupported system: ${config.aux.system}"
)
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/ELF-${hex0.m2libc.architecture}-debug.hex2"
"${sources.m2libc}/${architecture.m2libc}/ELF-${architecture.m2libc}-debug.hex2"
"-f"
hex2_linker_hex2
"-o"

View file

@ -14,6 +14,8 @@
system = config.aux.system;
builders = config.aux.foundation.builders;
sources = config.aux.foundation.stages.stage0.sources;
architecture = config.aux.foundation.stages.stage0.architecture;
in {
options.aux.foundation.stages.stage0.kaem-unwrapped = {
package = lib.options.create {
@ -70,37 +72,37 @@ in {
args = [
"--architecture"
hex0.m2libc.architecture
architecture.m2libc
"-f"
"${hex0.m2libc.src}/sys/types.h"
"${sources.m2libc}/sys/types.h"
"-f"
"${hex0.m2libc.src}/stddef.h"
"${sources.m2libc}/stddef.h"
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/unistd.c"
"${sources.m2libc}/${architecture.m2libc}/linux/unistd.c"
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/fcntl.c"
"${sources.m2libc}/${architecture.m2libc}/linux/fcntl.c"
"-f"
"${hex0.m2libc.src}/fcntl.c"
"${sources.m2libc}/fcntl.c"
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/sys/stat.c"
"${sources.m2libc}/${architecture.m2libc}/linux/sys/stat.c"
"-f"
"${hex0.m2libc.src}/string.c"
"${sources.m2libc}/string.c"
"-f"
"${hex0.m2libc.src}/stdlib.c"
"${sources.m2libc}/stdlib.c"
"-f"
"${hex0.m2libc.src}/stdio.h"
"${sources.m2libc}/stdio.h"
"-f"
"${hex0.m2libc.src}/stdio.c"
"${sources.m2libc}/stdio.c"
"-f"
"${hex0.m2libc.src}/bootstrappable.c"
"${sources.m2libc}/bootstrappable.c"
"-f"
"${hex0.mescc-tools.src}/Kaem/kaem.h"
"${sources.mescc-tools}/Kaem/kaem.h"
"-f"
"${hex0.mescc-tools.src}/Kaem/variable.c"
"${sources.mescc-tools}/Kaem/variable.c"
"-f"
"${hex0.mescc-tools.src}/Kaem/kaem_globals.c"
"${sources.mescc-tools}/Kaem/kaem_globals.c"
"-f"
"${hex0.mescc-tools.src}/Kaem/kaem.c"
"${sources.mescc-tools}/Kaem/kaem.c"
"--debug"
"-o"
(builtins.placeholder "out")
@ -137,16 +139,16 @@ in {
args = [
"--architecture"
hex0.m2libc.architecture
architecture.m2libc
(
if config.aux.platform.endian == "little"
then "--little-endian"
else "--big-endian"
)
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/${hex0.m2libc.architecture}_defs.M1"
"${sources.m2libc}/${architecture.m2libc}/${architecture.m2libc}_defs.M1"
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/libc-full.M1"
"${sources.m2libc}/${architecture.m2libc}/libc-full.M1"
"-f"
kaem_M1
"-f"
@ -157,7 +159,7 @@ in {
};
in [
"--architecture"
hex0.m2libc.architecture
architecture.m2libc
(
if config.aux.platform.endian == "little"
then "--little-endian"
@ -174,7 +176,7 @@ in {
else builtins.throw "Unsupported system: ${config.aux.system}"
)
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/ELF-${hex0.m2libc.architecture}-debug.hex2"
"${sources.m2libc}/${architecture.m2libc}/ELF-${architecture.m2libc}-debug.hex2"
"-f"
kaem_hex2
"-o"

View file

@ -0,0 +1,95 @@
{
lib,
config,
}: let
system = config.aux.system;
architecture = config.aux.foundation.stages.stage0.architecture.base;
in {
options.aux.foundation.stages.stage0.sources = {
base = lib.options.create {
type = lib.types.string;
description = "The source for the hex0 build files.";
};
m2libc = lib.options.create {
type = lib.types.string;
description = "The source for the M2libc build files.";
};
m2planet = lib.options.create {
type = lib.types.string;
description = "The source for the M2-Planet build files.";
};
m2mesoplanet = lib.options.create {
type = lib.types.string;
description = "The source for the M2-Mesoplanet build files.";
};
mescc-tools = lib.options.create {
type = lib.types.string;
description = "The source for the mescc-tools build files.";
};
mescc-tools-extra = lib.options.create {
type = lib.types.string;
description = "The source for the mescc-tools-extra build files.";
};
};
config = {
aux.foundation.stages.stage0.sources = {
# All sources are combined a central repository via submodules. Due to potential quirks surrounding
# 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
builtins.fetchTarball {
url = "https://github.com/oriansj/stage0-posix-amd64/archive/93fbe4c08772d8df1412e2554668e24cf604088c.tar.gz";
sha256 = "10d1xnjzqplpfip3pm89bydd501x1bcgkg7lkkadyq5bqpad5flp";
}
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
builtins.fetchTarball {
url = "https://github.com/oriansj/stage0-posix-x86/archive/e86bf7d304bae5ce5ccc88454bb60cf0837e941f.tar.gz";
sha256 = "1c1fk793yzq8zbg60n2zd22fsmirc3zr26fj0iskap456g84nxv8";
}
else builtins.throw "Unsupported architecture for stage0: ${architecture}";
m2libc = builtins.fetchTarball {
url = "https://github.com/oriansj/M2libc/archive/de7c75f144176c3b9be77695d9bf94440445aeae.tar.gz";
sha256 = "01k81zn8yx4jg6fbcjgkrf9rp074yikkmwqykdgi9143yfb2k3yv";
};
m2planet = builtins.fetchTarball {
url = "https://github.com/oriansj/M2-Planet/archive/51dc63b349ca13fa57b345964254cf26930c0a7d.tar.gz";
sha256 = "1kksk260dh6qd0dzgl9vgs67fs0lsxs9w0gniy0ii5fgmqxi8p65";
};
m2mesoplanet = builtins.fetchTarball {
url = "https://github.com/oriansj/M2-Mesoplanet/archive/c80645f06b035debaa08e95da3206346a9f61b97.tar.gz";
sha256 = "02vzqln38ylfnd88p87935yf26i60gkbv93ns5j7parqgyyz2kl4";
};
mescc-tools = builtins.fetchTarball {
url = "https://github.com/oriansj/mescc-tools/archive/5d37991e22d1e4147411a766f4410508ba872962.tar.gz";
sha256 = "1xgpqhc5diim3rr9a00939976svrbhfp4v5970548a137fdynl4c";
};
mescc-tools-extra = builtins.fetchTarball {
url = "https://github.com/oriansj/mescc-tools-extra/archive/c1bd4ab4c5b994d8167c1e6dfc14050dc151a911.tar.gz";
sha256 = "0v8vxn3a8rxbgi6vcw73jqkw9j5vg3qlvd4sxk2w0fpybjml8brd";
};
};
};
}

View file

@ -5,7 +5,8 @@ lib: {
## `lib.paths.into.drv` for convenience.
##
## @type a -> Bool
isDerivation = value: value.type or null == "derivation";
isDerivation = value:
value.type or null == "derivation";
## Sanitize a string to produce a valid name for a derivation.
##

View file

@ -25,7 +25,7 @@ lib: {
##
## @type Path -> Bool
store = value:
if lib.strings.stringifiable value
if lib.strings.validate.stringifiable value
then
builtins.substring 0 1 (builtins.toString value)
== "/"