nur-packages

My NUR packages
git clone git://git.sikmir.ru/nur-packages
Log | Files | Refs | README | LICENSE

default.nix (3068B)


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