feat: add foundation
This commit is contained in:
parent
39ea93b671
commit
3fe60580da
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
.direnv
|
||||
result
|
|
@ -24,6 +24,7 @@ may collaborate.
|
|||
|
||||
## Experiments
|
||||
|
||||
| Name | Phase | Description |
|
||||
| ---------------- | --------- | -------------------------------------------------------- |
|
||||
| [Aux Lib](./lib) | Iteration | A library of common functions used in the Aux ecosystem. |
|
||||
| Name | Phase | Description |
|
||||
| ------------------------------ | --------- | -------------------------------------------------------------------------- |
|
||||
| [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
23
foundation/LICENSE
Normal 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
95
foundation/README.md
Normal 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
23
foundation/flake.lock
Normal 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
37
foundation/flake.nix
Normal 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
|
||||
);
|
||||
};
|
||||
}
|
63
foundation/src/builders/file/text/default.nix
Normal file
63
foundation/src/builders/file/text/default.nix
Normal 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;
|
||||
});
|
||||
};
|
||||
};
|
||||
}
|
65
foundation/src/builders/kaem/default.nix
Normal file
65
foundation/src/builders/kaem/default.nix
Normal 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;
|
||||
});
|
||||
};
|
||||
};
|
||||
}
|
42
foundation/src/builders/raw/default.nix
Normal file
42
foundation/src/builders/raw/default.nix
Normal 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;
|
||||
});
|
||||
};
|
||||
};
|
||||
}
|
12
foundation/src/default.nix
Normal file
12
foundation/src/default.nix
Normal 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
|
38
foundation/src/exports/default.nix
Normal file
38
foundation/src/exports/default.nix
Normal 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"]);
|
||||
};
|
||||
}
|
324
foundation/src/platform/default.nix
Normal file
324
foundation/src/platform/default.nix
Normal 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}");
|
||||
};
|
||||
}
|
76
foundation/src/stages/stage0/default.nix
Normal file
76
foundation/src/stages/stage0/default.nix
Normal 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;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
3
foundation/src/stages/stage0/kaem/build.kaem
Normal file
3
foundation/src/stages/stage0/kaem/build.kaem
Normal file
|
@ -0,0 +1,3 @@
|
|||
mkdir -p ${out}/bin
|
||||
cp ${kaemUnwrapped} ${out}/bin/kaem
|
||||
chmod 555 ${out}/bin/kaem
|
77
foundation/src/stages/stage0/kaem/default.nix
Normal file
77
foundation/src/stages/stage0/kaem/default.nix
Normal 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];
|
||||
});
|
||||
};
|
||||
};
|
||||
}
|
40
foundation/src/stages/stage0/mescc-tools-extra/build.kaem
Normal file
40
foundation/src/stages/stage0/mescc-tools-extra/build.kaem
Normal 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
|
||||
|
79
foundation/src/stages/stage0/mescc-tools-extra/default.nix
Normal file
79
foundation/src/stages/stage0/mescc-tools-extra/default.nix
Normal 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;
|
||||
});
|
||||
};
|
||||
};
|
||||
}
|
205
foundation/src/stages/stage0/mescc-tools/build.kaem
Normal file
205
foundation/src/stages/stage0/mescc-tools/build.kaem
Normal 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
|
||||
|
178
foundation/src/stages/stage0/mescc-tools/default.nix
Normal file
178
foundation/src/stages/stage0/mescc-tools/default.nix
Normal 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";
|
||||
});
|
||||
};
|
||||
};
|
||||
}
|
223
foundation/src/stages/stage0/phases/phase00.nix
Normal file
223
foundation/src/stages/stage0/phases/phase00.nix
Normal 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.";
|
||||
};
|
||||
|
||||