default.nix (3404B)
1 { 2 lib, 3 stdenv, 4 fetchFromGitHub, 5 fetchurl, 6 makeWrapper, 7 pkgsCross, 8 bash, 9 cpio, 10 gcc-arm-embedded, 11 python3, 12 qemu, 13 unzip, 14 which, 15 arch ? "x86", 16 }: 17 18 assert lib.assertOneOf "arch" arch [ 19 "aarch64" 20 "arm" 21 "ppc" 22 "riscv64" 23 "x86" 24 ]; 25 26 let 27 third-party = lib.mapAttrs (name: spec: fetchurl spec) ( 28 builtins.fromJSON (builtins.readFile ./third-party.json) 29 ); 30 in 31 stdenv.mkDerivation (finalAttrs: { 32 pname = "embox-${arch}-qemu"; 33 version = "0.7.0"; 34 35 src = fetchFromGitHub { 36 owner = "embox"; 37 repo = "embox"; 38 tag = "v${finalAttrs.version}"; 39 hash = "sha256-S9ziXX0DGrrH3Lame2yfMYSYRcCp8jQ3l+yeqGlSJ0g="; 40 }; 41 42 patches = [ ./0001-fix-build.patch ]; 43 44 postPatch = '' 45 substituteInPlace mk/extbld/compiler_start.sh \ 46 --replace "/usr/bin/env bash" "${lib.getExe bash}" 47 substituteInPlace templates/aarch64/qemu/build.conf \ 48 --replace-fail "aarch64-elf" "aarch64-none-elf" 49 substituteInPlace templates/ppc/qemu/build.conf \ 50 --replace-fail "powerpc-elf" "powerpc-none-eabi" 51 substituteInPlace templates/riscv64/qemu/build.conf \ 52 --replace-fail "riscv64-unknown-elf" "riscv64-none-elf" 53 ''; 54 55 nativeBuildInputs = 56 [ 57 cpio 58 python3 59 unzip 60 which 61 makeWrapper 62 ] 63 ++ lib.optional (arch != "x86" && arch != "arm") pkgsCross."${arch}-embedded".stdenv.cc 64 ++ lib.optional (arch == "arm") gcc-arm-embedded; 65 66 configurePhase = "make confload-${arch}/qemu"; 67 68 preBuild = '' 69 patchShebangs ./mk 70 mkdir -p ./download 71 ln -s ${third-party.cjson} ./download/cjson-v1.7.16.tar.gz 72 ln -s ${third-party.acpica-unix} ./download/acpica-R06_28_23.tar.gz 73 ln -s ${third-party.openlibm} ./download/openlibm-0.8.3.tar.gz 74 ''; 75 76 installPhase = 77 let 78 platform_args = 79 { 80 aarch64 = "-M virt -cpu cortex-a53 -m 1024"; 81 arm = "-M integratorcp -m 256"; 82 ppc = "-M virtex-ml507 -m 64"; 83 riscv64 = "-M virt -m 512"; 84 x86 = "-enable-kvm -device pci-ohci,id=ohci -m 256"; 85 } 86 .${arch}; 87 net_args = { 88 aarch64 = "model=e1000"; 89 arm = "model=smc91c111"; 90 x86 = "model=virtio"; 91 }; 92 withNetwork = (lib.hasAttr arch net_args) && stdenv.isLinux; 93 in 94 '' 95 mkdir -p $out/bin 96 97 makeWrapper ${qemu}/bin/qemu-system-${if arch == "x86" then "i386" else arch} $out/bin/embox \ 98 --add-flags "${platform_args}" \ 99 --add-flags "-kernel $out/share/embox/images/embox.img" \ 100 --add-flags "${lib.optionalString withNetwork "-net nic,netdev=n0,${net_args.${arch}},macaddr=AA:BB:CC:DD:EE:02"}" \ 101 --add-flags "${lib.optionalString withNetwork "-netdev tap,script=$out/share/embox/scripts/start_script,downscript=$out/share/embox/scripts/stop_script,id=n0"}" \ 102 --add-flags "-nographic" 103 104 install -Dm644 build/base/bin/embox $out/share/embox/images/embox.img 105 install -Dm644 conf/*.conf* -t $out/share/embox/conf 106 '' 107 + lib.optionalString withNetwork '' 108 install -Dm755 scripts/qemu/{start,stop}_script -t $out/share/embox/scripts 109 ''; 110 111 meta = { 112 description = "Modular and configurable OS for embedded applications"; 113 homepage = "http://embox.github.io/"; 114 license = lib.licenses.bsd2; 115 maintainers = [ lib.maintainers.sikmir ]; 116 platforms = lib.platforms.unix; 117 skip.ci = true; 118 mainProgram = "embox"; 119 }; 120 })
