nur-packages

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

default.nix (3287B)


      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.5";
     33 
     34   src = fetchFromGitHub {
     35     owner = "embox";
     36     repo = "embox";
     37     tag = "v${finalAttrs.version}";
     38     hash = "sha256-HV8Azl1HXHtmL3U38Ey0q3ghE6aDHrQ+G7j7/kQrlUg=";
     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     ln -s ${third-party.openlibm} ./download/openlibm-0.8.3.tar.gz
     71   '';
     72 
     73   installPhase =
     74     let
     75       platform_args =
     76         {
     77           aarch64 = "-M virt -cpu cortex-a53 -m 1024";
     78           arm = "-M integratorcp -m 256";
     79           ppc = "-M virtex-ml507 -m 64";
     80           riscv64 = "-M virt -m 512";
     81           x86 = "-enable-kvm -device pci-ohci,id=ohci -m 256";
     82         }
     83         .${arch};
     84       net_args = {
     85         aarch64 = "model=e1000";
     86         arm = "model=smc91c111";
     87         x86 = "model=virtio";
     88       };
     89       withNetwork = (lib.hasAttr arch net_args) && stdenv.isLinux;
     90     in
     91     ''
     92       mkdir -p $out/bin
     93 
     94       makeWrapper ${qemu}/bin/qemu-system-${if arch == "x86" then "i386" else arch} $out/bin/embox \
     95         --add-flags "${platform_args}" \
     96         --add-flags "-kernel $out/share/embox/images/embox.img" \
     97         --add-flags "${lib.optionalString withNetwork "-net nic,netdev=n0,${net_args.${arch}},macaddr=AA:BB:CC:DD:EE:02"}" \
     98         --add-flags "${lib.optionalString withNetwork "-netdev tap,script=$out/share/embox/scripts/start_script,downscript=$out/share/embox/scripts/stop_script,id=n0"}" \
     99         --add-flags "-nographic"
    100 
    101       install -Dm644 build/base/bin/embox $out/share/embox/images/embox.img
    102       install -Dm644 conf/*.conf* -t $out/share/embox/conf
    103     ''
    104     + lib.optionalString withNetwork ''
    105       install -Dm755 scripts/qemu/{start,stop}_script -t $out/share/embox/scripts
    106     '';
    107 
    108   meta = {
    109     description = "Modular and configurable OS for embedded applications";
    110     homepage = "http://embox.github.io/";
    111     license = lib.licenses.bsd2;
    112     maintainers = [ lib.maintainers.sikmir ];
    113     platforms = lib.platforms.unix;
    114     skip.ci = true;
    115     mainProgram = "embox";
    116   };
    117 })