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