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
module-based-network
Daniel Barlow 2022-10-15 18:55:33 +01:00
parent fa31d00d6a
commit 77922c875b
9 changed files with 56 additions and 27 deletions

View File

@ -5,7 +5,7 @@
let
overlay = import ./overlay.nix;
nixpkgs = import <nixpkgs> ( device.system // {overlays = [overlay]; });
nixpkgs = import <nixpkgs> (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);

View File

@ -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

View File

@ -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";

View File

@ -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;
};
}

View File

@ -1,5 +1,5 @@
set -e
NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix-build '<liminix>' -I liminix-config=../smoke/configuration.nix --arg device "import <liminix/devices/$DEVICE.nix>" -A outputs.kernel.vmlinux -o vmlinux $*
NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix-build '<liminix>' -I liminix-config=../smoke/configuration.nix --arg device "import <liminix/devices/$DEVICE>" -A outputs.kernel.vmlinux -o vmlinux $*
TESTS=$(cat <<"EOF"

View File

@ -1,2 +1,2 @@
set -e
NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix-build --arg device "import <liminix/devices/qemu.nix>" test.nix
NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix-build --arg device "import <liminix/devices/qemu>" test.nix

View File

@ -14,7 +14,7 @@ fatal(){
}
trap fatal ERR
NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix-build '<liminix>' -I liminix-config=./configuration.nix --arg device "import <liminix/devices/qemu.nix>" -A outputs.default $*
NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix-build '<liminix>' -I liminix-config=./configuration.nix --arg device "import <liminix/devices/qemu>" -A outputs.default $*
if ! ( echo "cont" | socat - unix-connect:../support/ppp-server/qemu-monitor); then
echo "need pppoe server running"

View File

@ -1,5 +1,5 @@
set -e
NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix-build '<liminix>' -I liminix-config=./configuration.nix --arg device "import <liminix/devices/$DEVICE.nix>" -A outputs.squashfs -o smoke.img $*
NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix-build '<liminix>' -I liminix-config=./configuration.nix --arg device "import <liminix/devices/$DEVICE>" -A outputs.squashfs -o smoke.img $*
TESTS=$(cat <<"EOF"
test -n "${TMPDIR}"

View File

@ -14,7 +14,7 @@ fatal(){
}
trap fatal ERR
NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix-build '<liminix>' -I liminix-config=./configuration.nix --arg device "import <liminix/devices/qemu.nix>" -A outputs.default $*
NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix-build '<liminix>' -I liminix-config=./configuration.nix --arg device "import <liminix/devices/qemu>" -A outputs.default $*