convert devices from overlay to module

this makes it possible for devices to stash things in
`config` (e.g. pathname to DTS) that can later be overwritten
(even by the end user)
This commit is contained in:
Daniel Barlow 2023-02-10 17:54:33 +00:00
parent 6be459b9ac
commit 8cead61740
8 changed files with 263 additions and 278 deletions

View file

@ -8,14 +8,14 @@
let
overlay = import ./overlay.nix;
pkgs = import nixpkgs (device.system // {
overlays = [overlay device.overlay];
overlays = [overlay];
config = {allowUnsupportedSystem = true; };
});
inherit (pkgs) callPackage writeText liminix fetchFromGitHub;
inherit (pkgs.lib) concatStringsSep;
config = (import ./merge-modules.nix) [
./modules/base.nix
({ lib, ... } : { config = { inherit (device) kernel; }; })
device.module
liminix-config
./modules/s6
./modules/users.nix
@ -33,11 +33,11 @@ let
outputs = rec {
inherit squashfs;
kernel = pkgs.kernel.override {
inherit (config.kernel) config;
kernel = liminix.builders.kernel.override {
inherit (config.kernel) config src extraPatchPhase;
};
dtb = (callPackage ./kernel/dtb.nix {}) {
dts = config.kernel.dts { inherit openwrt; };
dts = config.kernel.dts;
includes = [
"${openwrt}/target/linux/ath79/dts"
"${kernel.headers}/include"
@ -91,7 +91,7 @@ let
tftpd = pkgs.buildPackages.tufted;
};
in {
outputs = outputs // { default = outputs.${device.outputs.default}; };
outputs = outputs // { default = outputs.${config.device.defaultOutput}; };
# this is just here as a convenience, so that we can get a
# cross-compiling nix-shell for any package we're customizing

View file

@ -24,15 +24,9 @@
};
};
# 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:
module = {pkgs, ... }:
let
openwrt = final.fetchFromGitHub {
openwrt = pkgs.pkgsBuildBuild.fetchFromGitHub {
name = "openwrt-source";
repo = "openwrt";
owner = "openwrt";
@ -40,8 +34,14 @@
hash = "sha256-YYi4gkpLjbOK7bM2MGQjAyEBuXJ9JNXoz/JEmYf8xE8=";
};
in {
kernel = prev.kernel.override {
src = final.fetchurl {
device.defaultOutput = "directory";
device.boot = {
loadAddress = "0x80060000";
entryPoint = "0x80060000";
};
kernel = {
src = pkgs.pkgsBuildBuild.fetchurl {
name = "linux.tar.gz";
url = "https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.15.71.tar.gz";
hash = "sha256-yhO2cXIeIgUxkSZf/4aAsF11uxyh+UUZu6D1h92vCD8=";
@ -59,10 +59,7 @@
patches ${openwrt}/target/linux/generic/hack-5.15/*.patch
patches ${openwrt}/target/linux/ath79/patches-5.15/*.patch
'';
};
};
kernel = rec {
dts = { openwrt,... }:"${openwrt}/target/linux/ath79/dts/qca9531_glinet_gl-ar750.dts";
dts = "${openwrt}/target/linux/ath79/dts/qca9531_glinet_gl-ar750.dts";
config = {
MIPS_ELF_APPENDED_DTB = "y";
OF = "y";
@ -122,9 +119,5 @@
"SQUASHFS_XZ" = "y";
};
};
outputs.default = "directory";
boot = {
loadAddress = "0x80060000";
entryPoint = "0x80060000";
};
}

View file

@ -11,15 +11,9 @@
};
};
# 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:
module = { pkgs, ...}:
let
openwrt = final.fetchFromGitHub {
openwrt = pkgs.fetchFromGitHub {
name = "openwrt-source";
repo = "openwrt";
owner = "openwrt";
@ -27,8 +21,16 @@
hash = "sha256-YYi4gkpLjbOK7bM2MGQjAyEBuXJ9JNXoz/JEmYf8xE8=";
};
in {
kernel = prev.kernel.override {
src = final.fetchurl {
device = {
defaultOutput = "directory";
boot = {
loadAddress = "0x80000000";
entryPoint = "0x80000000";
};
};
kernel = {
src = pkgs.fetchurl {
name = "linux.tar.gz";
url = "https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.15.71.tar.gz";
hash = "sha256-yhO2cXIeIgUxkSZf/4aAsF11uxyh+UUZu6D1h92vCD8=";
@ -46,10 +48,7 @@
patches ${openwrt}/target/linux/generic/hack-5.15/*.patch
patches ${openwrt}/target/linux/ramips/patches-5.15/*.patch
'';
};
};
kernel = rec {
dts = { openwrt,... } : "${openwrt}/target/linux/ramips/dts/mt7620a_glinet_gl-mt300a.dts";
dts = "${openwrt}/target/linux/ramips/dts/mt7620a_glinet_gl-mt300a.dts";
config = {
MIPS_ELF_APPENDED_DTB = "y";
OF = "y";
@ -106,9 +105,5 @@
"SQUASHFS_XZ" = "y";
};
};
outputs.default = "directory";
boot = {
loadAddress = "0x80000000";
entryPoint = "0x80000000";
};
}

View file

@ -11,15 +11,9 @@
};
};
# 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:
module = { pkgs, ...}:
let
openwrt = final.fetchFromGitHub {
openwrt = pkgs.fetchFromGitHub {
name = "openwrt-source";
repo = "openwrt";
owner = "openwrt";
@ -27,8 +21,16 @@
hash = "sha256-YYi4gkpLjbOK7bM2MGQjAyEBuXJ9JNXoz/JEmYf8xE8=";
};
in {
kernel = prev.kernel.override {
src = final.fetchurl {
device = {
defaultOutput = "directory";
boot = {
loadAddress = "0x80000000";
entryPoint = "0x80000000";
};
};
kernel = {
src = pkgs.fetchurl {
name = "linux.tar.gz";
url = "https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.15.71.tar.gz";
hash = "sha256-yhO2cXIeIgUxkSZf/4aAsF11uxyh+UUZu6D1h92vCD8=";
@ -46,10 +48,7 @@
patches ${openwrt}/target/linux/generic/hack-5.15/*.patch
patches ${openwrt}/target/linux/ramips/patches-5.15/*.patch
'';
};
};
kernel = rec {
dts = { openwrt,... } : "${openwrt}/target/linux/ramips/dts/mt7628an_glinet_gl-mt300n-v2.dts";
dts = "${openwrt}/target/linux/ramips/dts/mt7628an_glinet_gl-mt300n-v2.dts";
config = {
MIPS_ELF_APPENDED_DTB = "y";
OF = "y";
@ -117,9 +116,5 @@
"SQUASHFS_XZ" = "y";
};
};
outputs.default = "directory";
boot = {
loadAddress = "0x80000000";
entryPoint = "0x80000000";
};
}

View file

@ -13,22 +13,13 @@
};
};
overlay = final: prev:
let inherit (final) stdenvNoCC fetchFromGitHub;
in {
kernel = prev.kernel.override {
# using fetchurl not fetchzip because it doesn't unpack, and
# copying 6GB of data from one store location to another
# takes an absolute bloody age
src = final.fetchurl {
module = {pkgs, ... }: {
kernel = {
src = pkgs.pkgsBuildBuild.fetchurl {
name = "linux.tar.gz";
url = "https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.19.16.tar.gz";
hash = "sha256-m4NeoEsCEK0HSIKTZ6zYTgk1fD3W0PSOMXN6fyHpkP8=";
};
};
};
kernel = {
config = {
MIPS_MALTA= "y";
CPU_LITTLE_ENDIAN= "n";
@ -50,5 +41,6 @@
SERIAL_8250_CONSOLE= "y";
};
};
outputs.default = "directory";
device.defaultOutput = "directory";
};
}

View file

@ -24,7 +24,12 @@ in {
};
filesystem = mkOption { type = types.anything; };
kernel = {
dts = mkOption { type = types.functionTo types.string; };
src = mkOption { type = types.package; } ;
extraPatchPhase = mkOption {
default = "true";
type = types.lines;
} ;
dts = mkOption { type = types.string; };
config = mkOption {
# mostly the values are y n or m, but sometimes
# other strings are also used
@ -40,6 +45,12 @@ in {
users = mkOption {
type = types.attrsOf types.anything;
};
device = {
defaultOutput = mkOption {
type = types.nonEmptyStr;
};
boot = mkOption { type = types.any; };
};
};
config = {
defaultProfile.packages = with pkgs;

View file

@ -6,14 +6,13 @@ final: prev: {
networking = final.callPackage ./pkgs/liminix-tools/networking {};
builders = {
squashfs = final.callPackage ./pkgs/liminix-tools/builders/squashfs.nix {};
kernel = final.callPackage ./pkgs/kernel {};
};
};
writeAshScript = final.callPackage ./pkgs/write-ash-script {};
s6-init-bin = final.callPackage ./pkgs/s6-init-bin {};
s6-rc-database = final.callPackage ./pkgs/s6-rc-database {};
kernel = final.callPackage ./pkgs/kernel {};
dnsmasq =
let d = prev.dnsmasq.overrideAttrs(o: {
preBuild = ''

View file

@ -6,7 +6,7 @@
, config
, src
, extraPatchPhase ? "true"
, extraPatchPhase ? "echo"
} :
let writeConfig = name : config: writeText name
(builtins.concatStringsSep