From e859a030a401bdcc252e078faed407a4d6932227 Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Fri, 6 Nov 2020 20:59:33 +0100 Subject: [PATCH] Simplify packages layout --- overlay/default.nix | 7 +- overlay/libc/default.nix | 8 +- packages/default.nix | 86 +------------- packages/genodelabs/default.nix | 110 ++++++++++++++---- .../{targets.nix => depot-targets.nix} | 18 +-- packages/genodelabs/make-targets.nix | 20 ++++ packages/stdcxx/default.nix | 6 +- tests/solo5/multi.nix | 6 +- tests/vmm_x86.nix | 2 +- tests/x86.nix | 11 +- 10 files changed, 144 insertions(+), 130 deletions(-) rename packages/genodelabs/{targets.nix => depot-targets.nix} (90%) create mode 100644 packages/genodelabs/make-targets.nix diff --git a/overlay/default.nix b/overlay/default.nix index 9f31dac..f4c618e 100644 --- a/overlay/default.nix +++ b/overlay/default.nix @@ -69,12 +69,9 @@ in { genodePackages = import ../packages { inherit flake; - nixpkgs = final; + pkgs = final; }; - genodeSources = - buildPackages.callPackage ../packages/genodelabs { inherit flake; }; - libconfig = overrideHostAttrs libconfig (attrs: { configureFlags = [ "--disable-examples" ]; }); @@ -101,7 +98,7 @@ in { llvmPackages_8 = callPackage ./llvm-8 ({ inherit (stdenvAdapters) overrideCC; - inherit (targetPackages.genodeSources) genodeBase; + inherit (final.genodePackages.genodeSources) genodeBase; buildLlvmTools = buildPackages.llvmPackages_8.tools; targetLlvmLibraries = targetPackages.llvmPackages_8.libraries; }); diff --git a/overlay/libc/default.nix b/overlay/libc/default.nix index dbefc27..dbfc9e6 100644 --- a/overlay/libc/default.nix +++ b/overlay/libc/default.nix @@ -1,8 +1,8 @@ -{ genodeSources, symlinkJoin }: - -symlinkJoin { +{ genodePackages, symlinkJoin }: +let inherit (genodePackages) genodeSources; +in symlinkJoin { name = "posix"; - paths = map genodeSources.depot [ "libc" "posix" ]; + paths = with genodePackages; [ libc posix ]; postBuild = '' local headerDir="''${!outputDev}/include" mkdir -p "$headerDir" diff --git a/packages/default.nix b/packages/default.nix index ec2c55f..6eb9625 100644 --- a/packages/default.nix +++ b/packages/default.nix @@ -1,9 +1,10 @@ -{ flake, nixpkgs }: +{ flake, pkgs }: let - inherit (nixpkgs) - buildPackages callPackage fetchFromGitHub fetchgit genodeSources stdenv; - inherit (genodeSources) buildUpstream; + upstream = import ./genodelabs { inherit flake pkgs; }; + inherit (upstream) genodeSources; + + inherit (pkgs) buildPackages callPackage fetchFromGitHub fetchgit stdenv; dhallPackages = flake.inputs.nixpkgs.legacyPackages.x86_64-linux.callPackage ./dhall { }; @@ -22,80 +23,7 @@ let ''; }); - depotPkgs = with builtins; - let - names = attrNames (import ./genodelabs/targets.nix { - buildPackages = null; - ports = null; - }); - f = name: { - inherit name; - value = genodeSources.depot name; - }; - in listToAttrs (map f names); - - basePatches = [ ./genodelabs/cxx-align.patch ]; - -in depotPkgs // { - inherit stdenv genodeSources; - - base-hw-pc = buildUpstream { - name = "base-hw-pc"; - outputs = [ "out" "coreObj" "bootstrapObj" ]; - KERNEL = "hw"; - BOARD = "pc"; - targets = [ "bootstrap" "core" "timer" "lib/ld" ]; - patches = basePatches; - postInstall = '' - mv $out/lib/ld-hw.lib.so $out/lib/ld.lib.so - mv $out/bin/hw_timer_drv $out/bin/timer_drv - install build/bin/core-hw-pc.o $coreObj - install build/bin/bootstrap-hw-pc.o $bootstrapObj - ''; - meta.platforms = [ "x86_64-genode" ]; - }; - - base-hw-virt_qemu = buildUpstream { - name = "base-hw-virt_qemu"; - outputs = [ "out" "coreObj" "bootstrapObj" ]; - KERNEL = "hw"; - BOARD = "virt_qemu"; - targets = [ "bootstrap" "core" "timer" "lib/ld" ]; - patches = basePatches; - postInstall = '' - mv $out/lib/ld-hw.lib.so $out/lib/ld.lib.so - mv $out/bin/hw_timer_drv $out/bin/timer_drv - install build/bin/core-hw-virt_qemu.o $coreObj - install build/bin/bootstrap-hw-virt_qemu.o $bootstrapObj - ''; - meta.platforms = [ "aarch64-genode" ]; - }; - - base-linux = buildUpstream { - name = "base-linux"; - KERNEL = "linux"; - BOARD = "linux"; - targets = [ "core" "timer" "lib/ld" ]; - patches = basePatches; - postInstall = '' - mv $out/lib/ld-linux.lib.so $out/lib/ld.lib.so - mv $out/bin/linux_timer_drv $out/bin/timer_drv - ''; - HOST_INC_DIR = buildPackages.glibc.dev + "/include"; - }; - - base-nova = buildUpstream { - name = "base-nova"; - outputs = [ "out" "coreObj" ]; - KERNEL = "nova"; - targets = [ "core" "timer" "lib/ld" ]; - patches = basePatches; - postInstall = '' - mv $out/lib/ld-nova.lib.so $out/lib/ld.lib.so - mv $out/bin/nova_timer_drv $out/bin/timer_drv - install build/bin/core-nova.o $coreObj - ''; - }; +in upstream // { bender = buildPackages.callPackage ./bender { }; @@ -103,8 +31,6 @@ in depotPkgs // { dhallGenode = dhallPackages.genode; - init = genodeSources.depot "init"; - nic_bus = callPackage ./nic_bus { }; NOVA = callPackage ./NOVA { }; diff --git a/packages/genodelabs/default.nix b/packages/genodelabs/default.nix index 873e889..06f33eb 100644 --- a/packages/genodelabs/default.nix +++ b/packages/genodelabs/default.nix @@ -1,7 +1,9 @@ -{ flake, buildPackages, targetPackages }: +{ flake, pkgs }: let - platform = targetPackages.targetPlatform; + inherit (pkgs) lib buildPackages targetPackages; + + platform = pkgs.targetPlatform; arch = with platform; if isx86_64 then @@ -11,8 +13,6 @@ let else throw "unknown Genode arch for platform ${platform.system}"; - inherit (buildPackages) callPackage fetchurl lib; - upstreamSources = flake.inputs.genode; genodeSources = @@ -61,7 +61,7 @@ let let havePatches = patches != [ ]; version = portVersions.${name}; - in with buildPackages; + in with buildPackages.buildPackages; stdenvNoCC.mkDerivation (args // { name = name + "-port-" + version; inherit version patches; @@ -121,10 +121,9 @@ let # The "ports" mechanism is hardly deterministic, so prepare with # a pinned nixpkgs revision for a pinned platform. - toolchain = callPackage ./toolchain.nix { }; + toolchain = buildPackages.buildPackages.callPackage ./toolchain.nix { }; - stdenv' = - targetPackages.stdenvAdapters.overrideCC targetPackages.stdenv toolchain; + stdenv' = pkgs.stdenvAdapters.overrideCC pkgs.stdenv toolchain; buildUpstream = # Build from the Genode sources @@ -179,14 +178,14 @@ let buildDepot = # Build a Depot target from the Genode sources { name, apiOnly ? false, portInputs ? [ ], nativeBuildInputs ? [ ] - , meta ? { }, ... }@extraAttrs: + , buildInputs ? [ ], meta ? { }, ... }@extraAttrs: stdenv'.mkDerivation (extraAttrs // { pname = name; inherit (genodeSources) version; enableParallelBuilding = true; - nativeBuildInputs = with buildPackages; + nativeBuildInputs = with buildPackages.buildPackages; [ binutils bison flex stdenv.cc tcl which ] ++ nativeBuildInputs; src = genodeSources; @@ -234,7 +233,21 @@ let meta = { platforms = lib.platforms.genode; } // meta; }); - buildOverrides = callPackage ./targets.nix { inherit ports; }; + makePackages = let + overrides = import ./make-targets.nix { + inherit (pkgs) buildPackages genodePackages; + inherit ports; + }; + in lib.attrsets.mapAttrs + (name: value: (buildUpstream ({ inherit name; } // value))) overrides; + + depotPackages = lib.attrsets.mapAttrs + (name: value: (buildDepot ({ inherit name; } // value))) + (import ./depot-targets.nix { + inherit (pkgs) genodePackages; + inherit ports; + buildPackages = buildPackages.buildPackages; + }); specs = with platform; [ ] @@ -283,20 +296,69 @@ let ''; }; -in genodeSources // { - inherit buildUpstream buildDepot ports specs toolchain genodeBase; + basePatches = [ ./cxx-align.patch ]; - make = target: - let - name = builtins.replaceStrings [ "/" ] [ "-" ] target; - attrs = buildOverrides.${name} or { }; - in buildUpstream ({ - inherit name; - targets = [ target ]; - } // attrs); +in makePackages // depotPackages // { - depot = name: - let attrs = buildOverrides.${name} or { }; - in buildDepot ({ inherit name; } // attrs); + genodeSources = genodeSources // { + inherit buildUpstream buildDepot genodeBase ports specs toolchain; + }; + base-hw-pc = buildUpstream { + name = "base-hw-pc"; + outputs = [ "out" "coreObj" "bootstrapObj" ]; + KERNEL = "hw"; + BOARD = "pc"; + targets = [ "bootstrap" "core" "timer" "lib/ld" ]; + patches = basePatches; + postInstall = '' + mv $out/lib/ld-hw.lib.so $out/lib/ld.lib.so + mv $out/bin/hw_timer_drv $out/bin/timer_drv + install build/bin/core-hw-pc.o $coreObj + install build/bin/bootstrap-hw-pc.o $bootstrapObj + ''; + meta.platforms = [ "x86_64-genode" ]; + }; + + base-hw-virt_qemu = buildUpstream { + name = "base-hw-virt_qemu"; + outputs = [ "out" "coreObj" "bootstrapObj" ]; + KERNEL = "hw"; + BOARD = "virt_qemu"; + targets = [ "bootstrap" "core" "timer" "lib/ld" ]; + patches = basePatches; + postInstall = '' + mv $out/lib/ld-hw.lib.so $out/lib/ld.lib.so + mv $out/bin/hw_timer_drv $out/bin/timer_drv + install build/bin/core-hw-virt_qemu.o $coreObj + install build/bin/bootstrap-hw-virt_qemu.o $bootstrapObj + ''; + meta.platforms = [ "aarch64-genode" ]; + }; + + base-linux = buildUpstream { + name = "base-linux"; + KERNEL = "linux"; + BOARD = "linux"; + targets = [ "core" "timer" "lib/ld" ]; + patches = basePatches; + postInstall = '' + mv $out/lib/ld-linux.lib.so $out/lib/ld.lib.so + mv $out/bin/linux_timer_drv $out/bin/timer_drv + ''; + HOST_INC_DIR = buildPackages.glibc.dev + "/include"; + }; + + base-nova = buildUpstream { + name = "base-nova"; + outputs = [ "out" "coreObj" ]; + KERNEL = "nova"; + targets = [ "core" "timer" "lib/ld" ]; + patches = basePatches; + postInstall = '' + mv $out/lib/ld-nova.lib.so $out/lib/ld.lib.so + mv $out/bin/nova_timer_drv $out/bin/timer_drv + install build/bin/core-nova.o $coreObj + ''; + }; } diff --git a/packages/genodelabs/targets.nix b/packages/genodelabs/depot-targets.nix similarity index 90% rename from packages/genodelabs/targets.nix rename to packages/genodelabs/depot-targets.nix index a0f3d4e..74c704e 100644 --- a/packages/genodelabs/targets.nix +++ b/packages/genodelabs/depot-targets.nix @@ -3,9 +3,11 @@ # However, any package listed here with empty overrides ({ }) will be added to # the package attributes of this flake. -{ buildPackages, ports }: +{ buildPackages, genodePackages, ports }: with ports; let + self = genodePackages; + includeDir = pkg: buildPackages.lib.getDev pkg + "/include"; hostLibcInc = includeDir buildPackages.glibc; @@ -41,6 +43,7 @@ in { ipxe_nic_drv.portInputs = [ dde_ipxe ]; libc = { + buildInputs = [ self.vfs ]; portInputs = [ libc ]; patches = [ ./libc.patch ]; }; @@ -59,7 +62,10 @@ in { platform_drv = { }; - posix.portInputs = [ libc ]; + posix = { + buildInputs = [ self.libc ]; + portInputs = [ ports.libc ]; + }; report_rom = { }; @@ -82,12 +88,8 @@ in { "test-log".patches = [ ./test-log.patch ]; - "test-pci".patches = [ ./test-pci.patch ]; - "test-signal".patches = [ ./test-signal.patch ]; - "test-vmm_x86".patches = [ ./test-vmm_x86.patch ]; - usb_drv.portInputs = [ dde_linux ]; vbox5 = vbox5'; @@ -97,8 +99,8 @@ in { vesa_drv.portInputs = [ libc x86emu ]; vfs.outputs = [ "out" "lib" ]; - vfs_audit = {}; - vfs_block = { }; + vfs_audit = { }; + vfs_block.buildInputs = [ genodePackages.vfs ]; vfs_import.patches = [ ./vfs_import.patch ]; vfs_jitterentropy.portInputs = [ jitterentropy libc ]; vfs_lwip.portInputs = [ lwip ]; diff --git a/packages/genodelabs/make-targets.nix b/packages/genodelabs/make-targets.nix new file mode 100644 index 0000000..fc3d8a2 --- /dev/null +++ b/packages/genodelabs/make-targets.nix @@ -0,0 +1,20 @@ +# This file contains overrides necessary to build some Make targets. + +{ buildPackages, genodePackages, ports }: + +{ + ping.targets = [ "app/ping" ]; + + test-pci = { + targets = [ "test/pci" ]; + patches = [ ./test-pci.patch ]; + }; + + test-rtc.targets = [ "test/rtc" ]; + + test-vmm_x86 = { + targets = [ "test/vmm_x86" ]; + patches = [ ./test-vmm_x86.patch ]; + }; + +} diff --git a/packages/stdcxx/default.nix b/packages/stdcxx/default.nix index e84dd40..e94ab7e 100644 --- a/packages/stdcxx/default.nix +++ b/packages/stdcxx/default.nix @@ -1,6 +1,8 @@ -{ genodeSources }: +{ genodePackages }: -let port = genodeSources.ports.stdcxx; +let + inherit (genodePackages) genodeSources; + port = genodeSources.ports.stdcxx; in genodeSources.buildUpstream { name = "stdcxx"; outputs = [ "out" "dev" ]; diff --git a/tests/solo5/multi.nix b/tests/solo5/multi.nix index f4c4220..df1dcf5 100644 --- a/tests/solo5/multi.nix +++ b/tests/solo5/multi.nix @@ -6,14 +6,14 @@ if pkgs.stdenv.hostPlatform.isAarch64 then "True" else "False" } }"; inputs = with pkgs.genodePackages; [ - solo5 - solo5.tests nic_bridge nic_loopback + ping sequence + solo5 + solo5.tests vfs_block vfs_import - (genodeSources.make "app/ping") ]; }; }; diff --git a/tests/vmm_x86.nix b/tests/vmm_x86.nix index 6706cf7..80ca5d5 100644 --- a/tests/vmm_x86.nix +++ b/tests/vmm_x86.nix @@ -6,7 +6,7 @@ machine = { pkgs, ... }: { genode.init.children.vmm = { configFile = ./vmm_x86.dhall; - inputs = map pkgs.genodeSources.make [ "test/vmm_x86" ]; + inputs = with pkgs.genodePackages; [ test-vmm_x86 ]; }; }; } diff --git a/tests/x86.nix b/tests/x86.nix index b51a431..1ac0fbc 100644 --- a/tests/x86.nix +++ b/tests/x86.nix @@ -4,9 +4,14 @@ machine = { pkgs, ... }: { genode.init.subinits.test = { configFile = ./x86.dhall; - inputs = with pkgs.genodePackages; - [ acpi_drv platform_drv report_rom test-signal ] - ++ (map genodeSources.make [ "test/pci" "test/rtc" ]); + inputs = with pkgs.genodePackages; [ + acpi_drv + platform_drv + report_rom + test-signal + test-pci + test-rtc + ]; }; }; testScript = ''