Skip to content

Commit

Permalink
stage0-posix: move to top-level
Browse files Browse the repository at this point in the history
Towards ngi-nix/ngipkgs#304

Co-authored-by: Yifei Sun <ysun@hey.com>
Co-authored-by: Ali Jamadi <jamadi1377@gmail.com>
Co-authored-by: yakampe <yanis.kampe.cv@gmail.com>
Co-authored-by: GetPsyched <priyanshu@getpsyched.dev>
Co-authored-by: Adrien Faure <adrien.faure@protonmail.com>
Co-authored-by: Robert James Hernandez <rob@sarcasticadmin.com>
Co-authored-by: Shahar "Dawn" Or <mightyiampresence@gmail.com>
  • Loading branch information
7 people committed Jun 25, 2024
1 parent efb39c6 commit 64c42e4
Show file tree
Hide file tree
Showing 27 changed files with 68 additions and 72 deletions.
9 changes: 4 additions & 5 deletions pkgs/os-specific/linux/minimal-bootstrap/bash/2.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{ lib
, derivationWithMeta
, fetchurl
, kaem
, stage0-posix
, tinycc
, gnumake
, gnupatch
, coreutils
, mescc-tools-extra
, bash_2_05
}:
let
Expand Down Expand Up @@ -66,7 +65,7 @@ let
})
];
in
kaem.runCommand "${pname}-${version}" {
stage0-posix.kaem.runCommand "${pname}-${version}" {
inherit pname version;

nativeBuildInputs = [
Expand Down Expand Up @@ -105,12 +104,12 @@ kaem.runCommand "${pname}-${version}" {
bash_2_05
coreutils
# provides untar, ungz, and unbz2
mescc-tools-extra
stage0-posix.mescc-tools-extra
]);
} // (builtins.removeAttrs env [ "nativeBuildInputs" ]));

passthru.tests.get-version = result:
kaem.runCommand "${pname}-get-version-${version}" {} ''
stage0-posix.kaem.runCommand "${pname}-get-version-${version}" {} ''
${result}/bin/bash --version
mkdir ''${out}
'';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ lib
, fetchurl
, kaem
, stage0-posix
, tinycc
, gnumake
, gnupatch
Expand Down Expand Up @@ -70,7 +70,7 @@ let
})
];
in
kaem.runCommand "${pname}-${version}" {
stage0-posix.kaem.runCommand "${pname}-${version}" {
inherit pname version;

nativeBuildInputs = [
Expand Down
9 changes: 3 additions & 6 deletions pkgs/os-specific/linux/minimal-bootstrap/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
, hostPlatform
, fetchurl
, checkMeta
, stage0-posix
}:

lib.makeScope
# Prevent using top-level attrs to protect against introducing dependency on
# non-bootstrap packages by mistake. Any top-level inputs must be explicitly
# declared here.
(extra: lib.callPackageWith ({ inherit lib config buildPlatform hostPlatform fetchurl checkMeta; } // extra))
(extra: lib.callPackageWith ({ inherit lib config buildPlatform hostPlatform fetchurl checkMeta stage0-posix; } // extra))
(self: with self; {

bash_2_05 = callPackage ./bash/2.nix { tinycc = tinycc-mes; };
Expand Down Expand Up @@ -177,10 +178,6 @@ lib.makeScope
gnumake = gnumake-musl;
};

stage0-posix = callPackage ./stage0-posix { };

inherit (self.stage0-posix) kaem m2libc mescc-tools mescc-tools-extra;

tinycc-bootstrappable = lib.recurseIntoAttrs (callPackage ./tinycc/bootstrappable.nix { });
tinycc-mes = lib.recurseIntoAttrs (callPackage ./tinycc/mes.nix { });
tinycc-musl = lib.recurseIntoAttrs (callPackage ./tinycc/musl.nix {
Expand All @@ -197,7 +194,7 @@ lib.makeScope

inherit (callPackage ./utils.nix { }) derivationWithMeta writeTextFile writeText;

test = kaem.runCommand "minimal-bootstrap-test" {} ''
test = stage0-posix.kaem.runCommand "minimal-bootstrap-test" {} ''
echo ${bash.tests.get-version}
echo ${bash_2_05.tests.get-version}
echo ${binutils.tests.get-version}
Expand Down
4 changes: 2 additions & 2 deletions pkgs/os-specific/linux/minimal-bootstrap/gnumake/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ lib
, fetchurl
, kaem
, stage0-posix
, tinycc
, gnupatch
}:
Expand Down Expand Up @@ -145,7 +145,7 @@ let

objects = map (x: lib.replaceStrings [".c"] [".o"] (builtins.baseNameOf x)) sources;
in
kaem.runCommand "${pname}-${version}" {
stage0-posix.kaem.runCommand "${pname}-${version}" {
inherit pname version;

nativeBuildInputs = [ tinycc.compiler gnupatch ];
Expand Down
4 changes: 2 additions & 2 deletions pkgs/os-specific/linux/minimal-bootstrap/gnupatch/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ lib
, fetchurl
, kaem
, stage0-posix
, tinycc
}:
let
Expand Down Expand Up @@ -67,7 +67,7 @@ let

objects = map (x: lib.replaceStrings [".c"] [".o"] (builtins.baseNameOf x)) sources;
in
kaem.runCommand "${pname}-${version}" {
stage0-posix.kaem.runCommand "${pname}-${version}" {
inherit pname version;

nativeBuildInputs = [ tinycc.compiler ];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ lib
, fetchurl
, kaem
, stage0-posix
, tinycc
, gnumake
, gnupatch
Expand Down Expand Up @@ -32,7 +32,7 @@ let
})
];
in
kaem.runCommand "${pname}-${version}" {
stage0-posix.kaem.runCommand "${pname}-${version}" {
inherit pname version;

nativeBuildInputs = [
Expand Down
4 changes: 2 additions & 2 deletions pkgs/os-specific/linux/minimal-bootstrap/ln-boot/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ lib
, kaem
, stage0-posix
, mes
}:
let
Expand All @@ -8,7 +8,7 @@ let

src = ./ln.c;
in
kaem.runCommand "${pname}-${version}" {
stage0-posix.kaem.runCommand "${pname}-${version}" {
inherit pname version;

meta = with lib; {
Expand Down
23 changes: 11 additions & 12 deletions pkgs/os-specific/linux/minimal-bootstrap/mes/default.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{ lib
, fetchurl
, callPackage
, kaem
, mescc-tools
, stage0-posix
}:

# Maintenance note:
Expand Down Expand Up @@ -40,7 +39,7 @@ let
platforms = [ "i686-linux" ];
};

srcPost = kaem.runCommand "${pname}-src-${version}" {
srcPost = stage0-posix.kaem.runCommand "${pname}-src-${version}" {
outputs = [ "out" "bin" ];
inherit meta;
} ''
Expand Down Expand Up @@ -75,9 +74,9 @@ let
replace --file ''${guile_mes} --output ''${guile_mes} --match-on "(getenv \"GUILE_LOAD_PATH\")" --replace-with ''${__GUILE_LOAD_PATH}
module_mescc_scm=module/mescc/mescc.scm
replace --file ''${module_mescc_scm} --output ''${module_mescc_scm} --match-on "(getenv \"M1\")" --replace-with "\"${mescc-tools}/bin/M1\""
replace --file ''${module_mescc_scm} --output ''${module_mescc_scm} --match-on "(getenv \"HEX2\")" --replace-with "\"${mescc-tools}/bin/hex2\""
replace --file ''${module_mescc_scm} --output ''${module_mescc_scm} --match-on "(getenv \"BLOOD_ELF\")" --replace-with "\"${mescc-tools}/bin/blood-elf\""
replace --file ''${module_mescc_scm} --output ''${module_mescc_scm} --match-on "(getenv \"M1\")" --replace-with "\"${stage0-posix.mescc-tools}/bin/M1\""
replace --file ''${module_mescc_scm} --output ''${module_mescc_scm} --match-on "(getenv \"HEX2\")" --replace-with "\"${stage0-posix.mescc-tools}/bin/hex2\""
replace --file ''${module_mescc_scm} --output ''${module_mescc_scm} --match-on "(getenv \"BLOOD_ELF\")" --replace-with "\"${stage0-posix.mescc-tools}/bin/blood-elf\""
replace --file ''${module_mescc_scm} --output ''${module_mescc_scm} --match-on "(getenv \"srcdest\")" --replace-with "\"''${MES_PREFIX}\""
mes_c=src/mes.c
Expand Down Expand Up @@ -128,7 +127,7 @@ let
[ "" ]
(builtins.baseNameOf source);

compile = source: kaem.runCommand (stripExt source) {} ''
compile = source: stage0-posix.kaem.runCommand (stripExt source) {} ''
mkdir ''${out}
cd ''${out}
${CC} -c ${srcPrefix}/${source}
Expand All @@ -145,7 +144,7 @@ let

mkLib = libname: sources: let
os = map compile sources;
in kaem.runCommand "${pname}-${libname}-${version}" {
in stage0-posix.kaem.runCommand "${pname}-${libname}-${version}" {
inherit meta;
} ''
LIBDIR=''${out}/lib
Expand All @@ -162,10 +161,10 @@ let
libc_tcc = mkLib "libc+tcc" libc_tcc_SOURCES;

# Recompile Mes and Mes C library using mes-m2 bootstrapped Mes
libs = kaem.runCommand "${pname}-m2-libs-${version}" {
libs = stage0-posix.kaem.runCommand "${pname}-m2-libs-${version}" {
inherit pname version;

passthru.tests.get-version = result: kaem.runCommand "${pname}-get-version-${version}" {} ''
passthru.tests.get-version = result: stage0-posix.kaem.runCommand "${pname}-get-version-${version}" {} ''
${result}/bin/mes --version
mkdir ''${out}
'';
Expand Down Expand Up @@ -200,10 +199,10 @@ let
'';

# Build mes itself
compiler = kaem.runCommand "${pname}-${version}" {
compiler = stage0-posix.kaem.runCommand "${pname}-${version}" {
inherit pname version;

passthru.tests.get-version = result: kaem.runCommand "${pname}-get-version-${version}" {} ''
passthru.tests.get-version = result: stage0-posix.kaem.runCommand "${pname}-get-version-${version}" {} ''
${result}/bin/mes --version
mkdir ''${out}
'';
Expand Down
4 changes: 2 additions & 2 deletions pkgs/os-specific/linux/minimal-bootstrap/mes/libc.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{ lib
, kaem
, ln-boot
, mes
, mes-libc
, stage0-posix
}:
let
pname = "mes-libc";
Expand All @@ -20,7 +20,7 @@ let
firstLibc = lib.take 100 libc_gnu_SOURCES;
lastLibc = lib.drop 100 libc_gnu_SOURCES;
in
kaem.runCommand "${pname}-${version}" {
stage0-posix.kaem.runCommand "${pname}-${version}" {
inherit pname version;

nativeBuildInputs = [ ln-boot ];
Expand Down
4 changes: 2 additions & 2 deletions pkgs/os-specific/linux/minimal-bootstrap/mes/nyacc.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ lib
, fetchurl
, kaem
, stage0-posix
, nyacc
}:
let
Expand All @@ -15,7 +15,7 @@ let
sha256 = "065ksalfllbdrzl12dz9d9dcxrv97wqxblslngsc6kajvnvlyvpk";
};
in
kaem.runCommand "${pname}-${version}" {
stage0-posix.kaem.runCommand "${pname}-${version}" {
inherit pname version;

passthru.guilePath = "${nyacc}/share/${pname}-${version}/module";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{ lib
, callPackage
, fetchurl
, kaem
, stage0-posix
, mes
, mes-libc
}:
Expand All @@ -24,7 +24,7 @@ let
url = "https://gitlab.com/janneke/tinycc/-/archive/${rev}/tinycc-${rev}.tar.gz";
sha256 = "1a0cw9a62qc76qqn5sjmp3xrbbvsz2dxrw21lrnx9q0s74mwaxbq";
};
src = (kaem.runCommand "tinycc-bootstrappable-${version}-source" {} ''
src = (stage0-posix.kaem.runCommand "tinycc-bootstrappable-${version}-source" {} ''
ungz --file ${tarball} --output tinycc.tar
mkdir -p ''${out}
cd ''${out}
Expand All @@ -47,8 +47,8 @@ let
pname = "tinycc-boot-mes";

tinycc-boot-mes = rec {
compiler = kaem.runCommand "${pname}-${version}" {
passthru.tests.get-version = result: kaem.runCommand "${pname}-get-version-${version}" {} ''
compiler = stage0-posix.kaem.runCommand "${pname}-${version}" {
passthru.tests.get-version = result: stage0-posix.kaem.runCommand "${pname}-get-version-${version}" {} ''
${result}/bin/tcc -version
mkdir ''${out}
'';
Expand Down
14 changes: 7 additions & 7 deletions pkgs/os-specific/linux/minimal-bootstrap/tinycc/common.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ lib
, kaem
, stage0-posix
, mes-libc
}:

Expand All @@ -15,14 +15,14 @@ rec {
}:
let

crt = kaem.runCommand "crt" {} ''
crt = stage0-posix.kaem.runCommand "crt" {} ''
mkdir -p ''${out}/lib
${tcc}/bin/tcc ${mes-libc.CFLAGS} -c -o ''${out}/lib/crt1.o ${mes-libc}/lib/crt1.c
${tcc}/bin/tcc ${mes-libc.CFLAGS} -c -o ''${out}/lib/crtn.o ${mes-libc}/lib/crtn.c
${tcc}/bin/tcc ${mes-libc.CFLAGS} -c -o ''${out}/lib/crti.o ${mes-libc}/lib/crti.c
'';

library = lib: options: source: kaem.runCommand "${lib}.a" {} ''
library = lib: options: source: stage0-posix.kaem.runCommand "${lib}.a" {} ''
${tcc}/bin/tcc ${options} -c -o ${lib}.o ${source}
${tcc}/bin/tcc -ar cr ''${out} ${lib}.o
'';
Expand All @@ -31,7 +31,7 @@ rec {
libc = library "libc" mes-libc.CFLAGS "${mes-libc}/lib/libc.c";
libgetopt = library "libgetopt" mes-libc.CFLAGS "${mes-libc}/lib/libgetopt.c";
in
kaem.runCommand "${pname}-libs-${version}" {} ''
stage0-posix.kaem.runCommand "${pname}-libs-${version}" {} ''
mkdir -p ''${out}/lib
cp ${crt}/lib/crt1.o ''${out}/lib
cp ${crt}/lib/crtn.o ''${out}/lib
Expand All @@ -54,14 +54,14 @@ rec {
options = lib.strings.concatStringsSep " " buildOptions;
libtccOptions = lib.strings.concatStringsSep " "
(["-c" "-D" "TCC_TARGET_I386=1" ] ++ libtccBuildOptions);
compiler = kaem.runCommand "${pname}-${version}" {
compiler = stage0-posix.kaem.runCommand "${pname}-${version}" {
inherit pname version meta;
passthru.tests = rec {
get-version = result: kaem.runCommand "${pname}-get-version-${version}" {} ''
get-version = result: stage0-posix.kaem.runCommand "${pname}-get-version-${version}" {} ''
${result}/bin/tcc -version
mkdir ''${out}
'';
chain = result: kaem.runCommand "${pname}-chain-${version}" {} ''
chain = result: stage0-posix.kaem.runCommand "${pname}-chain-${version}" {} ''
echo ${prev.compiler.tests.chain or prev.compiler.tests.get-version};
${result}/bin/tcc -version
mkdir ''${out}
Expand Down
6 changes: 3 additions & 3 deletions pkgs/os-specific/linux/minimal-bootstrap/tinycc/mes.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{ lib
, fetchurl
, callPackage
, kaem
, stage0-posix
, tinycc-bootstrappable
}:
let
Expand All @@ -20,7 +20,7 @@ let
url = "https://repo.or.cz/tinycc.git/snapshot/${rev}.tar.gz";
sha256 = "11idrvbwfgj1d03crv994mpbbbyg63j1k64lw1gjy7mkiifw2xap";
};
src = (kaem.runCommand "tinycc-${version}-source" {} ''
src = (stage0-posix.kaem.runCommand "tinycc-${version}-source" {} ''
ungz --file ${tarball} --output tinycc.tar
mkdir -p ''${out}
cd ''${out}
Expand All @@ -40,7 +40,7 @@ let
platforms = [ "i686-linux" ];
};

tccdefs = kaem.runCommand "tccdefs-${version}" {} ''
tccdefs = stage0-posix.kaem.runCommand "tccdefs-${version}" {} ''
mkdir ''${out}
${tinycc-bootstrappable.compiler}/bin/tcc \
-B ${tinycc-bootstrappable.libs}/lib \
Expand Down
Loading

0 comments on commit 64c42e4

Please sign in to comment.