diff options
| author | Alejandro Soto <alejandro@34project.org> | 2022-12-16 15:07:06 -0600 |
|---|---|---|
| committer | Alejandro Soto <alejandro@34project.org> | 2022-12-16 22:20:26 -0600 |
| commit | 3a675869ed2d73c9b51941f5b1f753e3d345c5e8 (patch) | |
| tree | 0f3cebc37082f01c43760f6cb735818ef646230a /nix/flake.nix | |
| parent | 2c7ad7bd098d885f3df623fe099adf500fbafad7 (diff) | |
Add initramfs PoC with busybox init
Diffstat (limited to '')
| -rw-r--r-- | nix/flake.nix | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/nix/flake.nix b/nix/flake.nix index dbc4e2d..cdffdcc 100644 --- a/nix/flake.nix +++ b/nix/flake.nix @@ -2,7 +2,96 @@ outputs = { self, nixpkgs }: let system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; config.allowUnfree = true; }; + + crossSystem = "arm-linux"; + cross = import nixpkgs { + inherit system; + + config.allowUnsupportedSystem = true; + + crossSystem = { + config = "arm-unknown-linux-gnueabi"; + + gcc = { + # > Switch "--with-arch" may not be used with switch "--with-cpu" + # > make[1]: *** [Makefile:4315: configure-gcc] Error 1 + #arch = "armv4"; + + # Ver SA110 en arch/arm/mm/Kconfig, es parecido + cpu = "arm810"; + }; + + linux-kernel = { + name = "taller"; + target = "uImage"; + makeFlags = [ "LOADADDR=0x8000" ]; + autoModules = false; + baseConfig = "taller_defconfig"; + }; + }; + }; in { + # Tomado de pkgs/build-support/vm/default.nix + packages."${crossSystem}".proof-of-concept = cross.makeInitrd { + contents = [ + { + symlink = "/init"; + + object = with cross; let + initrdUtils = runCommand "initrd-utils" + { nativeBuildInputs = [ buildPackages.nukeReferences ]; + allowedReferences = [ "out" ]; # prevent accidents like glibc being included in the initrd + } + '' + mkdir -p $out/bin + mkdir -p $out/lib + + # Copy what we need from Glibc. + cp -p ${cross.glibc.out}/lib/ld-linux*.so.? $out/lib + cp -p ${cross.glibc.out}/lib/libc.so.* $out/lib + cp -p ${cross.glibc.out}/lib/libm.so.* $out/lib + cp -p ${cross.glibc.out}/lib/libresolv.so.* $out/lib + + # Copy BusyBox. + cp -pd ${cross.busybox}/bin/* $out/bin + + # Run patchelf to make the programs refer to the copied libraries. + for i in $out/bin/* $out/lib/*; do if ! test -L $i; then nuke-refs $i; fi; done + + for i in $out/bin/*; do + if [ -f "$i" -a ! -L "$i" ]; then + echo "patching $i..." + patchelf --set-interpreter $out/lib/ld-linux*.so.? --set-rpath $out/lib $i || true + fi + done + ''; + + + path = lib.makeSearchPath "bin" [ + #bashInteractive + #coreutils-full + #gnugrep + #neofetch + #util-linux + ]; + in writeScript "init" '' + #!${initrdUtils}/bin/ash + + export PATH=${initrdUtils}/bin + + mkdir -p /dev /etc /proc /sys + echo -n > /etc/fstab + + mount -t devtmpfs devtmpfs /dev + mount -t proc none /proc + mount -t sysfs none /sys + + exec ash + ''; + } + ]; + }; + devShells."${system}" = with pkgs; { default = mkShell { buildInputs = [ |
