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