feat: add foundation

This commit is contained in:
Jake Hamilton 2024-06-04 19:04:40 -07:00
parent 39ea93b671
commit 3fe60580da
Signed by untrusted user: jakehamilton
GPG key ID: 9762169A1B35EA68
43 changed files with 4549 additions and 6 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
.direnv
result

View file

@ -24,6 +24,7 @@ may collaborate.
## Experiments ## Experiments
| Name | Phase | Description | | Name | Phase | Description |
| ---------------- | --------- | -------------------------------------------------------- | | ------------------------------ | --------- | -------------------------------------------------------------------------- |
| [Aux Lib](./lib) | Iteration | A library of common functions used in the Aux ecosystem. | | [Aux Lib](./lib) | Iteration | A library of common functions used in the Aux ecosystem. |
| [Aux Foundation](./foundation) | Idea | Foundational packages which allow for bootstrapping a greater package set. |

23
foundation/LICENSE Normal file
View file

@ -0,0 +1,23 @@
MIT License
Copyright (c) 2003-2023 Eelco Dolstra and the Nixpkgs/NixOS contributors
Copyright (c) 2024 Aux Contributors
Permission is hereby granted, free
of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice
(including the next paragraph) shall be included in all copies or substantial
portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

95
foundation/README.md Normal file
View file

@ -0,0 +1,95 @@
# Aux Foundation
Aux Foundation provides a set of foundational packages which are required for bootstrapping
a larger package set.
## Usage
Packages can be imported both with and without Nix Flakes. To import them using Nix Flakes,
add this repository as an input.
```nix
inputs.foundation.url = "github:auxolotl/labs?dir=foundation";
```
To import this library without using Nix Flakes, you will need to use `fetchTarball` and
import the library entrypoint.
```nix
let
labs = builtins.fetchTarball {
url = "https://github.com/auxolotl/labs/archive/main.tar.gz";
sha256 = "<sha256>";
};
lib = import "${labs}/foundation";
in
# ...
```
## Development
This foundational package set is created using modules. Each builder and package is separated
accordingly and can be found in their respective directories. In addition, packages are grouped
into the different stages of the bootstrapping process.
### Inputs
Due to the fundamental nature of this project, the only accepted input is `lib` which itself
has no dependencies. _Everything_ else must be built from scratch in the package set.
### Formatting
> **Note:** To keep this flake light and keep its inputs empty we do not include a package
> set which would provide a formatter. Instead please run `nix run nixpkgs#nixfmt-rfc-style`
> until an improved solution is available.
All code in this project must be formatted using the provided formatter in the `flake.nix`
file. You can run this formatter using the command `nix fmt` (not currently available).
### Code Quality
In order to keep the project approachable and easy to maintain, certain patterns are not allowed.
In particular, the use of `with` and `rec` are not allowed. Additionally, you should prefer the
fully qualified name of a variable rather than creating intermediate ones using `inherit`.
### Builders
Builders are wrappers around `builtins.derivation` and provide additional functionality via
abstraction. They can be found in [`./src/builders`](./src/builders). Each builder specifies
its own `build` function which can be called elsewhere in the package set to construct packages.
For example, here is a module that makes use of the `kaem` builder:
```nix
{config}: let
builders = config.aux.foundation.builders;
stage0 = config.aux.foundation.stages.stage0;
package = builders.kaem.build {
name = "my-package";
deps.build.host = [
stage0.mescc-tools.package
stage0.mescc-tools-extra.package
];
script = ''
mkdir ''${out}/bin
cp ${./my-binary} ''${out}/bin/my-package
chmod 555 ''${out}/bin/my-package
'';
};
in
# ...
```
### Stages
The bootstrapping process is broken up into different stages which focus on different goals.
Each stage can be found in [`./src/stages`](./src/stages).
#### Stage 0
This stage is responsible for starting with a single binary seed and producing the tools
necessary to compile (simple) C code. This stage will then compile the original tools it
used from C sources.

23
foundation/flake.lock Normal file
View file

@ -0,0 +1,23 @@
{
"nodes": {
"lib": {
"locked": {
"lastModified": 1,
"narHash": "sha256-303zkU+ntdAF6JLE9gA3k5piX5RvKtQp6JXovZWzDdQ=",
"path": "../lib",
"type": "path"
},
"original": {
"path": "../lib",
"type": "path"
}
},
"root": {
"inputs": {
"lib": "lib"
}
}
},
"root": "root",
"version": 7
}

37
foundation/flake.nix Normal file
View file

@ -0,0 +1,37 @@
{
description = "A set of foundational packages required for bootstrapping a larger package set.";
inputs = {
lib = {
url = "path:../lib";
};
};
outputs = inputs: let
inherit (inputs.lib) lib;
modules = import ./src;
forEachSystem = lib.attrs.generate [
"x86_64-linux"
"aarch64-linux"
# "x86_64-darwin"
# "aarch64-darwin"
];
in {
modules.aux = modules;
packages = forEachSystem (
system: let
result = lib.modules.run {
modules =
(builtins.attrValues modules)
++ [
{config.aux.system = system;}
];
};
in
result.config.exports.resolved.packages
);
};
}

View file

@ -0,0 +1,63 @@
{
lib,
config,
}: let
system = config.aux.system;
in {
options.aux.foundation.builders.file.text = {
build = lib.options.create {
type = lib.types.function lib.types.package;
description = "Builds a package using the text file builder.";
};
};
config = {
aux.foundation.builders.file.text = {
build = lib.modules.overrides.default (settings @ {
name,
contents,
isExecutable ? false,
destination ? "",
meta ? {},
extras ? {},
...
}: let
script =
''
target=''${out}''${destination}
''
+ lib.strings.when (builtins.dirOf destination == ".") ''
mkdir -p ''${out}''${destinationDir}
''
+ ''
cp ''${contentPath} ''${target}
''
+ lib.strings.when isExecutable ''
chmod 555 ''${target}
'';
package = builtins.derivation (
(builtins.removeAttrs settings ["meta" "extras" "executable" "isExecutable"])
// {
inherit name system contents destination;
destinationDir = builtins.dirOf destination;
passAsFile = ["contents"];
builder = "${config.aux.foundation.stages.stage0.kaem.package}/bin/kaem";
args = [
"--verbose"
"--strict"
"--file"
(builtins.toFile "write-text-to-file.kaem" script)
];
}
);
in
package
// {
inherit meta extras;
});
};
};
}

View file

@ -0,0 +1,65 @@
{
lib,
config,
}: let
system = config.aux.system;
builders = config.aux.foundation.builders;
stage0 = config.aux.foundation.stages.stage0;
in {
options.aux.foundation.builders.kaem = {
build = lib.options.create {
type = lib.types.function lib.types.package;
description = "Builds a package using the kaem builder.";
};
};
config = {
aux.foundation.builders.kaem = {
build = lib.modules.overrides.default (settings @ {
name,
script,
meta ? {},
extras ? {},
env ? {},
deps ? {},
...
}: let
package = builtins.derivation (
(builtins.removeAttrs settings ["meta" "extras" "executable" "env" "deps" "script"])
env
// {
inherit name system;
builder = "${stage0.kaem.package}/bin/kaem";
args = [
"--verbose"
"--strict"
"--file"
(
builders.file.text.build {
name = "${name}-builder";
contents = script;
}
)
];
PATH = lib.paths.bin (
(deps.build.host or [])
++ [
stage0.kaem.package
stage0.mescc-tools.package
stage0.mescc-tools-extra.package
]
);
}
);
in
package
// {
inherit meta extras;
});
};
};
}

View file

@ -0,0 +1,42 @@
{
lib,
config,
}: let
system = config.aux.system;
in {
options.aux.foundation.builders.raw = {
build = lib.options.create {
type = lib.types.function lib.types.package;
description = "Builds a package using the raw builder.";
};
};
config = {
aux.foundation.builders.raw = {
build = lib.modules.overrides.default (settings @ {
pname,
version,
executable,
args ? [],
meta ? {},
extras ? {},
...
}: let
package = builtins.derivation (
(builtins.removeAttrs settings ["meta" "extras" "executable"])
// {
inherit version pname system args;
name = "${pname}-${version}";
builder = executable;
}
);
in
package
// {
inherit meta extras;
});
};
};
}

View file

@ -0,0 +1,12 @@
let
modules = {
builderFileText = ./builders/file/text;
builderKaem = ./builders/kaem;
builderRaw = ./builders/raw;
exports = ./exports;
platform = ./platform;
stage0 = ./stages/stage0;
system = ./system;
};
in
modules

View file

@ -0,0 +1,38 @@
{
lib,
config,
}: let
options = {
packages = lib.options.create {
default.value = {};
type = lib.types.attrs.of lib.types.package;
};
};
in {
options = {
exports = {
inherit (options) packages;
resolved = {
inherit (options) packages;
};
};
};
config = {
exports.resolved =
builtins.mapAttrs (
name: value:
lib.attrs.filter
(
name: value:
if value ? meta && value.meta ? platforms
then builtins.elem config.aux.system value.meta.platforms
else true
)
value
)
(builtins.removeAttrs config.exports ["resolved"]);
};
}

View file

@ -0,0 +1,324 @@
{
lib,
config,
}: let
system = config.aux.system;
parts = lib.strings.split "-" system;
platform = builtins.elemAt parts 0;
target = builtins.elemAt parts 1;
platforms = {
arm = {
bits = 32;
endian = "little";
family = "arm";
};
armv5tel = {
bits = 32;
endian = "little";
family = "arm";
version = "5";
arch = "armv5t";
};
armv6m = {
bits = 32;
endian = "little";
family = "arm";
version = "6";
arch = "armv6-m";
};
armv6l = {
bits = 32;
endian = "little";
family = "arm";
version = "6";
arch = "armv6";
};
armv7a = {
bits = 32;
endian = "little";
family = "arm";
version = "7";
arch = "armv7-a";
};
armv7r = {
bits = 32;
endian = "little";
family = "arm";
version = "7";
arch = "armv7-r";
};
armv7m = {
bits = 32;
endian = "little";
family = "arm";
version = "7";
arch = "armv7-m";
};
armv7l = {
bits = 32;
endian = "little";
family = "arm";
version = "7";
arch = "armv7";
};
armv8a = {
bits = 32;
endian = "little";
family = "arm";
version = "8";
arch = "armv8-a";
};
armv8r = {
bits = 32;
endian = "little";
family = "arm";
version = "8";
arch = "armv8-a";
};
armv8m = {
bits = 32;
endian = "little";
family = "arm";
version = "8";
arch = "armv8-m";
};
aarch64 = {
bits = 64;
endian = "little";
family = "arm";
version = "8";
arch = "armv8-a";
};
aarch64_be = {
bits = 64;
endian = "big";
family = "arm";
version = "8";
arch = "armv8-a";
};
i386 = {
bits = 32;
endian = "little";
family = "x86";
arch = "i386";
};
i486 = {
bits = 32;
endian = "little";
family = "x86";
arch = "i486";
};
i586 = {
bits = 32;
endian = "little";
family = "x86";
arch = "i586";
};
i686 = {
bits = 32;
endian = "little";
family = "x86";
arch = "i686";
};
x86_64 = {
bits = 64;
endian = "little";
family = "x86";
arch = "x86-64";
};
microblaze = {
bits = 32;
endian = "big";
family = "microblaze";
};
microblazeel = {
bits = 32;
endian = "little";
family = "microblaze";
};
mips = {
bits = 32;
endian = "big";
family = "mips";
};
mipsel = {
bits = 32;
endian = "little";
family = "mips";
};
mips64 = {
bits = 64;
endian = "big";
family = "mips";
};
mips64el = {
bits = 64;
endian = "little";
family = "mips";
};
mmix = {
bits = 64;
endian = "big";
family = "mmix";
};
m68k = {
bits = 32;
endian = "big";
family = "m68k";
};
powerpc = {
bits = 32;
endian = "big";
family = "power";
};
powerpc64 = {
bits = 64;
endian = "big";
family = "power";
};
powerpc64le = {
bits = 64;
endian = "little";
family = "power";
};
powerpcle = {
bits = 32;
endian = "little";
family = "power";
};
riscv32 = {
bits = 32;
endian = "little";
family = "riscv";
};
riscv64 = {
bits = 64;
endian = "little";
family = "riscv";
};
s390 = {
bits = 32;
endian = "big";
family = "s390";
};
s390x = {
bits = 64;
endian = "big";
family = "s390";
};
sparc = {
bits = 32;
endian = "big";
family = "sparc";
};
sparc64 = {
bits = 64;
endian = "big";
family = "sparc";
};
wasm32 = {
bits = 32;
endian = "little";
family = "wasm";
};
wasm64 = {
bits = 64;
endian = "little";
family = "wasm";
};
alpha = {
bits = 64;
endian = "little";
family = "alpha";
};
rx = {
bits = 32;
endian = "little";
family = "rx";
};
msp430 = {
bits = 16;
endian = "little";
family = "msp430";
};
avr = {
bits = 8;
family = "avr";
};
vc4 = {
bits = 32;
endian = "little";
family = "vc4";
};
or1k = {
bits = 32;
endian = "big";
family = "or1k";
};
loongarch64 = {
bits = 64;
endian = "little";
family = "loongarch";
};
javascript = {
bits = 32;
endian = "little";
family = "javascript";
};
};
in {
options.aux.platform = {
family = lib.options.create {
type = lib.types.string;
description = "Family of the platform";
};
bits = lib.options.create {
type = lib.types.int;
description = "Number of bits in the platform";
};
endian = lib.options.create {
type = lib.types.enum ["little" "big"];
default.value = "big";
description = "Endianess of the platform";
};
arch = lib.options.create {
type = lib.types.nullish lib.types.string;
default.value = null;
description = "Architecture of the platform";
};
version = lib.options.create {
type = lib.types.nullish lib.types.string;
default.value = null;
description = "Version of the platform";
};
};
config = {
aux.platform =
platforms.${platform}
or (builtins.throw "Unsupported platform: ${system}");
};
}

View file

@ -0,0 +1,76 @@
{
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 {
includes = [
./phases/phase00.nix
./phases/phase01.nix
./phases/phase02.nix
./phases/phase03.nix
./phases/phase04.nix
./phases/phase05.nix
./phases/phase06.nix
./phases/phase07.nix
./phases/phase08.nix
./phases/phase09.nix
./phases/phase10.nix
./phases/phase11.nix
./phases/phase12.nix
./mescc-tools
./mescc-tools-extra
./kaem
];
config = {
exports = {
packages = {
stage0-hex0 = cfg.hex0.package;
stage0-hex1 = cfg.hex1.package;
stage0-hex2-0 = cfg.hex2-0.package;
stage0-catm = cfg.catm.package;
stage0-M0 = cfg.M0.package;
stage0-cc_arch = cfg.cc_arch.package;
stage0-M2 = cfg.M2.package;
stage0-blood-elf = cfg.blood-elf.package;
stage0-M1-0 = cfg.M1-0.package;
stage0-hex2-1 = cfg.hex2-1.package;
stage0-M1 = cfg.M1.package;
stage0-hex2 = cfg.hex2.package;
stage0-kaem-unwrapped = cfg.kaem-unwrapped.package;
stage0-mescc-tools = cfg.mescc-tools.package;
stage0-mescc-tools-extra = cfg.mescc-tools-extra.package;
stage0-kaem = cfg.kaem.package;
};
};
};
}

View file

@ -0,0 +1,3 @@
mkdir -p ${out}/bin
cp ${kaemUnwrapped} ${out}/bin/kaem
chmod 555 ${out}/bin/kaem

View file

@ -0,0 +1,77 @@
{
lib,
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;
in {
options.aux.foundation.stages.stage0.kaem = {
package = lib.options.create {
type = lib.types.package;
description = "The package to use for kaem.";
};
meta = {
description = lib.options.create {
type = lib.types.string;
description = "Description for the package.";
default.value = "Minimal build tool for running scripts on systems that lack any shell.";
};
homepage = lib.options.create {
type = lib.types.string;
description = "Homepage for the package.";
default.value = "https://github.com/oriansj/stage0-posix";
};
license = lib.options.create {
# TODO: Add a proper type for licenses.
type = lib.types.attrs.any;
description = "License for the package.";
default.value = lib.licenses.gpl3Plus;
};
platforms = lib.options.create {
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = ["x86_64-linux" "aarch64-linux" "i686-linux"];
};
};
};
config = {
aux.foundation.stages.stage0.kaem = {
package = lib.modules.overrides.default (builders.raw.build {
pname = "kaem";
version = "1.6.0";
meta = cfg.meta;
executable = kaem-unwrapped.package;
args = [
"--verbose"
"--strict"
"--file"
./build.kaem
];
kaemUnwrapped = kaem-unwrapped.package;
PATH = lib.paths.bin [mescc-tools-extra.package];
});
};
};
}

View file

@ -0,0 +1,40 @@
# This is a modified version of mescc-tools-extra/mescc-tools-extra.kaem
# https://github.com/oriansj/mescc-tools-extra/blob/ec53af69d6d2119b47b369cd0ec37ac806e7ad60/mescc-tools-extra.kaem
# - Paths to build inputs have been changed for nix
# - Added additional step to create $out directory
## Copyright (C) 2017 Jeremiah Orians
## This file is part of mescc-tools.
##
## mescc-tools is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## mescc-tools is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with mescc-tools. If not, see <http://www.gnu.org/licenses/>.
alias CC="${mesccTools}/bin/M2-Mesoplanet --operating-system ${m2libcOS} --architecture ${m2libcArch} -f"
cd ${src}
# Create output folder
CC mkdir.c -o ${TMP}/mkdir
${TMP}/mkdir -p ${out}/bin
CC sha256sum.c -o ${out}/bin/sha256sum
CC match.c -o ${out}/bin/match
CC mkdir.c -o ${out}/bin/mkdir
CC untar.c -o ${out}/bin/untar
CC ungz.c -o ${out}/bin/ungz
CC unbz2.c -o ${out}/bin/unbz2
CC catm.c -o ${out}/bin/catm
CC cp.c -o ${out}/bin/cp
CC chmod.c -o ${out}/bin/chmod
CC rm.c -o ${out}/bin/rm
CC replace.c -o ${out}/bin/replace

View file

@ -0,0 +1,79 @@
{
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;
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;
system = config.aux.system;
builders = config.aux.foundation.builders;
in {
options.aux.foundation.stages.stage0.mescc-tools-extra = {
package = lib.options.create {
type = lib.types.package;
description = "The package to use for mescc-tools-extra.";
};
meta = {
description = lib.options.create {
type = lib.types.string;
description = "Description for the package.";
default.value = "Collection of tools for use in bootstrapping.";
};
homepage = lib.options.create {
type = lib.types.string;
description = "Homepage for the package.";
default.value = "https://github.com/oriansj/stage0-posix";
};
license = lib.options.create {
# TODO: Add a proper type for licenses.
type = lib.types.attrs.any;
description = "License for the package.";
default.value = lib.licenses.gpl3Plus;
};
platforms = lib.options.create {
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = ["x86_64-linux" "aarch64-linux" "i686-linux"];
};
};
};
config = {
aux.foundation.stages.stage0.mescc-tools-extra = {
package = lib.modules.overrides.default (builders.raw.build {
pname = "mescc-tools-tools";
version = "1.6.0";
meta = cfg.meta;
executable = kaem-unwrapped.package;
args = [
"--verbose"
"--strict"
"--file"
./build.kaem
];
src = hex0.mescc-tools-extra.src;
m2libcOS = "linux";
m2libcArch = hex0.m2libc.architecture;
mesccTools = mescc-tools.package;
});
};
};
}

View file

@ -0,0 +1,205 @@
# This is a modified version of stage0-posix/x86/mescc-tools-full-kaem.kaem
# https://github.com/oriansj/stage0-posix-x86/blob/56e6b8df3e95f4bc04f8b420a4cd8c82c70b9efa/mescc-tools-full-kaem.kaem
# - Paths to build inputs have been changed for nix
# Mes --- Maxwell Equations of Software
# Copyright © 2017,2019 Jan Nieuwenhuizen <janneke@gnu.org>
# Copyright © 2017,2019 Jeremiah Orians
#
# This file is part of Mes.
#
# Mes is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or (at
# your option) any later version.
#
# Mes is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Mes. If not, see <http://www.gnu.org/licenses/>.
${mkdir} -p ${out}/bin
${cp} ${M2} ${out}/bin/M2
${chmod} 0555 ${out}/bin/M2
${cp} ${M1} ${out}/bin/M1
${chmod} 0555 ${out}/bin/M1
${cp} ${hex2} ${out}/bin/hex2
${chmod} 0555 ${out}/bin/hex2
# M2-Mesoplanet searches for runtime dependencies in environment variables
# We can hardcode them with the "replace" utility from mescc-tools-extra
${replace} \
--file ${m2mesoplanet}/cc.c \
--output ./cc_patched.c \
--match-on "env_lookup(\"M2LIBC_PATH\")" \
--replace-with "\"${m2libc}\""
${replace} \
--file ${m2mesoplanet}/cc_spawn.c \
--output ./cc_spawn_patched.c \
--match-on "env_lookup(\"PATH\")" \
--replace-with "\"${out}/bin:\""
###############################################
# Phase-12 Build M2-Mesoplanet from M2-Planet #
###############################################
${M2} --architecture ${m2libcArch} \
-f ${m2libc}/sys/types.h \
-f ${m2libc}/stddef.h \
-f ${m2libc}/${m2libcArch}/linux/fcntl.c \
-f ${m2libc}/fcntl.c \
-f ${m2libc}/${m2libcArch}/linux/unistd.c \
-f ${m2libc}/${m2libcArch}/linux/sys/stat.c \
-f ${m2libc}/stdlib.c \
-f ${m2libc}/stdio.h \
-f ${m2libc}/stdio.c \
-f ${m2libc}/string.c \
-f ${m2libc}/bootstrappable.c \
-f ${m2mesoplanet}/cc.h \
-f ${m2mesoplanet}/cc_globals.c \
-f ${m2mesoplanet}/cc_env.c \
-f ${m2mesoplanet}/cc_reader.c \
-f ./cc_spawn_patched.c \
-f ${m2mesoplanet}/cc_core.c \
-f ${m2mesoplanet}/cc_macro.c \
-f ./cc_patched.c \
--debug \
-o ./M2-Mesoplanet-1.M1
${blood-elf-0} ${endianFlag} ${bloodFlag} -f ./M2-Mesoplanet-1.M1 -o ./M2-Mesoplanet-1-footer.M1
${M1} --architecture ${m2libcArch} \
${endianFlag} \
-f ${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1 \
-f ${m2libc}/${m2libcArch}/libc-full.M1 \
-f ./M2-Mesoplanet-1.M1 \
-f ./M2-Mesoplanet-1-footer.M1 \
-o ./M2-Mesoplanet-1.hex2
${hex2} --architecture ${m2libcArch} \
${endianFlag} \
--base-address ${baseAddress} \
-f ${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2 \
-f ./M2-Mesoplanet-1.hex2 \
-o ${out}/bin/M2-Mesoplanet
#################################################
# Phase-13 Build final blood-elf from C sources #
#################################################
${M2} --architecture ${m2libcArch} \
-f ${m2libc}/sys/types.h \
-f ${m2libc}/stddef.h \
-f ${m2libc}/${m2libcArch}/linux/fcntl.c \
-f ${m2libc}/fcntl.c \
-f ${m2libc}/${m2libcArch}/linux/unistd.c \
-f ${m2libc}/stdlib.c \
-f ${m2libc}/stdio.h \
-f ${m2libc}/stdio.c \
-f ${m2libc}/bootstrappable.c \
-f ${mesccTools}/stringify.c \
-f ${mesccTools}/blood-elf.c \
--debug \
-o ./blood-elf-1.M1
${blood-elf-0} ${endianFlag} ${bloodFlag} -f ./blood-elf-1.M1 -o ./blood-elf-1-footer.M1
${M1} --architecture ${m2libcArch} \
${endianFlag} \
-f ${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1 \
-f ${m2libc}/${m2libcArch}/libc-full.M1 \
-f ./blood-elf-1.M1 \
-f ./blood-elf-1-footer.M1 \
-o ./blood-elf-1.hex2
${hex2} --architecture ${m2libcArch} \
${endianFlag} \
--base-address ${baseAddress} \
-f ${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2 \
-f ./blood-elf-1.hex2 \
-o ${out}/bin/blood-elf
# Now we have our shipping debuggable blood-elf, the rest will be down hill from
# here as we have ALL of the core pieces of compiling and assembling debuggable
# programs in a debuggable form with corresponding C source code.
#############################################
# Phase-14 Build get_machine from C sources #
#############################################
${M2} --architecture ${m2libcArch} \
-f ${m2libc}/sys/types.h \
-f ${m2libc}/stddef.h \
-f ${m2libc}/${m2libcArch}/linux/unistd.c \
-f ${m2libc}/${m2libcArch}/linux/fcntl.c \
-f ${m2libc}/fcntl.c \
-f ${m2libc}/stdlib.c \
-f ${m2libc}/stdio.h \
-f ${m2libc}/stdio.c \
-f ${m2libc}/bootstrappable.c \
-f ${mesccTools}/get_machine.c \
--debug \
-o get_machine.M1
${out}/bin/blood-elf ${endianFlag} ${bloodFlag} -f ./get_machine.M1 -o ./get_machine-footer.M1
${M1} --architecture ${m2libcArch} \
${endianFlag} \
-f ${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1 \
-f ${m2libc}/${m2libcArch}/libc-full.M1 \
-f ./get_machine.M1 \
-f ./get_machine-footer.M1 \
-o ./get_machine.hex2
${hex2} --architecture ${m2libcArch} \
${endianFlag} \
--base-address ${baseAddress} \
-f ${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2 \
-f ./get_machine.hex2 \
-o ${out}/bin/get_machine
############################################
# Phase-15 Build M2-Planet from M2-Planet #
############################################
${M2} --architecture ${m2libcArch} \
-f ${m2libc}/sys/types.h \
-f ${m2libc}/stddef.h \
-f ${m2libc}/${m2libcArch}/linux/unistd.c \
-f ${m2libc}/${m2libcArch}/linux/fcntl.c \
-f ${m2libc}/fcntl.c \
-f ${m2libc}/stdlib.c \
-f ${m2libc}/stdio.h \
-f ${m2libc}/stdio.c \
-f ${m2libc}/bootstrappable.c \
-f ${m2planet}/cc.h \
-f ${m2planet}/cc_globals.c \
-f ${m2planet}/cc_reader.c \
-f ${m2planet}/cc_strings.c \
-f ${m2planet}/cc_types.c \
-f ${m2planet}/cc_core.c \
-f ${m2planet}/cc_macro.c \
-f ${m2planet}/cc.c \
--debug \
-o ./M2-1.M1
${out}/bin/blood-elf ${endianFlag} ${bloodFlag} -f ./M2-1.M1 -o ./M2-1-footer.M1
${M1} --architecture ${m2libcArch} \
${endianFlag} \
-f ${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1 \
-f ${m2libc}/${m2libcArch}/libc-full.M1 \
-f ./M2-1.M1 \
-f ./M2-1-footer.M1 \
-o ./M2-1.hex2
${hex2} --architecture ${m2libcArch} \
${endianFlag} \
--base-address ${baseAddress} \
-f ${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2 \
-f ./M2-1.hex2 \
-o ${out}/bin/M2-Planet

View file

@ -0,0 +1,178 @@
{
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;
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;
system = config.aux.system;
builders = config.aux.foundation.builders;
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}";
getExtraUtil = name: let
script = builtins.toFile "build-${name}.kaem" ''
''${M2} --architecture ${hex0.m2libc.architecture} \
-f ''${m2libc}/sys/types.h \
-f ''${m2libc}/stddef.h \
-f ''${m2libc}/${hex0.m2libc.architecture}/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}/stdlib.c \
-f ''${m2libc}/stdio.h \
-f ''${m2libc}/stdio.c \
-f ''${m2libc}/string.c \
-f ''${m2libc}/bootstrappable.c \
-f ''${mesccToolsExtra}/${name}.c \
--debug \
-o ${name}.M1
''${blood-elf-0} ${endianFlag} ${bloodFlag} -f ${name}.M1 -o ${name}-footer.M1
''${M1} --architecture ${hex0.m2libc.architecture} \
${endianFlag} \
-f ''${m2libc}/${hex0.m2libc.architecture}/${hex0.m2libc.architecture}_defs.M1 \
-f ''${m2libc}/${hex0.m2libc.architecture}/libc-full.M1 \
-f ${name}.M1 \
-f ${name}-footer.M1 \
-o ${name}.hex2
''${hex2} --architecture ${hex0.m2libc.architecture} \
${endianFlag} \
-f ''${m2libc}/${hex0.m2libc.architecture}/ELF-${hex0.m2libc.architecture}-debug.hex2 \
-f ${name}.hex2 \
--base-address ${baseAddress} \
-o ''${out}
'';
in
builders.raw.build {
pname = "mescc-tools-extra-${name}";
version = "1.6.0";
meta = cfg.meta;
executable = kaem-unwrapped.package;
args = [
"--verbose"
"--strict"
"--file"
script
];
src = hex0.src;
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;
bloodFlag = bloodFlag;
endianFlag = endianFlag;
baseAddress = baseAddress;
};
in {
options.aux.foundation.stages.stage0.mescc-tools = {
package = lib.options.create {
type = lib.types.package;
description = "The package to use for mescc-tools.";
};
meta = {
description = lib.options.create {
type = lib.types.string;
description = "Description for the package.";
default.value = "Collection of tools for use in bootstrapping.";
};
homepage = lib.options.create {
type = lib.types.string;
description = "Homepage for the package.";
default.value = "https://github.com/oriansj/stage0-posix";
};
license = lib.options.create {
# TODO: Add a proper type for licenses.
type = lib.types.attrs.any;
description = "License for the package.";
default.value = lib.licenses.gpl3Plus;
};
platforms = lib.options.create {
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = ["x86_64-linux" "aarch64-linux" "i686-linux"];
};
};
};
config = {
aux.foundation.stages.stage0.mescc-tools = {
package = lib.modules.overrides.default (builders.raw.build {
pname = "mescc-tools";
version = "1.6.0";
meta = cfg.meta;
executable = kaem-unwrapped.package;
args = [
"--verbose"
"--strict"
"--file"
./build.kaem
];
M1 = M1.package;
M2 = M2.package;
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;
bloodFlag = bloodFlag;
endianFlag = endianFlag;
baseAddress = baseAddress;
mkdir = getExtraUtil "mkdir";
cp = getExtraUtil "cp";
chmod = getExtraUtil "chmod";
replace = getExtraUtil "replace";
});
};
};
}

View file

@ -0,0 +1,223 @@
{
lib,
config,
}: let
cfg = config.aux.foundation.stages.stage0.hex0;
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 {
options.aux.foundation.stages.stage0.hex0 = {
package = lib.options.create {
type = lib.types.package;
description = "The package to use for hex0.";
};
meta = {
description = lib.options.create {
type = lib.types.string;
description = "Description for the package.";
default.value = "Minimal assembler for bootstrapping.";
};
homepage = lib.options.create {
type = lib.types.string;
description = "Homepage for the package.";
default.value = "https://github.com/oriansj/stage0-posix";
};
license = lib.options.create {
# TODO: Add a proper type for licenses.
type = lib.types.attrs.any;
description = "License for the package.";
default.value = lib.licenses.gpl3Plus;
};
platforms = lib.options.create {
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = ["x86_64-linux" "aarch64-linux" "i686-linux"];
};
};
hash = lib.options.create {
type = lib.types.nullish lib.types.string;
default = {
text = "<sha256 hash>";
value = null;
};
};
executable = lib.options.create {
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 = {
aux.foundation.stages.stage0.hex0 = {
package = lib.modules.overrides.default (builders.raw.build {
pname = "hex0";
version = "1.6.0";
meta = cfg.meta;
executable = cfg.executable;
args = [
"${cfg.src}/hex0_${architecture}.hex0"
(builtins.placeholder "out")
];
outputHashMode = "recursive";
outputHashAlgo = "sha256";
outputHash = cfg.hash;
});
hash = lib.modules.overrides.default (
if system == "x86_64-linux"
then "sha256-XTPsoKeI6wTZAF0UwEJPzuHelWOJe//wXg4HYO0dEJo="
else if system == "aarch64-linux"
then "sha256-RCgK9oZRDQUiWLVkcIBSR2HeoB+Bh0czthrpjFEkCaY="
else if system == "i686-linux"
then "sha256-QU3RPGy51W7M2xnfFY1IqruKzusrSLU+L190ztN6JW8="
else null
);
executable = lib.modules.overrides.default (import <nix/fetchurl.nix> {
name = "hex0-seed";
url = "https://github.com/oriansj/bootstrap-seeds/raw/b1263ff14a17835f4d12539226208c426ced4fba/POSIX/${architecture}/hex0-seed";
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

@ -0,0 +1,62 @@
{
lib,
config,
}: let
cfg = config.aux.foundation.stages.stage0.hex1;
hex0 = config.aux.foundation.stages.stage0.hex0;
system = config.aux.system;
builders = config.aux.foundation.builders;
in {
options.aux.foundation.stages.stage0.hex1 = {
package = lib.options.create {
type = lib.types.package;
description = "The package to use for hex0.";
};
meta = {
description = lib.options.create {
type = lib.types.string;
description = "Description for the package.";
default.value = "Collection of tools for use in bootstrapping.";
};
homepage = lib.options.create {
type = lib.types.string;
description = "Homepage for the package.";
default.value = "https://github.com/oriansj/stage0-posix";
};
license = lib.options.create {
# TODO: Add a proper type for licenses.
type = lib.types.attrs.any;
description = "License for the package.";
default.value = lib.licenses.gpl3Plus;
};
platforms = lib.options.create {
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = ["x86_64-linux" "aarch64-linux" "i686-linux"];
};
};
};
config = {
aux.foundation.stages.stage0.hex1 = {
package = lib.modules.overrides.default (builders.raw.build {
pname = "hex1";
version = "1.6.0";
meta = cfg.meta;
executable = hex0.package;
args = [
"${hex0.src}/hex1_${hex0.architecture}.hex0"
(builtins.placeholder "out")
];
});
};
};
}

View file

@ -0,0 +1,63 @@
{
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;
system = config.aux.system;
builders = config.aux.foundation.builders;
in {
options.aux.foundation.stages.stage0.hex2-0 = {
package = lib.options.create {
type = lib.types.package;
description = "The package to use for hex2-0.";
};
meta = {
description = lib.options.create {
type = lib.types.string;
description = "Description for the package.";
default.value = "Collection of tools for use in bootstrapping.";
};
homepage = lib.options.create {
type = lib.types.string;
description = "Homepage for the package.";
default.value = "https://github.com/oriansj/stage0-posix";
};
license = lib.options.create {
# TODO: Add a proper type for licenses.
type = lib.types.attrs.any;
description = "License for the package.";
default.value = lib.licenses.gpl3Plus;
};
platforms = lib.options.create {
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = ["x86_64-linux" "aarch64-linux" "i686-linux"];
};
};
};
config = {
aux.foundation.stages.stage0.hex2-0 = {
package = lib.modules.overrides.default (builders.raw.build {
pname = "hex2-0";
version = "1.6.0";
meta = cfg.meta;
executable = hex1.package;
args = [
"${hex0.src}/hex2_${hex0.architecture}.hex1"
(builtins.placeholder "out")
];
});
};
};
}

View file

@ -0,0 +1,73 @@
{
lib,
config,
}: let
cfg = config.aux.foundation.stages.stage0.catm;
hex0 = config.aux.foundation.stages.stage0.hex0;
hex1 = config.aux.foundation.stages.stage0.hex1;
hex2-0 = config.aux.foundation.stages.stage0.hex2-0;
system = config.aux.system;
builders = config.aux.foundation.builders;
in {
options.aux.foundation.stages.stage0.catm = {
package = lib.options.create {
type = lib.types.package;
description = "The package to use for catm.";
};
meta = {
description = lib.options.create {
type = lib.types.string;
description = "Description for the package.";
default.value = "Collection of tools for use in bootstrapping.";
};
homepage = lib.options.create {
type = lib.types.string;
description = "Homepage for the package.";
default.value = "https://github.com/oriansj/stage0-posix";
};
license = lib.options.create {
# TODO: Add a proper type for licenses.
type = lib.types.attrs.any;
description = "License for the package.";
default.value = lib.licenses.gpl3Plus;
};
platforms = lib.options.create {
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = ["x86_64-linux" "aarch64-linux" "i686-linux"];
};
};
};
config = {
aux.foundation.stages.stage0.catm = {
package = lib.modules.overrides.default (builders.raw.build {
pname = "catm";
version = "1.6.0";
meta = cfg.meta;
executable =
if hex0.architecture == "AArch64"
then hex1.package
else hex2-0.package;
args =
if hex0.architecture == "AArch64"
then [
"${hex0.src}/catm_${hex0.architecture}.hex1"
(builtins.placeholder "out")
]
else [
"${hex0.src}/catm_${hex0.architecture}.hex2"
(builtins.placeholder "out")
];
});
};
};
}

View file

@ -0,0 +1,79 @@
{
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;
catm = config.aux.foundation.stages.stage0.catm;
system = config.aux.system;
builders = config.aux.foundation.builders;
in {
options.aux.foundation.stages.stage0.M0 = {
package = lib.options.create {
type = lib.types.package;
description = "The package to use for M0.";
};
meta = {
description = lib.options.create {
type = lib.types.string;
description = "Description for the package.";
default.value = "Collection of tools for use in bootstrapping.";
};
homepage = lib.options.create {
type = lib.types.string;
description = "Homepage for the package.";
default.value = "https://github.com/oriansj/stage0-posix";
};
license = lib.options.create {
# TODO: Add a proper type for licenses.
type = lib.types.attrs.any;
description = "License for the package.";
default.value = lib.licenses.gpl3Plus;
};
platforms = lib.options.create {
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = ["x86_64-linux" "aarch64-linux" "i686-linux"];
};
};
};
config = {
aux.foundation.stages.stage0.M0 = {
package = lib.modules.overrides.default (builders.raw.build {
pname = "M0";
version = "1.6.0";
meta = cfg.meta;
executable = hex2-0.package;
args = let
M0_hex2-0 = builders.raw.build {
pname = "M0_hex2-0";
version = "1.6.0";
meta = cfg.meta;
executable = catm.package;
args = [
(builtins.placeholder "out")
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/ELF-${hex0.m2libc.architecture}.hex2"
"${hex0.src}/M0_${hex0.architecture}.hex2"
];
};
in [
M0_hex2-0
(builtins.placeholder "out")
];
});
};
};
}

View file

@ -0,0 +1,93 @@
{
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;
catm = config.aux.foundation.stages.stage0.catm;
M0 = config.aux.foundation.stages.stage0.M0;
system = config.aux.system;
builders = config.aux.foundation.builders;
in {
options.aux.foundation.stages.stage0.cc_arch = {
package = lib.options.create {
type = lib.types.package;
description = "The package to use for cc_arch.";
};
meta = {
description = lib.options.create {
type = lib.types.string;
description = "Description for the package.";
default.value = "Collection of tools for use in bootstrapping.";
};
homepage = lib.options.create {
type = lib.types.string;
description = "Homepage for the package.";
default.value = "https://github.com/oriansj/stage0-posix";
};
license = lib.options.create {
# TODO: Add a proper type for licenses.
type = lib.types.attrs.any;
description = "License for the package.";
default.value = lib.licenses.gpl3Plus;
};
platforms = lib.options.create {
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = ["x86_64-linux" "aarch64-linux" "i686-linux"];
};
};
};
config = {
aux.foundation.stages.stage0.cc_arch = {
package = lib.modules.overrides.default (builders.raw.build {
pname = "cc_arch";
version = "1.6.0";
meta = cfg.meta;
executable = hex2-0.package;
args = let
cc_arch0_hex2-0 = builders.raw.build {
pname = "cc_arch0_hex2-0";
version = "1.6.0";
meta = cfg.meta;
executable = M0.package;
args = [
"${hex0.src}/cc_${hex0.m2libc.architecture}.M1"
(builtins.placeholder "out")
];
};
cc_arch1_hex2-0 = builders.raw.build {
pname = "cc_arch1_hex2-0";
version = "1.6.0";
meta = cfg.meta;
executable = catm.package;
args = [
(builtins.placeholder "out")
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/ELF-${hex0.m2libc.architecture}.hex2"
cc_arch0_hex2-0
];
};
in [
cc_arch1_hex2-0
(builtins.placeholder "out")
];
});
};
};
}

View file

@ -0,0 +1,144 @@
{
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;
catm = config.aux.foundation.stages.stage0.catm;
M0 = config.aux.foundation.stages.stage0.M0;
cc_arch = config.aux.foundation.stages.stage0.cc_arch;
system = config.aux.system;
builders = config.aux.foundation.builders;
in {
options.aux.foundation.stages.stage0.M2 = {
package = lib.options.create {
type = lib.types.package;
description = "The package to use for M2.";
};
meta = {
description = lib.options.create {
type = lib.types.string;
description = "Description for the package.";
default.value = "Collection of tools for use in bootstrapping.";
};
homepage = lib.options.create {
type = lib.types.string;
description = "Homepage for the package.";
default.value = "https://github.com/oriansj/stage0-posix";
};
license = lib.options.create {
# TODO: Add a proper type for licenses.
type = lib.types.attrs.any;
description = "License for the package.";
default.value = lib.licenses.gpl3Plus;
};
platforms = lib.options.create {
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = ["x86_64-linux" "aarch64-linux" "i686-linux"];
};
};
};
config = {
aux.foundation.stages.stage0.M2 = {
package = lib.modules.overrides.default (builders.raw.build {
pname = "M2";
version = "1.6.0";
meta = cfg.meta;
executable = hex2-0.package;
args = let
M2_c = builders.raw.build {
pname = "M2_c";
version = "1.6.0";
meta = cfg.meta;
executable = catm.package;
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"
];
};
M2_M1 = builders.raw.build {
pname = "M2_M1";
version = "1.6.0";
meta = cfg.meta;
executable = cc_arch.package;
args = [
M2_c
(builtins.placeholder "out")
];
};
M2_M1' = builders.raw.build {
pname = "M2_M1";
version = "1.6.0";
meta = cfg.meta;
executable = catm.package;
args = [
(builtins.placeholder "out")
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/${hex0.m2libc.architecture}_defs.M1"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/libc-core.M1"
M2_M1
];
};
M2_hex2-0 = builders.raw.build {
pname = "M2_hex2-0";
version = "1.6.0";
meta = cfg.meta;
executable = M0.package;
args = [
M2_M1'
(builtins.placeholder "out")
];
};
M2_hex2-0' = builders.raw.build {
pname = "M2_hex2-0";
version = "1.6.0";
meta = cfg.meta;
executable = catm.package;
args = [
(builtins.placeholder "out")
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/ELF-${hex0.m2libc.architecture}.hex2"
M2_hex2-0
];
};
in [
M2_hex2-0'
(builtins.placeholder "out")
];
});
};
};
}

View file

@ -0,0 +1,134 @@
{
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;
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;
system = config.aux.system;
builders = config.aux.foundation.builders;
in {
options.aux.foundation.stages.stage0.blood-elf = {
package = lib.options.create {
type = lib.types.package;
description = "The package to use for blood-elf.";
};
meta = {
description = lib.options.create {
type = lib.types.string;
description = "Description for the package.";
default.value = "Collection of tools for use in bootstrapping.";
};
homepage = lib.options.create {
type = lib.types.string;
description = "Homepage for the package.";
default.value = "https://github.com/oriansj/stage0-posix";
};
license = lib.options.create {
# TODO: Add a proper type for licenses.
type = lib.types.attrs.any;
description = "License for the package.";
default.value = lib.licenses.gpl3Plus;
};
platforms = lib.options.create {
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = ["x86_64-linux" "aarch64-linux" "i686-linux"];
};
};
};
config = {
aux.foundation.stages.stage0.blood-elf = {
package = lib.modules.overrides.default (builders.raw.build {
pname = "blood-elf";
version = "1.6.0";
meta = cfg.meta;
executable = hex2-0.package;
args = let
blood-elf_M1 = builders.raw.build {
pname = "blood-elf_M1";
version = "1.6.0";
meta = cfg.meta;
executable = M2.package;
args = [
"--architecture"
hex0.m2libc.architecture
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/bootstrap.c"
"-f"
"${hex0.m2libc.src}/bootstrappable.c"
"-f"
"${hex0.mescc-tools.src}/stringify.c"
"-f"
"${hex0.mescc-tools.src}/blood-elf.c"
"--bootstrap-mode"
"-o"
(builtins.placeholder "out")
];
};
blood-elf_M1' = builders.raw.build {
pname = "blood-elf_M1-1";
version = "1.6.0";
meta = cfg.meta;
executable = catm.package;
args = [
(builtins.placeholder "out")
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/${hex0.m2libc.architecture}_defs.M1"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/libc-core.M1"
blood-elf_M1
];
};
blood-elf_hex2-0 = builders.raw.build {
pname = "blood-elf_hex2-0";
version = "1.6.0";
meta = cfg.meta;
executable = M0.package;
args = [
blood-elf_M1'
(builtins.placeholder "out")
];
};
blood-elf_hex2-0' = builders.raw.build {
pname = "blood-elf_hex2-0-1";
version = "1.6.0";
meta = cfg.meta;
executable = catm.package;
args = [
(builtins.placeholder "out")
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/ELF-${hex0.m2libc.architecture}.hex2"
blood-elf_hex2-0
];
};
in [
blood-elf_hex2-0'
(builtins.placeholder "out")
];
});
};
};
}

View file

@ -0,0 +1,159 @@
{
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;
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;
system = config.aux.system;
builders = config.aux.foundation.builders;
in {
options.aux.foundation.stages.stage0.M1-0 = {
package = lib.options.create {
type = lib.types.package;
description = "The package to use for M1-0.";
};
meta = {
description = lib.options.create {
type = lib.types.string;
description = "Description for the package.";
default.value = "Collection of tools for use in bootstrapping.";
};
homepage = lib.options.create {
type = lib.types.string;
description = "Homepage for the package.";
default.value = "https://github.com/oriansj/stage0-posix";
};
license = lib.options.create {
# TODO: Add a proper type for licenses.
type = lib.types.attrs.any;
description = "License for the package.";
default.value = lib.licenses.gpl3Plus;
};
platforms = lib.options.create {
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = ["x86_64-linux" "aarch64-linux" "i686-linux"];
};
};
};
config = {
aux.foundation.stages.stage0.M1-0 = {
package = lib.modules.overrides.default (builders.raw.build {
pname = "M1-0";
version = "1.6.0";
meta = cfg.meta;
executable = hex2-0.package;
args = let
M1-macro-0_M1 = builders.raw.build {
pname = "M1-macro-0_M1";
version = "1.6.0";
meta = cfg.meta;
executable = M2.package;
args = [
"--architecture"
hex0.m2libc.architecture
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/bootstrap.c"
"-f"
"${hex0.m2libc.src}/bootstrappable.c"
"-f"
"${hex0.mescc-tools.src}/stringify.c"
"-f"
"${hex0.mescc-tools.src}/M1-macro.c"
"--bootstrap-mode"
"--debug"
"-o"
(builtins.placeholder "out")
];
};
M1-macro-0-footer_M1 = builders.raw.build {
pname = "M1-macro-0-footer_M1";
version = "1.6.0";
meta = cfg.meta;
executable = blood-elf.package;
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"
)
"-o"
(builtins.placeholder "out")
];
};
M1-macro-0_M1' = builders.raw.build {
pname = "M1-macro-0_M1-1";
version = "1.6.0";
meta = cfg.meta;
executable = catm.package;
args = [
(builtins.placeholder "out")
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/${hex0.m2libc.architecture}_defs.M1"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/libc-core.M1"
M1-macro-0_M1
M1-macro-0-footer_M1
];
};
M1-macro-0_hex2-0 = builders.raw.build {
pname = "M1-macro-0_hex2-0";
version = "1.6.0";
meta = cfg.meta;
executable = M0.package;
args = [
M1-macro-0_M1'
(builtins.placeholder "out")
];
};
M1-macro-0_hex2-0' = builders.raw.build {
pname = "M1-macro-0_hex2-0-1";
version = "1.6.0";
meta = cfg.meta;
executable = catm.package;
args = [
(builtins.placeholder "out")
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/ELF-${hex0.m2libc.architecture}-debug.hex2"
M1-macro-0_hex2-0
];
};
in [
M1-macro-0_hex2-0'
(builtins.placeholder "out")
];
});
};
};
}

View file

@ -0,0 +1,178 @@
{
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;
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-0 = config.aux.foundation.stages.stage0.M1-0;
system = config.aux.system;
builders = config.aux.foundation.builders;
in {
options.aux.foundation.stages.stage0.hex2-1 = {
package = lib.options.create {
type = lib.types.package;
description = "The package to use for hex2-1.";
};
meta = {
description = lib.options.create {
type = lib.types.string;
description = "Description for the package.";
default.value = "Collection of tools for use in bootstrapping.";
};
homepage = lib.options.create {
type = lib.types.string;
description = "Homepage for the package.";
default.value = "https://github.com/oriansj/stage0-posix";
};
license = lib.options.create {
# TODO: Add a proper type for licenses.
type = lib.types.attrs.any;
description = "License for the package.";
default.value = lib.licenses.gpl3Plus;
};
platforms = lib.options.create {
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = ["x86_64-linux" "aarch64-linux" "i686-linux"];
};
};
};
config = {
aux.foundation.stages.stage0.hex2-1 = {
package = lib.modules.overrides.default (builders.raw.build {
pname = "hex2-1";
version = "1.6.0";
meta = cfg.meta;
executable = hex2-0.package;
args = let
hex2_linker_M1 = builders.raw.build {
pname = "hex2_linker_M1";
version = "1.6.0";
meta = cfg.meta;
executable = M2.package;
args = [
"--architecture"
hex0.m2libc.architecture
"-f"
"${hex0.m2libc.src}/sys/types.h"
"-f"
"${hex0.m2libc.src}/stddef.h"
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/unistd.c"
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/fcntl.c"
"-f"
"${hex0.m2libc.src}/fcntl.c"
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/sys/stat.c"
"-f"
"${hex0.m2libc.src}/stdlib.c"
"-f"
"${hex0.m2libc.src}/stdio.h"
"-f"
"${hex0.m2libc.src}/stdio.c"
"-f"
"${hex0.m2libc.src}/bootstrappable.c"
"-f"
"${hex0.mescc-tools.src}/hex2.h"
"-f"
"${hex0.mescc-tools.src}/hex2_linker.c"
"-f"
"${hex0.mescc-tools.src}/hex2_word.c"
"-f"
"${hex0.mescc-tools.src}/hex2.c"
"--debug"
"-o"
(builtins.placeholder "out")
];
};
hex2_linker-footer_M1 = builders.raw.build {
pname = "hex2_linker-footer_M1";
version = "1.6.0";
meta = cfg.meta;
executable = blood-elf.package;
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"
)
"-o"
(builtins.placeholder "out")
];
};
hex2_linker_hex2 = builders.raw.build {
pname = "hex2_linker_hex2";
version = "1.6.0";
meta = cfg.meta;
executable = M1-0.package;
args = [
"--architecture"
hex0.m2libc.architecture
(
if config.aux.platform.endian == "little"
then "--little-endian"
else "--big-endian"
)
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/${hex0.m2libc.architecture}_defs.M1"
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/libc-full.M1"
"-f"
hex2_linker_M1
"-f"
hex2_linker-footer_M1
"-o"
(builtins.placeholder "out")
];
};
hex2_linker_hex2' = builders.raw.build {
pname = "hex2_linker_hex2-1";
version = "1.6.0";
meta = cfg.meta;
executable = catm.package;
args = [
(builtins.placeholder "out")
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/ELF-${hex0.m2libc.architecture}-debug.hex2"
hex2_linker_hex2
];
};
in [
hex2_linker_hex2'
(builtins.placeholder "out")
];
});
};
};
}

View file

@ -0,0 +1,184 @@
{
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;
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-0 = config.aux.foundation.stages.stage0.M1-0;
hex2-1 = config.aux.foundation.stages.stage0.hex2-1;
system = config.aux.system;
builders = config.aux.foundation.builders;
in {
options.aux.foundation.stages.stage0.M1 = {
package = lib.options.create {
type = lib.types.package;
description = "The package to use for M1.";
};
meta = {
description = lib.options.create {
type = lib.types.string;
description = "Description for the package.";
default.value = "Collection of tools for use in bootstrapping.";
};
homepage = lib.options.create {
type = lib.types.string;
description = "Homepage for the package.";
default.value = "https://github.com/oriansj/stage0-posix";
};
license = lib.options.create {
# TODO: Add a proper type for licenses.
type = lib.types.attrs.any;
description = "License for the package.";
default.value = lib.licenses.gpl3Plus;
};
platforms = lib.options.create {
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = ["x86_64-linux" "aarch64-linux" "i686-linux"];
};
};
};
config = {
aux.foundation.stages.stage0.M1 = {
package = lib.modules.overrides.default (builders.raw.build {
pname = "M1";
version = "1.6.0";
meta = cfg.meta;
executable = hex2-1.package;
args = let
M1-macro_M1 = builders.raw.build {
pname = "M1-macro_M1";
version = "1.6.0";
meta = cfg.meta;
executable = M2.package;
args = [
"--architecture"
hex0.m2libc.architecture
"-f"
"${hex0.m2libc.src}/sys/types.h"
"-f"
"${hex0.m2libc.src}/stddef.h"
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/unistd.c"
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/fcntl.c"
"-f"
"${hex0.m2libc.src}/fcntl.c"
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/sys/stat.c"
"-f"
"${hex0.m2libc.src}/string.c"
"-f"
"${hex0.m2libc.src}/stdlib.c"
"-f"
"${hex0.m2libc.src}/stdio.h"
"-f"
"${hex0.m2libc.src}/stdio.c"
"-f"
"${hex0.m2libc.src}/bootstrappable.c"
"-f"
"${hex0.mescc-tools.src}/stringify.c"
"-f"
"${hex0.mescc-tools.src}/M1-macro.c"
"--debug"
"-o"
(builtins.placeholder "out")
];
};
M1-macro-footer_M1 = builders.raw.build {
pname = "M1-macro-footer_M1";
version = "1.6.0";
meta = cfg.meta;
executable = blood-elf.package;
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"
)
"-o"
(builtins.placeholder "out")
];
};
M1-macro_hex2 = builders.raw.build {
pname = "M1-macro_hex2";
version = "1.6.0";
meta = cfg.meta;
executable = M1-0.package;
args = [
"--architecture"
hex0.m2libc.architecture
(
if config.aux.platform.endian == "little"
then "--little-endian"
else "--big-endian"
)
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/${hex0.m2libc.architecture}_defs.M1"
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/libc-full.M1"
"-f"
M1-macro_M1
"-f"
M1-macro-footer_M1
"-o"
(builtins.placeholder "out")
];
};
in [
"--architecture"
hex0.m2libc.architecture
(
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}"
)
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/ELF-${hex0.m2libc.architecture}-debug.hex2"
"-f"
M1-macro_hex2
"-o"
(builtins.placeholder "out")
];
});
};
};
}

View file

@ -0,0 +1,184 @@
{
lib,
config,
}: let
cfg = config.aux.foundation.stages.stage0.hex2;
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-1 = config.aux.foundation.stages.stage0.hex2-1;
system = config.aux.system;
builders = config.aux.foundation.builders;
in {
options.aux.foundation.stages.stage0.hex2 = {
package = lib.options.create {
type = lib.types.package;
description = "The package to use for hex2.";
};
meta = {
description = lib.options.create {
type = lib.types.string;
description = "Description for the package.";
default.value = "Collection of tools for use in bootstrapping.";
};
homepage = lib.options.create {
type = lib.types.string;
description = "Homepage for the package.";
default.value = "https://github.com/oriansj/stage0-posix";
};
license = lib.options.create {
# TODO: Add a proper type for licenses.
type = lib.types.attrs.any;
description = "License for the package.";
default.value = lib.licenses.gpl3Plus;
};
platforms = lib.options.create {
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = ["x86_64-linux" "aarch64-linux" "i686-linux"];
};
};
};
config = {
aux.foundation.stages.stage0.hex2 = {
package = lib.modules.overrides.default (builders.raw.build {
pname = "hex2";
version = "1.6.0";
meta = cfg.meta;
executable = hex2-1.package;
args = let
hex2_linker_M1 = builders.raw.build {
pname = "hex2_linker_M1";
version = "1.6.0";
meta = cfg.meta;
executable = M2.package;
args = [
"--architecture"
hex0.m2libc.architecture
"-f"
"${hex0.m2libc.src}/sys/types.h"
"-f"
"${hex0.m2libc.src}/stddef.h"
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/unistd.c"
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/fcntl.c"
"-f"
"${hex0.m2libc.src}/fcntl.c"
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/sys/stat.c"
"-f"
"${hex0.m2libc.src}/stdlib.c"
"-f"
"${hex0.m2libc.src}/stdio.h"
"-f"
"${hex0.m2libc.src}/stdio.c"
"-f"
"${hex0.m2libc.src}/bootstrappable.c"
"-f"
"${hex0.mescc-tools.src}/hex2.h"
"-f"
"${hex0.mescc-tools.src}/hex2_linker.c"
"-f"
"${hex0.mescc-tools.src}/hex2_word.c"
"-f"
"${hex0.mescc-tools.src}/hex2.c"
"--debug"
"-o"
(builtins.placeholder "out")
];
};
hex2_linker-footer_M1 = builders.raw.build {
pname = "hex2_linker-footer_M1";
version = "1.6.0";
meta = cfg.meta;
executable = blood-elf.package;
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"
)
"-o"
(builtins.placeholder "out")
];
};
hex2_linker_hex2 = builders.raw.build {
pname = "hex2_linker_hex2";
version = "1.6.0";
meta = cfg.meta;
executable = M1.package;
args = [
"--architecture"
hex0.m2libc.architecture
(
if config.aux.platform.endian == "little"
then "--little-endian"
else "--big-endian"
)
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/${hex0.m2libc.architecture}_defs.M1"
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/libc-full.M1"
"-f"
hex2_linker_M1
"-f"
hex2_linker-footer_M1
"-o"
(builtins.placeholder "out")
];
};
in [
"--architecture"
hex0.m2libc.architecture
(
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}"
)
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/ELF-${hex0.m2libc.architecture}-debug.hex2"
"-f"
hex2_linker_hex2
"-o"
(builtins.placeholder "out")
];
});
};
};
}

View file

@ -0,0 +1,186 @@
{
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;
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;
system = config.aux.system;
builders = config.aux.foundation.builders;
in {
options.aux.foundation.stages.stage0.kaem-unwrapped = {
package = lib.options.create {
type = lib.types.package;
description = "The package to use for kaem-unwrapped.";
};
meta = {
description = lib.options.create {
type = lib.types.string;
description = "Description for the package.";
default.value = "Collection of tools for use in bootstrapping.";
};
homepage = lib.options.create {
type = lib.types.string;
description = "Homepage for the package.";
default.value = "https://github.com/oriansj/stage0-posix";
};
license = lib.options.create {
# TODO: Add a proper type for licenses.
type = lib.types.attrs.any;
description = "License for the package.";
default.value = lib.licenses.gpl3Plus;
};
platforms = lib.options.create {
type = lib.types.list.of lib.types.string;
description = "Platforms the package supports.";
default.value = ["x86_64-linux" "aarch64-linux" "i686-linux"];
};
};
};
config = {
aux.foundation.stages.stage0.kaem-unwrapped = {
package = lib.modules.overrides.default (builders.raw.build {
pname = "kaem-unwrapped";
version = "1.6.0";
meta = cfg.meta;
executable = hex2.package;
args = let
kaem_M1 = builders.raw.build {
pname = "kaem_M1";
version = "1.6.0";
meta = cfg.meta;
executable = M2.package;
args = [
"--architecture"
hex0.m2libc.architecture
"-f"
"${hex0.m2libc.src}/sys/types.h"
"-f"
"${hex0.m2libc.src}/stddef.h"
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/unistd.c"
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/fcntl.c"
"-f"
"${hex0.m2libc.src}/fcntl.c"
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/linux/sys/stat.c"
"-f"
"${hex0.m2libc.src}/string.c"
"-f"
"${hex0.m2libc.src}/stdlib.c"
"-f"
"${hex0.m2libc.src}/stdio.h"
"-f"
"${hex0.m2libc.src}/stdio.c"
"-f"
"${hex0.m2libc.src}/bootstrappable.c"
"-f"
"${hex0.mescc-tools.src}/Kaem/kaem.h"
"-f"
"${hex0.mescc-tools.src}/Kaem/variable.c"
"-f"
"${hex0.mescc-tools.src}/Kaem/kaem_globals.c"
"-f"
"${hex0.mescc-tools.src}/Kaem/kaem.c"
"--debug"
"-o"
(builtins.placeholder "out")
];
};
kaem-footer_M1 = builders.raw.build {
pname = "kaem-footer_M1";
version = "1.6.0";
meta = cfg.meta;
executable = blood-elf.package;
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"
)
"-o"
(builtins.placeholder "out")
];
};
kaem_hex2 = builders.raw.build {
pname = "kaem_hex2";
version = "1.6.0";
meta = cfg.meta;
executable = M1.package;
args = [
"--architecture"
hex0.m2libc.architecture
(
if config.aux.platform.endian == "little"
then "--little-endian"
else "--big-endian"
)
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/${hex0.m2libc.architecture}_defs.M1"
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/libc-full.M1"
"-f"
kaem_M1
"-f"
kaem-footer_M1
"-o"
(builtins.placeholder "out")
];
};
in [
"--architecture"
hex0.m2libc.architecture
(
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}"
)
"-f"
"${hex0.m2libc.src}/${hex0.m2libc.architecture}/ELF-${hex0.m2libc.architecture}-debug.hex2"
"-f"
kaem_hex2
"-o"
(builtins.placeholder "out")
];
});
};
};
}

View file

@ -0,0 +1,17 @@
{
lib,
config,
}: let
cfg = config.aux.foundation.stages.stage1;
in {
includes = [
./mes
];
config = {
exports = {
packages = {
};
};
};
}

View file

@ -0,0 +1,12 @@
{
lib,
config,
}: let
system = config.aux.system;
builders = config.aux.foundation.builders;
in {
config = {
aux.foundation.stages.stage0.mes = {
};
};
}

View file

@ -0,0 +1,11 @@
{lib}: {
options.aux = {
system = lib.options.create {
type = lib.types.string;
description = ''
The system to build packages for. This value can be provided as either
`config.aux.system` or by setting the `system` argument for modules.
'';
};
};
}

View file

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

View file

@ -144,5 +144,19 @@ lib: {
valid = builtins.concatMap process names; valid = builtins.concatMap process names;
in in
builtins.listToAttrs valid; builtins.listToAttrs valid;
## Generate an attribute set from a list of names and a function that is
## applied to each name.
##
## @type (List String) -> (String -> Any) -> Attrs
generate = names: f: let
pairs =
builtins.map (name: {
inherit name;
value = f name;
})
names;
in
builtins.listToAttrs pairs;
}; };
} }

View file

@ -6,6 +6,7 @@ let
./fp ./fp
./generators ./generators
./importers ./importers
./licenses
./lists ./lists
./math ./math
./modules ./modules

1270
lib/src/licenses/all.nix Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,33 @@
lib: {
licenses = let
raw = import ./all.nix;
defaults = name: {
inherit name;
free = true;
};
withDefaults = name: license: (defaults name) // license;
withSpdx = license:
if license ? spdx
then
license
// {
url = "https://spdx.org/licenses/${license.spdx}.html";
}
else license;
withRedistributable = license:
{
redistributable = license.free;
}
// license;
normalize = name:
lib.fp.pipe [
(withDefaults name)
withSpdx
withRedistributable
];
in
builtins.mapAttrs normalize raw;
}

View file

@ -474,8 +474,8 @@ lib: {
prefix ? [], prefix ? [],
}: }:
lib.modules.run { lib.modules.run {
modules = settings.modules ++ extensions.modules; modules = (settings.modules or []) ++ (extensions.modules or []);
args = (settings.args or {}) // extensions.args; args = (settings.args or {}) // (extensions.args or {});
prefix = extensions.prefix or settings.prefix or []; prefix = extensions.prefix or settings.prefix or [];
}; };

View file

@ -44,5 +44,13 @@ lib: {
else x) else x)
] ]
value; value;
## Get an output of a package.
##
## @type String -> Package -> String
getOutput = output: package:
if ! package ? outputSpecified || !package.outputSpecified
then package.${output} or package.out or package
else package;
}; };
} }

View file

@ -32,5 +32,37 @@ lib: {
&& builtins.dirOf (builtins.toString value) == builtins.storeDir && builtins.dirOf (builtins.toString value) == builtins.storeDir
else false; else false;
}; };
## Create a search path from a list of paths.
##
## @type String -> [String] -> String
search = target: paths:
lib.strings.concatMapSep
":"
(path: path + "/" + target)
(builtins.filter (value: value != null) paths);
## Create a search path from a list of packages.
##
## @type String -> [Package] -> String
searchFromOutput = output: target: packages:
lib.paths.search
target
(builtins.map (lib.packages.getOutput output) packages);
## Create a search path for the binary output of a package.
##
## @type [Package] -> String
bin = lib.paths.searchFromOutput "bin" "bin";
## Create a search path for the library output of a package.
##
## @type [Package] -> String
lib = lib.paths.searchFromOutput "lib" "lib";
## Create a search path for the include output of a package.
##
## @type [Package] -> String
include = lib.paths.searchFromOutput "dev" "include";
}; };
} }