From 77922c875b284c1d1ab5fa35d0604e036b059aa3 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Sat, 15 Oct 2022 18:55:33 +0100 Subject: [PATCH] add per-device overlay presently this is used to reference the appropriate kernel and (if needed) openwrt source trees, but I would not be surprised if we find other uses --- default.nix | 8 +++-- .../{gl-ar750.nix => gl-ar750/default.nix} | 29 ++++++++++++++++++- devices/{qemu.nix => qemu/default.nix} | 15 ++++++++++ kernel/default.nix | 21 ++------------ tests/kernel/run.sh | 2 +- tests/module/run.sh | 2 +- tests/pppoe/run.sh | 2 +- tests/smoke/run.sh | 2 +- tests/wlan/run.sh | 2 +- 9 files changed, 56 insertions(+), 27 deletions(-) rename devices/{gl-ar750.nix => gl-ar750/default.nix} (75%) rename devices/{qemu.nix => qemu/default.nix} (90%) diff --git a/default.nix b/default.nix index d30fe5c..6268bd5 100644 --- a/default.nix +++ b/default.nix @@ -5,7 +5,7 @@ let overlay = import ./overlay.nix; - nixpkgs = import ( device.system // {overlays = [overlay]; }); + nixpkgs = import (device.system // {overlays = [overlay device.overlay]; }); inherit (nixpkgs.pkgs) callPackage writeText liminix; inherit (nixpkgs.lib) concatStringsSep; config = (import ./merge-modules.nix) [ @@ -56,16 +56,18 @@ let bootm 0x${toHexString uimageStart} ''; - directory = nixpkgs.pkgs.runCommand "liminix" {} '' + directory = nixpkgs.pkgs.runCommand "liminix" {} ('' mkdir $out cd $out ln -s ${squashfs} squashfs ln -s ${kernel.vmlinux} vmlinux ln -s ${manifest} manifest + '' + + (if device ? boot then '' ln -s ${uimage} uimage ${if phram then "ln -s ${boot-scr} boot.scr" else ""} ln -s ${boot-scr} flash.scr - ''; + '' else "")); # this exists so that you can run "nix-store -q --tree" on it and find # out what's in the image, which is nice if it's unexpectedly huge manifest = writeText "manifest.json" (builtins.toJSON config.filesystem.contents); diff --git a/devices/gl-ar750.nix b/devices/gl-ar750/default.nix similarity index 75% rename from devices/gl-ar750.nix rename to devices/gl-ar750/default.nix index 644d3b7..5ca4554 100644 --- a/devices/gl-ar750.nix +++ b/devices/gl-ar750/default.nix @@ -20,6 +20,34 @@ }; }; }; + + # We need to be able to import default.nix before we import nixpkgs + # because it has the system config to tell nixpkgs what arch to build for. + # But we also need some way to do things like fetchFromGitHub in the + # per-device config and we can only do that once we have a reference to + # pkgs + + overlay = final: prev: + let inherit (final) fetchFromGitHub; + in { + sources = { + openwrt = fetchFromGitHub { + name = "openwrt-source"; + repo = "openwrt"; + owner = "openwrt"; + rev = "a5265497a4f6da158e95d6a450cb2cb6dc085cab"; + hash = "sha256-YYi4gkpLjbOK7bM2MGQjAyEBuXJ9JNXoz/JEmYf8xE8="; + }; + kernel = fetchFromGitHub { + name = "kernel-source"; + owner = "torvalds"; + repo = "linux"; + rev = "3d7cb6b04c3f3115719235cc6866b10326de34cd"; # v5.19 + hash = "sha256-OVsIRScAnrPleW1vbczRAj5L/SGGht2+GnvZJClMUu4="; + }; + }; + }; + kernel = rec { checkedConfig = { "MIPS_ELF_APPENDED_DTB" = "y"; @@ -42,7 +70,6 @@ CONSOLE_LOGLEVEL_DEFAULT = "8"; CONSOLE_LOGLEVEL_QUIET = "4"; - # "empty" initramfs source should create an initial # filesystem that has a /dev/console node and not much # else. Note that pid 1 is started *before* the root diff --git a/devices/qemu.nix b/devices/qemu/default.nix similarity index 90% rename from devices/qemu.nix rename to devices/qemu/default.nix index 930e598..b6b26ea 100644 --- a/devices/qemu.nix +++ b/devices/qemu/default.nix @@ -12,6 +12,21 @@ }; }; }; + + overlay = final: prev: + let inherit (final) fetchFromGitHub; + in { + sources = { + kernel = fetchFromGitHub { + name = "kernel-source"; + owner = "torvalds"; + repo = "linux"; + rev = "3d7cb6b04c3f3115719235cc6866b10326de34cd"; # v5.19 + hash = "sha256-OVsIRScAnrPleW1vbczRAj5L/SGGht2+GnvZJClMUu4="; + }; + }; + }; + kernel = { config = { SYSVIPC= "y"; diff --git a/kernel/default.nix b/kernel/default.nix index fc7f2a9..fb88fe5 100644 --- a/kernel/default.nix +++ b/kernel/default.nix @@ -6,15 +6,9 @@ , config , checkedConfig +, sources }: let - source = fetchFromGitHub { - owner = "torvalds"; - repo = "linux"; - rev = "3d7cb6b04c3f3115719235cc6866b10326de34cd"; # v5.19 - hash = "sha256-OVsIRScAnrPleW1vbczRAj5L/SGGht2+GnvZJClMUu4="; - }; - # The kernel is huge and takes a long time just to # download and unpack. This derivation creates # a source tree in a suitable shape to build from - @@ -24,7 +18,7 @@ let tree = stdenvNoCC.mkDerivation { name = "spindled-kernel-tree"; - src = source; + src = sources.kernel; phases = [ "unpackPhase" "patchPhase" "patchScripts" "installPhase" ]; patches = [ ./random.patch ]; patchScripts = '' @@ -36,15 +30,6 @@ let ''; }; - openwrtSource = fetchFromGitHub { - name = "openwrt-source-tree"; - repo = "openwrt"; - owner = "openwrt"; - rev = "a5265497a4f6da158e95d6a450cb2cb6dc085cab"; - hash = "sha256-YYi4gkpLjbOK7bM2MGQjAyEBuXJ9JNXoz/JEmYf8xE8="; - }; - - in rec { vmlinux = callPackage ./vmlinux.nix { inherit tree config checkedConfig; @@ -53,7 +38,7 @@ in rec { uimage = callPackage ./uimage.nix { }; dtb = callPackage ./dtb.nix { - openwrt = openwrtSource; + openwrt = sources.openwrt; kernel = tree; }; } diff --git a/tests/kernel/run.sh b/tests/kernel/run.sh index 694a86c..0ffe338 100755 --- a/tests/kernel/run.sh +++ b/tests/kernel/run.sh @@ -1,5 +1,5 @@ set -e -NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix-build '' -I liminix-config=../smoke/configuration.nix --arg device "import " -A outputs.kernel.vmlinux -o vmlinux $* +NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix-build '' -I liminix-config=../smoke/configuration.nix --arg device "import " -A outputs.kernel.vmlinux -o vmlinux $* TESTS=$(cat <<"EOF" diff --git a/tests/module/run.sh b/tests/module/run.sh index 1197da8..37010d5 100755 --- a/tests/module/run.sh +++ b/tests/module/run.sh @@ -1,2 +1,2 @@ set -e -NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix-build --arg device "import " test.nix +NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix-build --arg device "import " test.nix diff --git a/tests/pppoe/run.sh b/tests/pppoe/run.sh index 48cb80d..e6294a5 100755 --- a/tests/pppoe/run.sh +++ b/tests/pppoe/run.sh @@ -14,7 +14,7 @@ fatal(){ } trap fatal ERR -NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix-build '' -I liminix-config=./configuration.nix --arg device "import " -A outputs.default $* +NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix-build '' -I liminix-config=./configuration.nix --arg device "import " -A outputs.default $* if ! ( echo "cont" | socat - unix-connect:../support/ppp-server/qemu-monitor); then echo "need pppoe server running" diff --git a/tests/smoke/run.sh b/tests/smoke/run.sh index e8a6811..59969f4 100755 --- a/tests/smoke/run.sh +++ b/tests/smoke/run.sh @@ -1,5 +1,5 @@ set -e -NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix-build '' -I liminix-config=./configuration.nix --arg device "import " -A outputs.squashfs -o smoke.img $* +NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix-build '' -I liminix-config=./configuration.nix --arg device "import " -A outputs.squashfs -o smoke.img $* TESTS=$(cat <<"EOF" test -n "${TMPDIR}" diff --git a/tests/wlan/run.sh b/tests/wlan/run.sh index 0c538e8..dd9568e 100755 --- a/tests/wlan/run.sh +++ b/tests/wlan/run.sh @@ -14,7 +14,7 @@ fatal(){ } trap fatal ERR -NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix-build '' -I liminix-config=./configuration.nix --arg device "import " -A outputs.default $* +NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix-build '' -I liminix-config=./configuration.nix --arg device "import " -A outputs.default $*