From 1642b2173bc3f061e578f4620cfb75e35394b154 Mon Sep 17 00:00:00 2001 From: Jake Hamilton Date: Wed, 5 Jun 2024 04:10:35 -0700 Subject: [PATCH] refactor: code cleanup, move sources to separate module --- foundation/flake.lock | 2 +- foundation/flake.nix | 2 - .../stages/stage0/architecture/default.nix | 35 +++++ foundation/src/stages/stage0/default.nix | 3 + foundation/src/stages/stage0/kaem/default.nix | 15 +-- .../stage0/mescc-tools-extra/default.nix | 6 +- .../src/stages/stage0/mescc-tools/default.nix | 46 ++++--- .../src/stages/stage0/phases/phase00.nix | 122 +----------------- .../src/stages/stage0/phases/phase01.nix | 4 +- .../src/stages/stage0/phases/phase02.nix | 4 +- .../src/stages/stage0/phases/phase03.nix | 10 +- .../src/stages/stage0/phases/phase04.nix | 6 +- .../src/stages/stage0/phases/phase05.nix | 6 +- .../src/stages/stage0/phases/phase06.nix | 28 ++-- .../src/stages/stage0/phases/phase07.nix | 18 +-- .../src/stages/stage0/phases/phase08.nix | 18 +-- .../src/stages/stage0/phases/phase09.nix | 40 +++--- .../src/stages/stage0/phases/phase10.nix | 40 +++--- .../src/stages/stage0/phases/phase11.nix | 42 +++--- .../src/stages/stage0/phases/phase12.nix | 44 ++++--- .../src/stages/stage0/sources/default.nix | 95 ++++++++++++++ lib/src/packages/default.nix | 3 +- lib/src/paths/default.nix | 2 +- 23 files changed, 314 insertions(+), 277 deletions(-) create mode 100644 foundation/src/stages/stage0/architecture/default.nix create mode 100644 foundation/src/stages/stage0/sources/default.nix diff --git a/foundation/flake.lock b/foundation/flake.lock index ae29a0d..6272b7f 100644 --- a/foundation/flake.lock +++ b/foundation/flake.lock @@ -3,7 +3,7 @@ "lib": { "locked": { "lastModified": 1, - "narHash": "sha256-303zkU+ntdAF6JLE9gA3k5piX5RvKtQp6JXovZWzDdQ=", + "narHash": "sha256-wgO96O9ALMMXtfBKuh9rYo3KIVq4nk8V7Cke4dg0MOk=", "path": "../lib", "type": "path" }, diff --git a/foundation/flake.nix b/foundation/flake.nix index f17fe5d..e8c5694 100644 --- a/foundation/flake.nix +++ b/foundation/flake.nix @@ -19,8 +19,6 @@ # "aarch64-darwin" ]; in { - modules.aux = modules; - packages = forEachSystem ( system: let result = lib.modules.run { diff --git a/foundation/src/stages/stage0/architecture/default.nix b/foundation/src/stages/stage0/architecture/default.nix new file mode 100644 index 0000000..ecb975c --- /dev/null +++ b/foundation/src/stages/stage0/architecture/default.nix @@ -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"''; + }; + }; + }; +} diff --git a/foundation/src/stages/stage0/default.nix b/foundation/src/stages/stage0/default.nix index 0ded291..aff235a 100644 --- a/foundation/src/stages/stage0/default.nix +++ b/foundation/src/stages/stage0/default.nix @@ -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 diff --git a/foundation/src/stages/stage0/kaem/default.nix b/foundation/src/stages/stage0/kaem/default.nix index 4947847..961a4ad 100644 --- a/foundation/src/stages/stage0/kaem/default.nix +++ b/foundation/src/stages/stage0/kaem/default.nix @@ -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 { diff --git a/foundation/src/stages/stage0/mescc-tools-extra/default.nix b/foundation/src/stages/stage0/mescc-tools-extra/default.nix index 337524c..d98eee0 100644 --- a/foundation/src/stages/stage0/mescc-tools-extra/default.nix +++ b/foundation/src/stages/stage0/mescc-tools-extra/default.nix @@ -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; }); }; diff --git a/foundation/src/stages/stage0/mescc-tools/default.nix b/foundation/src/stages/stage0/mescc-tools/default.nix index ba7e56e..f3d11ca 100644 --- a/foundation/src/stages/stage0/mescc-tools/default.nix +++ b/foundation/src/stages/stage0/mescc-tools/default.nix @@ -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; diff --git a/foundation/src/stages/stage0/phases/phase00.nix b/foundation/src/stages/stage0/phases/phase00.nix index a778220..c18e67f 100644 --- a/foundation/src/stages/stage0/phases/phase00.nix +++ b/foundation/src/stages/stage0/phases/phase00.nix @@ -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"; - }; - }; }; }; } diff --git a/foundation/src/stages/stage0/phases/phase01.nix b/foundation/src/stages/stage0/phases/phase01.nix index 355989c..7053a44 100644 --- a/foundation/src/stages/stage0/phases/phase01.nix +++ b/foundation/src/stages/stage0/phases/phase01.nix @@ -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") ]; }); diff --git a/foundation/src/stages/stage0/phases/phase02.nix b/foundation/src/stages/stage0/phases/phase02.nix index ab2606c..8cb217a 100644 --- a/foundation/src/stages/stage0/phases/phase02.nix +++ b/foundation/src/stages/stage0/phases/phase02.nix @@ -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") ]; }); diff --git a/foundation/src/stages/stage0/phases/phase03.nix b/foundation/src/stages/stage0/phases/phase03.nix index 156e5cf..764c5ad 100644 --- a/foundation/src/stages/stage0/phases/phase03.nix +++ b/foundation/src/stages/stage0/phases/phase03.nix @@ -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") ]; }); diff --git a/foundation/src/stages/stage0/phases/phase04.nix b/foundation/src/stages/stage0/phases/phase04.nix index 57808fa..d2a94da 100644 --- a/foundation/src/stages/stage0/phases/phase04.nix +++ b/foundation/src/stages/stage0/phases/phase04.nix @@ -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 [ diff --git a/foundation/src/stages/stage0/phases/phase05.nix b/foundation/src/stages/stage0/phases/phase05.nix index 3c11dbe..a6c2bde 100644 --- a/foundation/src/stages/stage0/phases/phase05.nix +++ b/foundation/src/stages/stage0/phases/phase05.nix @@ -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 ]; }; diff --git a/foundation/src/stages/stage0/phases/phase06.nix b/foundation/src/stages/stage0/phases/phase06.nix index 728e3e7..943e540 100644 --- a/foundation/src/stages/stage0/phases/phase06.nix +++ b/foundation/src/stages/stage0/phases/phase06.nix @@ -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 ]; }; diff --git a/foundation/src/stages/stage0/phases/phase07.nix b/foundation/src/stages/stage0/phases/phase07.nix index ee4e8b0..43a577e 100644 --- a/foundation/src/stages/stage0/phases/phase07.nix +++ b/foundation/src/stages/stage0/phases/phase07.nix @@ -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 ]; }; diff --git a/foundation/src/stages/stage0/phases/phase08.nix b/foundation/src/stages/stage0/phases/phase08.nix index c678c85..f83746b 100644 --- a/foundation/src/stages/stage0/phases/phase08.nix +++ b/foundation/src/stages/stage0/phases/phase08.nix @@ -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 ]; }; diff --git a/foundation/src/stages/stage0/phases/phase09.nix b/foundation/src/stages/stage0/phases/phase09.nix index 08dc589..6011a4e 100644 --- a/foundation/src/stages/stage0/phases/phase09.nix +++ b/foundation/src/stages/stage0/phases/phase09.nix @@ -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 ]; }; diff --git a/foundation/src/stages/stage0/phases/phase10.nix b/foundation/src/stages/stage0/phases/phase10.nix index b941865..b611260 100644 --- a/foundation/src/stages/stage0/phases/phase10.nix +++ b/foundation/src/stages/stage0/phases/phase10.nix @@ -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" diff --git a/foundation/src/stages/stage0/phases/phase11.nix b/foundation/src/stages/stage0/phases/phase11.nix index 68775f5..2f2920d 100644 --- a/foundation/src/stages/stage0/phases/phase11.nix +++ b/foundation/src/stages/stage0/phases/phase11.nix @@ -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" diff --git a/foundation/src/stages/stage0/phases/phase12.nix b/foundation/src/stages/stage0/phases/phase12.nix index b9d1d5a..57dff75 100644 --- a/foundation/src/stages/stage0/phases/phase12.nix +++ b/foundation/src/stages/stage0/phases/phase12.nix @@ -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" diff --git a/foundation/src/stages/stage0/sources/default.nix b/foundation/src/stages/stage0/sources/default.nix new file mode 100644 index 0000000..af9d52b --- /dev/null +++ b/foundation/src/stages/stage0/sources/default.nix @@ -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"; + }; + }; + }; +} diff --git a/lib/src/packages/default.nix b/lib/src/packages/default.nix index 0373db2..b944244 100644 --- a/lib/src/packages/default.nix +++ b/lib/src/packages/default.nix @@ -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. ## diff --git a/lib/src/paths/default.nix b/lib/src/paths/default.nix index 8378c0b..c8ff14c 100644 --- a/lib/src/paths/default.nix +++ b/lib/src/paths/default.nix @@ -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) == "/"