From efd878dc5ea187ccf35d661bb5a26c4b908225f4 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Sat, 18 Mar 2023 19:17:58 +0000 Subject: [PATCH] extract common code for patching kernel source fdorm openwrt --- devices/gl-ar750/default.nix | 24 ++++--------------- devices/gl-mt300a/default.nix | 24 ++++--------------- devices/gl-mt300n-v2/default.nix | 24 ++++--------------- pkgs/default.nix | 2 ++ pkgs/openwrt/default.nix | 41 ++++++++++++++++++++++++++++++++ 5 files changed, 55 insertions(+), 60 deletions(-) create mode 100644 pkgs/openwrt/default.nix diff --git a/devices/gl-ar750/default.nix b/devices/gl-ar750/default.nix index 686ab38..f7d2272 100644 --- a/devices/gl-ar750/default.nix +++ b/devices/gl-ar750/default.nix @@ -40,13 +40,7 @@ module = {pkgs, config, ... }: let - openwrt = pkgs.pkgsBuildBuild.fetchFromGitHub { - name = "openwrt-source"; - repo = "openwrt"; - owner = "openwrt"; - rev = "a5265497a4f6da158e95d6a450cb2cb6dc085cab"; - hash = "sha256-YYi4gkpLjbOK7bM2MGQjAyEBuXJ9JNXoz/JEmYf8xE8="; - }; + openwrt = pkgs.openwrt; firmwareBlobs = pkgs.pkgsBuildBuild.fetchFromGitHub { owner = "kvalo"; repo = "ath10k-firmware"; @@ -96,9 +90,9 @@ }; rootDevice = "1f05"; dts = { - src = "${openwrt}/target/linux/ath79/dts/qca9531_glinet_gl-ar750.dts"; + src = "${openwrt.src}/target/linux/ath79/dts/qca9531_glinet_gl-ar750.dts"; includes = [ - "${openwrt}/target/linux/ath79/dts" + "${openwrt.src}/target/linux/ath79/dts" ]; }; @@ -136,17 +130,7 @@ hash = "sha256-yhO2cXIeIgUxkSZf/4aAsF11uxyh+UUZu6D1h92vCD8="; }; extraPatchPhase = '' - cp -av ${openwrt}/target/linux/generic/files/* . - chmod -R u+w . - cp -av ${openwrt}/target/linux/ath79/files/* . - chmod -R u+w . - patches() { - for i in $* ; do patch --batch --forward -p1 < $i ;done - } - patches ${openwrt}/target/linux/generic/backport-5.15/*.patch - patches ${openwrt}/target/linux/generic/pending-5.15/*.patch - patches ${openwrt}/target/linux/generic/hack-5.15/*.patch - patches ${openwrt}/target/linux/ath79/patches-5.15/*.patch + ${openwrt.applyPatches.ath79} ''; config = { MIPS_ELF_APPENDED_DTB = "y"; diff --git a/devices/gl-mt300a/default.nix b/devices/gl-mt300a/default.nix index 50ba15c..5e6545c 100644 --- a/devices/gl-mt300a/default.nix +++ b/devices/gl-mt300a/default.nix @@ -21,13 +21,7 @@ module = { pkgs, config, ...}: let inherit (pkgs.liminix.networking) interface; - openwrt = pkgs.fetchFromGitHub { - name = "openwrt-source"; - repo = "openwrt"; - owner = "openwrt"; - rev = "a5265497a4f6da158e95d6a450cb2cb6dc085cab"; - hash = "sha256-YYi4gkpLjbOK7bM2MGQjAyEBuXJ9JNXoz/JEmYf8xE8="; - }; + inherit (pkgs) openwrt; mac80211 = pkgs.mac80211.override { drivers = ["rt2800soc"]; klibBuild = config.outputs.kernel.modulesupport; @@ -55,9 +49,9 @@ rootDevice = "1f05"; dts = { - src = "${openwrt}/target/linux/ramips/dts/mt7620a_glinet_gl-mt300a.dts"; + src = "${openwrt.src}/target/linux/ramips/dts/mt7620a_glinet_gl-mt300a.dts"; includes = [ - "${openwrt}/target/linux/ramips/dts" + "${openwrt.src}/target/linux/ramips/dts" ]; }; networkInterfaces = rec { @@ -94,17 +88,7 @@ hash = "sha256-yhO2cXIeIgUxkSZf/4aAsF11uxyh+UUZu6D1h92vCD8="; }; extraPatchPhase = '' - cp -av ${openwrt}/target/linux/generic/files/* . - chmod -R u+w . - cp -av ${openwrt}/target/linux/ramips/files/* . - chmod -R u+w . - patches() { - for i in $* ; do patch --batch --forward -p1 < $i ;done - } - patches ${openwrt}/target/linux/generic/backport-5.15/*.patch - patches ${openwrt}/target/linux/generic/pending-5.15/*.patch - patches ${openwrt}/target/linux/generic/hack-5.15/*.patch - patches ${openwrt}/target/linux/ramips/patches-5.15/*.patch + ${openwrt.applyPatches.ramips} ''; config = { MIPS_ELF_APPENDED_DTB = "y"; diff --git a/devices/gl-mt300n-v2/default.nix b/devices/gl-mt300n-v2/default.nix index 48f2c36..0cff7e7 100644 --- a/devices/gl-mt300n-v2/default.nix +++ b/devices/gl-mt300n-v2/default.nix @@ -16,14 +16,8 @@ inherit (pkgs.liminix.networking) interface; inherit (pkgs.liminix.services) oneshot; inherit (pkgs.pseudofile) dir symlink; + inherit (pkgs) openwrt; - openwrt = pkgs.fetchFromGitHub { - name = "openwrt-source"; - repo = "openwrt"; - owner = "openwrt"; - rev = "a5265497a4f6da158e95d6a450cb2cb6dc085cab"; - hash = "sha256-YYi4gkpLjbOK7bM2MGQjAyEBuXJ9JNXoz/JEmYf8xE8="; - }; mac80211 = pkgs.mac80211.override { drivers = ["mt7603e"]; klibBuild = config.outputs.kernel.modulesupport; @@ -52,9 +46,9 @@ rootDevice = "1f05"; dts = { - src = "${openwrt}/target/linux/ramips/dts/mt7628an_glinet_gl-mt300n-v2.dts"; + src = "${openwrt.src}/target/linux/ramips/dts/mt7628an_glinet_gl-mt300n-v2.dts"; includes = [ - "${openwrt}/target/linux/ramips/dts" + "${openwrt.src}/target/linux/ramips/dts" ]; }; networkInterfaces = rec { @@ -109,17 +103,7 @@ hash = "sha256-yhO2cXIeIgUxkSZf/4aAsF11uxyh+UUZu6D1h92vCD8="; }; extraPatchPhase = '' - cp -av ${openwrt}/target/linux/generic/files/* . - chmod -R u+w . - cp -av ${openwrt}/target/linux/ramips/files/* . - chmod -R u+w . - patches() { - for i in $* ; do patch --batch --forward -p1 < $i ;done - } - patches ${openwrt}/target/linux/generic/backport-5.15/*.patch - patches ${openwrt}/target/linux/generic/pending-5.15/*.patch - patches ${openwrt}/target/linux/generic/hack-5.15/*.patch - patches ${openwrt}/target/linux/ramips/patches-5.15/*.patch + ${openwrt.applyPatches.ramips} ''; config = { MIPS_ELF_APPENDED_DTB = "y"; diff --git a/pkgs/default.nix b/pkgs/default.nix index cc5847b..0eaa5b3 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -38,4 +38,6 @@ lzma = callPackage ./lzma {}; swconfig = callPackage ./swconfig {}; + + openwrt = callPackage ./openwrt {}; } diff --git a/pkgs/openwrt/default.nix b/pkgs/openwrt/default.nix new file mode 100644 index 0000000..e46ea85 --- /dev/null +++ b/pkgs/openwrt/default.nix @@ -0,0 +1,41 @@ +{ + fetchFromGitHub +, writeShellScript +}: +let + src = fetchFromGitHub { + name = "openwrt-source"; + repo = "openwrt"; + owner = "openwrt"; + rev = "a5265497a4f6da158e95d6a450cb2cb6dc085cab"; + hash = "sha256-YYi4gkpLjbOK7bM2MGQjAyEBuXJ9JNXoz/JEmYf8xE8="; + }; +in { + inherit src; + applyPatches.ath79 = writeShellScript "apply-patches-ath79" '' + cp -av ${src}/target/linux/generic/files/* . + chmod -R u+w . + cp -av ${src}/target/linux/ath79/files/* . + chmod -R u+w . + patches() { + for i in $* ; do patch --batch --forward -p1 < $i ;done + } + patches ${src}/target/linux/generic/backport-5.15/*.patch + patches ${src}/target/linux/generic/pending-5.15/*.patch + patches ${src}/target/linux/generic/hack-5.15/*.patch + patches ${src}/target/linux/ath79/patches-5.15/*.patch + ''; + applyPatches.ramips = writeShellScript "apply-patches-ramips" '' + cp -av ${src}/target/linux/generic/files/* . + chmod -R u+w . + cp -av ${src}/target/linux/ramips/files/* . + chmod -R u+w . + patches() { + for i in $* ; do patch --batch --forward -p1 < $i ;done + } + patches ${src}/target/linux/generic/backport-5.15/*.patch + patches ${src}/target/linux/generic/pending-5.15/*.patch + patches ${src}/target/linux/generic/hack-5.15/*.patch + patches ${src}/target/linux/ramips/patches-5.15/*.patch + ''; +}