forked from dan/liminix
rename config.outputs to config.system.outputs
New rules: everything under "config" that isn't actually configuration (e.g. build products) will in future live in config.system. This is the first step.
This commit is contained in:
parent
492317623d
commit
2e50368bd2
|
@ -41,8 +41,8 @@ let
|
|||
];
|
||||
}).config.system;
|
||||
in {
|
||||
outputs = config.outputs // {
|
||||
default = config.outputs.${config.hardware.defaultOutput};
|
||||
outputs = config.system.outputs // {
|
||||
default = config.system.outputs.${config.hardware.defaultOutput};
|
||||
};
|
||||
|
||||
# this is just here as a convenience, so that we can get a
|
||||
|
|
|
@ -59,7 +59,7 @@
|
|||
};
|
||||
mac80211 = pkgs.mac80211.override {
|
||||
drivers = ["ath9k" "ath10k_pci"];
|
||||
klibBuild = config.outputs.kernel.modulesupport;
|
||||
klibBuild = config.system.outputs.kernel.modulesupport;
|
||||
};
|
||||
ath10k_cal_data =
|
||||
let
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
inherit (pkgs) openwrt;
|
||||
mac80211 = pkgs.mac80211.override {
|
||||
drivers = ["rt2800soc"];
|
||||
klibBuild = config.outputs.kernel.modulesupport;
|
||||
klibBuild = config.system.outputs.kernel.modulesupport;
|
||||
};
|
||||
in {
|
||||
hardware = {
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
mac80211 = pkgs.mac80211.override {
|
||||
drivers = ["mt7603e"];
|
||||
klibBuild = config.outputs.kernel.modulesupport;
|
||||
klibBuild = config.system.outputs.kernel.modulesupport;
|
||||
};
|
||||
wlan_firmware = pkgs.fetchurl {
|
||||
url = "https://github.com/openwrt/mt76/raw/f24b56f935392ca1d35fae5fd6e56ef9deda4aad/firmware/mt7628_e2.bin";
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
let
|
||||
mac80211 = pkgs.mac80211.override {
|
||||
drivers = ["mac80211_hwsim"];
|
||||
klibBuild = config.outputs.kernel.modulesupport;
|
||||
klibBuild = config.system.outputs.kernel.modulesupport;
|
||||
};
|
||||
inherit (pkgs.liminix.networking) interface;
|
||||
in {
|
||||
|
|
|
@ -238,8 +238,8 @@ in rec {
|
|||
let
|
||||
script= pkgs.firewallgen "firewall.nft" (import ./rotuer-firewall.nix);
|
||||
kmodules = pkgs.kernel-modules.override {
|
||||
kernelSrc = config.outputs.kernel.src;
|
||||
modulesupport = config.outputs.kernel.modulesupport;
|
||||
kernelSrc = config.system.outputs.kernel.src;
|
||||
modulesupport = config.system.outputs.kernel.modulesupport;
|
||||
kconfig = {
|
||||
NFT_FIB_IPV4 = "m";
|
||||
NFT_FIB_IPV6 = "m";
|
||||
|
|
|
@ -8,8 +8,32 @@ let
|
|||
inherit (lib) mkOption types concatStringsSep;
|
||||
inherit (config.boot) tftp;
|
||||
in {
|
||||
options = {
|
||||
options.system.outputs = {
|
||||
firmware = mkOption {
|
||||
type = types.package;
|
||||
internal = true; # component of flashimage
|
||||
description = ''
|
||||
Binary image (combining kernel, FDT, rootfs, initramfs
|
||||
if needed, etc) for the target device.
|
||||
'';
|
||||
};
|
||||
flash-scr = mkOption {
|
||||
type = types.package;
|
||||
internal = true; # component of flashimage
|
||||
description = ''
|
||||
Copy-pastable U-Boot commands to TFTP download the
|
||||
image and write it to flash
|
||||
'';
|
||||
};
|
||||
flashimage = mkOption {
|
||||
type = types.package;
|
||||
description = ''
|
||||
Flashable image for the target device, and the script to
|
||||
install it
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
kernel = {
|
||||
config = {
|
||||
|
@ -21,43 +45,44 @@ in {
|
|||
"flashcp"
|
||||
];
|
||||
|
||||
outputs.firmware =
|
||||
let o = config.outputs; in
|
||||
pkgs.runCommand "firmware" {} ''
|
||||
dd if=${o.uimage} of=$out bs=128k conv=sync
|
||||
dd if=${o.rootfs} of=$out bs=128k conv=sync,nocreat,notrunc oflag=append
|
||||
'';
|
||||
outputs.flashimage =
|
||||
let o = config.outputs; in
|
||||
pkgs.runCommand "flashimage" {} ''
|
||||
mkdir $out
|
||||
cd $out
|
||||
ln -s ${o.firmware} firmware.bin
|
||||
ln -s ${o.rootfs} rootfs
|
||||
ln -s ${o.kernel} vmlinux
|
||||
ln -s ${o.manifest} manifest
|
||||
ln -s ${o.kernel.headers} build
|
||||
ln -s ${o.uimage} uimage
|
||||
ln -s ${o.dtb} dtb
|
||||
ln -s ${o.flash-scr} flash.scr
|
||||
'';
|
||||
|
||||
outputs.flash-scr =
|
||||
let
|
||||
inherit (pkgs.lib.trivial) toHexString;
|
||||
inherit (config.hardware) flash;
|
||||
in
|
||||
pkgs.buildPackages.runCommand "" {} ''
|
||||
imageSize=$(stat -L -c %s ${config.outputs.firmware})
|
||||
cat > $out << EOF
|
||||
setenv serverip ${tftp.serverip}
|
||||
setenv ipaddr ${tftp.ipaddr}
|
||||
tftp 0x$(printf %x ${tftp.loadAddress}) result/firmware.bin
|
||||
erase 0x$(printf %x ${flash.address}) +${flash.size}
|
||||
cp.b 0x$(printf %x ${tftp.loadAddress}) 0x$(printf %x ${flash.address}) \''${filesize}
|
||||
echo command line was ${builtins.toJSON (concatStringsSep " " config.boot.commandLine)}
|
||||
EOF
|
||||
system.outputs = {
|
||||
firmware =
|
||||
let o = config.system.outputs; in
|
||||
pkgs.runCommand "firmware" {} ''
|
||||
dd if=${o.uimage} of=$out bs=128k conv=sync
|
||||
dd if=${o.rootfs} of=$out bs=128k conv=sync,nocreat,notrunc oflag=append
|
||||
'';
|
||||
flashimage =
|
||||
let o = config.system.outputs; in
|
||||
pkgs.runCommand "flashimage" {} ''
|
||||
mkdir $out
|
||||
cd $out
|
||||
ln -s ${o.firmware} firmware.bin
|
||||
ln -s ${o.rootfs} rootfs
|
||||
ln -s ${o.kernel} vmlinux
|
||||
ln -s ${o.manifest} manifest
|
||||
ln -s ${o.kernel.headers} build
|
||||
ln -s ${o.uimage} uimage
|
||||
ln -s ${o.dtb} dtb
|
||||
ln -s ${o.flash-scr} flash.scr
|
||||
'';
|
||||
|
||||
flash-scr =
|
||||
let
|
||||
inherit (pkgs.lib.trivial) toHexString;
|
||||
inherit (config.hardware) flash;
|
||||
in
|
||||
pkgs.buildPackages.runCommand "" {} ''
|
||||
imageSize=$(stat -L -c %s ${config.system.outputs.firmware})
|
||||
cat > $out << EOF
|
||||
setenv serverip ${tftp.serverip}
|
||||
setenv ipaddr ${tftp.ipaddr}
|
||||
tftp 0x$(printf %x ${tftp.loadAddress}) result/firmware.bin
|
||||
erase 0x$(printf %x ${flash.address}) +${flash.size}
|
||||
cp.b 0x$(printf %x ${tftp.loadAddress}) 0x$(printf %x ${flash.address}) \''${filesize}
|
||||
echo command line was ${builtins.toJSON (concatStringsSep " " config.boot.commandLine)}
|
||||
EOF
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
, ...
|
||||
}:
|
||||
let
|
||||
inherit (lib) mkEnableOption mkIf;
|
||||
inherit (lib) mkEnableOption mkOption mkIf types;
|
||||
inherit (pkgs) runCommand callPackage writeText;
|
||||
in
|
||||
{
|
||||
|
@ -14,15 +14,23 @@ in
|
|||
enable = mkEnableOption "enable initramfs";
|
||||
default = false;
|
||||
};
|
||||
system.outputs.initramfs = mkOption {
|
||||
type = types.package;
|
||||
internal = true;
|
||||
description = ''
|
||||
Initramfs image capable of mounting the jffs2 root
|
||||
filesystem
|
||||
'';
|
||||
};
|
||||
};
|
||||
config = mkIf config.boot.initramfs.enable {
|
||||
kernel.config = {
|
||||
BLK_DEV_INITRD = "y";
|
||||
INITRAMFS_SOURCE = builtins.toJSON "${config.outputs.initramfs}";
|
||||
INITRAMFS_SOURCE = builtins.toJSON "${config.system.outputs.initramfs}";
|
||||
# INITRAMFS_COMPRESSION_LZO = "y";
|
||||
};
|
||||
|
||||
outputs = {
|
||||
system.outputs = {
|
||||
initramfs =
|
||||
let inherit (pkgs.pkgsBuildBuild) gen_init_cpio;
|
||||
in runCommand "initramfs.cpio" {} ''
|
||||
|
|
|
@ -5,12 +5,23 @@
|
|||
, ...
|
||||
}:
|
||||
let
|
||||
inherit (lib) mkIf;
|
||||
inherit (lib) mkIf mkOption types;
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
./initramfs.nix
|
||||
];
|
||||
options.system.outputs = {
|
||||
systemConfiguration = mkOption {
|
||||
type = types.package;
|
||||
description = ''
|
||||
pkgs.systemconfig for the configured filesystem,
|
||||
contains 'activate' and 'init' commands
|
||||
'';
|
||||
internal = true;
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf (config.rootfsType == "jffs2") {
|
||||
kernel.config = {
|
||||
JFFS2_FS = "y";
|
||||
|
@ -21,7 +32,7 @@ in
|
|||
JFFS2_CMODE_SIZE = "y";
|
||||
};
|
||||
boot.initramfs.enable = true;
|
||||
outputs = rec {
|
||||
system.outputs = rec {
|
||||
systemConfiguration =
|
||||
pkgs.systemconfig config.filesystem.contents;
|
||||
rootfs =
|
||||
|
|
|
@ -8,39 +8,56 @@ let
|
|||
inherit (lib) mkOption mkForce types concatStringsSep;
|
||||
in {
|
||||
imports = [ ./ramdisk.nix ];
|
||||
options.system.outputs = {
|
||||
kexecboot = mkOption {
|
||||
type = types.package;
|
||||
description = ''
|
||||
Directory containing files needed for kexec booting.
|
||||
Can be copied onto the target device using ssh or similar
|
||||
'';
|
||||
};
|
||||
boot-sh = mkOption {
|
||||
type = types.package;
|
||||
description = ''
|
||||
Shell script to run on the target device that invokes
|
||||
kexec with appropriate options
|
||||
'';
|
||||
};
|
||||
};
|
||||
config = {
|
||||
boot.ramdisk.enable = true;
|
||||
system.outputs = {
|
||||
kexecboot =
|
||||
let o = config.system.outputs; in
|
||||
pkgs.runCommand "kexecboot" {} ''
|
||||
mkdir $out
|
||||
cd $out
|
||||
ln -s ${o.rootfs} rootfs
|
||||
ln -s ${o.kernel} kernel
|
||||
ln -s ${o.manifest} manifest
|
||||
ln -s ${o.boot-sh} boot.sh
|
||||
ln -s ${pkgs.kexec-tools-static}/bin/kexec ./kexec
|
||||
ln -s ${o.dtb} dtb
|
||||
'';
|
||||
|
||||
outputs.kexecboot =
|
||||
let o = config.outputs; in
|
||||
pkgs.runCommand "kexecboot" {} ''
|
||||
mkdir $out
|
||||
cd $out
|
||||
ln -s ${o.rootfs} rootfs
|
||||
ln -s ${o.kernel} kernel
|
||||
ln -s ${o.manifest} manifest
|
||||
ln -s ${o.boot-sh} boot.sh
|
||||
ln -s ${pkgs.kexec-tools-static}/bin/kexec ./kexec
|
||||
ln -s ${o.dtb} dtb
|
||||
'';
|
||||
|
||||
outputs.boot-sh =
|
||||
let
|
||||
inherit (pkgs.lib.trivial) toHexString;
|
||||
inherit (config.outputs) rootfs kernel;
|
||||
cmdline = concatStringsSep " " config.boot.commandLine;
|
||||
in
|
||||
pkgs.buildPackages.runCommand "boot.sh.sh" {
|
||||
} ''
|
||||
rootfsStart=${toString (100 * 1024 * 1024)}
|
||||
rootfsBytes=$(stat -L -c %s ${rootfs})
|
||||
append_cmd="mtdparts=phram0:''${rootfsBytes}(rootfs) phram.phram=phram0,''${rootfsStart},''${rootfsBytes} memmap=''${rootfsBytes}\$''${rootfsStart}";
|
||||
cat > $out <<EOF
|
||||
#!/bin/sh
|
||||
test -d \$1
|
||||
cd \$1
|
||||
./kexec -f -d --map-file rootfs@$rootfsStart --dtb dtb --command-line '${cmdline} $append_cmd' kernel
|
||||
EOF
|
||||
'';
|
||||
boot-sh =
|
||||
let
|
||||
inherit (pkgs.lib.trivial) toHexString;
|
||||
inherit (config.system.outputs) rootfs kernel;
|
||||
cmdline = concatStringsSep " " config.boot.commandLine;
|
||||
in
|
||||
pkgs.buildPackages.runCommand "boot.sh.sh" {
|
||||
} ''
|
||||
rootfsStart=${toString (100 * 1024 * 1024)}
|
||||
rootfsBytes=$(stat -L -c %s ${rootfs})
|
||||
append_cmd="mtdparts=phram0:''${rootfsBytes}(rootfs) phram.phram=phram0,''${rootfsStart},''${rootfsBytes} memmap=''${rootfsBytes}\$''${rootfsStart}";
|
||||
cat > $out <<EOF
|
||||
#!/bin/sh
|
||||
test -d \$1
|
||||
cd \$1
|
||||
./kexec -f -d --map-file rootfs@$rootfsStart --dtb dtb --command-line '${cmdline} $append_cmd' kernel
|
||||
EOF
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -13,14 +13,52 @@ in
|
|||
./squashfs.nix
|
||||
];
|
||||
options = {
|
||||
outputs = mkOption {
|
||||
type = types.attrsOf types.package;
|
||||
default = {};
|
||||
system.outputs = {
|
||||
kernel = mkOption {
|
||||
type = types.package;
|
||||
description = ''
|
||||
Kernel vmlinux file (usually ELF)
|
||||
'';
|
||||
};
|
||||
dtb = mkOption {
|
||||
type = types.package;
|
||||
description = ''
|
||||
Compiled device tree (FDT) for the target device
|
||||
'';
|
||||
};
|
||||
uimage = mkOption {
|
||||
type = types.package;
|
||||
description = ''
|
||||
Combined kernel and FDT in uImage (U-Boot compatible) format
|
||||
'';
|
||||
};
|
||||
vmroot = mkOption {
|
||||
type = types.package;
|
||||
description = ''
|
||||
Directory containing separate kernel and rootfs image for
|
||||
use with qemu (see mips-vm)
|
||||
'';
|
||||
};
|
||||
manifest = mkOption {
|
||||
type = types.package;
|
||||
description = ''
|
||||
Debugging aid. JSON rendition of config.filesystem, on
|
||||
which can run "nix-store -q --tree" on it and find
|
||||
out what's in the image, which is nice if it's unexpectedly huge
|
||||
'';
|
||||
};
|
||||
rootfs = mkOption {
|
||||
type = types.package;
|
||||
description = ''
|
||||
root filesystem (squashfs or jffs2) image
|
||||
'';
|
||||
internal = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
config = {
|
||||
outputs = rec {
|
||||
tftpd = pkgs.buildPackages.tufted;
|
||||
system.outputs = rec {
|
||||
# tftpd = pkgs.buildPackages.tufted;
|
||||
kernel = liminix.builders.kernel.override {
|
||||
inherit (config.kernel) config src extraPatchPhase;
|
||||
};
|
||||
|
@ -40,14 +78,12 @@ in
|
|||
vmroot = pkgs.runCommand "qemu" {} ''
|
||||
mkdir $out
|
||||
cd $out
|
||||
ln -s ${config.outputs.rootfs} rootfs
|
||||
ln -s ${config.system.outputs.rootfs} rootfs
|
||||
ln -s ${kernel} vmlinux
|
||||
ln -s ${manifest} manifest
|
||||
ln -s ${kernel.headers} build
|
||||
'';
|
||||
|
||||
# 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);
|
||||
};
|
||||
};
|
||||
|
|
|
@ -10,8 +10,7 @@ let
|
|||
in
|
||||
{
|
||||
config = mkIf (config.rootfsType == "squashfs") {
|
||||
outputs = rec {
|
||||
rootfs = liminix.builders.squashfs config.filesystem.contents;
|
||||
};
|
||||
system.outputs.rootfs =
|
||||
liminix.builders.squashfs config.filesystem.contents;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -13,40 +13,58 @@ in {
|
|||
type = types.int;
|
||||
default = 0;
|
||||
};
|
||||
options.system.outputs = {
|
||||
tftpboot = mkOption {
|
||||
type = types.package;
|
||||
description = ''
|
||||
Directory containing files needed for TFTP booting
|
||||
'';
|
||||
};
|
||||
boot-scr = mkOption {
|
||||
type = types.package;
|
||||
description = ''
|
||||
U-Boot commands to load and boot a kernel and rootfs over TFTP.
|
||||
Copy-paste into the device boot monitor
|
||||
'';
|
||||
};
|
||||
};
|
||||
config = {
|
||||
boot.ramdisk.enable = true;
|
||||
|
||||
outputs.tftpboot =
|
||||
let o = config.outputs; in
|
||||
pkgs.runCommand "tftpboot" {} ''
|
||||
mkdir $out
|
||||
cd $out
|
||||
ln -s ${o.rootfs} rootfs
|
||||
ln -s ${o.kernel} vmlinux
|
||||
ln -s ${o.manifest} manifest
|
||||
ln -s ${o.kernel.headers} build
|
||||
ln -s ${o.uimage} uimage
|
||||
ln -s ${o.boot-scr} boot.scr
|
||||
'';
|
||||
system.outputs = rec {
|
||||
tftpboot =
|
||||
let o = config.system.outputs; in
|
||||
pkgs.runCommand "tftpboot" {} ''
|
||||
mkdir $out
|
||||
cd $out
|
||||
ln -s ${o.rootfs} rootfs
|
||||
ln -s ${o.kernel} vmlinux
|
||||
ln -s ${o.manifest} manifest
|
||||
ln -s ${o.kernel.headers} build
|
||||
ln -s ${o.uimage} uimage
|
||||
ln -s ${o.boot-scr} boot.scr
|
||||
'';
|
||||
|
||||
outputs.boot-scr =
|
||||
let
|
||||
inherit (pkgs.lib.trivial) toHexString;
|
||||
in
|
||||
pkgs.buildPackages.runCommand "boot-scr" {} ''
|
||||
uimageSize=$(($(stat -L -c %s ${config.outputs.uimage}) + 0x1000 &(~0xfff)))
|
||||
rootfsStart=0x$(printf %x $((${cfg.loadAddress} + 0x100000 + $uimageSize)))
|
||||
rootfsBytes=$(($(stat -L -c %s ${config.outputs.rootfs}) + 0x100000 &(~0xfffff)))
|
||||
rootfsBytes=$(($rootfsBytes + ${toString cfg.freeSpaceBytes} ))
|
||||
cmd="mtdparts=phram0:''${rootfsMb}M(rootfs) phram.phram=phram0,''${rootfsStart},''${rootfsBytes},${config.hardware.flash.eraseBlockSize} memmap=''${rootfsBytes}\$''${rootfsStart} root=/dev/mtdblock0";
|
||||
boot-scr =
|
||||
let
|
||||
inherit (pkgs.lib.trivial) toHexString;
|
||||
o = config.system.outputs;
|
||||
in
|
||||
pkgs.buildPackages.runCommand "boot-scr" {} ''
|
||||
uimageSize=$(($(stat -L -c %s ${o.uimage}) + 0x1000 &(~0xfff)))
|
||||
rootfsStart=0x$(printf %x $((${cfg.loadAddress} + 0x100000 + $uimageSize)))
|
||||
rootfsBytes=$(($(stat -L -c %s ${o.rootfs}) + 0x100000 &(~0xfffff)))
|
||||
rootfsBytes=$(($rootfsBytes + ${toString cfg.freeSpaceBytes} ))
|
||||
cmd="mtdparts=phram0:''${rootfsMb}M(rootfs) phram.phram=phram0,''${rootfsStart},''${rootfsBytes},${config.hardware.flash.eraseBlockSize} memmap=''${rootfsBytes}\$''${rootfsStart} root=/dev/mtdblock0";
|
||||
|
||||
cat > $out << EOF
|
||||
setenv serverip ${cfg.serverip}
|
||||
setenv ipaddr ${cfg.ipaddr}
|
||||
setenv bootargs 'liminix $cmd'
|
||||
tftp 0x$(printf %x ${cfg.loadAddress}) result/uimage ; tftp 0x$(printf %x $rootfsStart) result/rootfs
|
||||
bootm 0x$(printf %x ${cfg.loadAddress})
|
||||
EOF
|
||||
'';
|
||||
cat > $out << EOF
|
||||
setenv serverip ${cfg.serverip}
|
||||
setenv ipaddr ${cfg.ipaddr}
|
||||
setenv bootargs 'liminix $cmd'
|
||||
tftp 0x$(printf %x ${cfg.loadAddress}) result/uimage ; tftp 0x$(printf %x $rootfsStart) result/rootfs
|
||||
bootm 0x$(printf %x ${cfg.loadAddress})
|
||||
EOF
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue