zyxel-nwa-fit.nix (1741B)
1 { 2 config 3 , pkgs 4 , lib 5 , ... 6 }: 7 let 8 inherit (lib) mkIf mkEnableOption mkOption types concatStringsSep; 9 models = "6b e1 6f e1 ff ff ff ff ff ff"; 10 in { 11 options.system.outputs = { 12 zyxel-nwa-fit = mkOption { 13 type = types.package; 14 description = '' 15 zyxel-nwa-fit 16 ************* 17 18 This output provides a FIT image for Zyxel NWA series 19 containing a kernel image and an UBIFS rootfs. 20 21 It can usually be used as a factory image to install Liminix 22 on a system with pre-existing firmware and OS. 23 ''; 24 }; 25 }; 26 27 imports = [ 28 ./ubivolume.nix 29 ]; 30 31 config = mkIf (config.rootfsType == "ubifs") { 32 33 system.outputs.zyxel-nwa-fit = 34 let 35 o = config.system.outputs; 36 # 8129kb padding. 37 paddedKernel = pkgs.runCommand "padded-kernel" {} '' 38 cp --no-preserve=mode ${o.uimage} $out 39 dd if=/dev/zero of=$out bs=1 count=1 seek=8388607 40 ''; 41 firmwareImage = pkgs.runCommand "firmware-image" {} '' 42 cat ${paddedKernel} ${o.rootfs} > $out 43 ''; 44 dts = pkgs.writeText "image.its" '' 45 /dts-v1/; 46 47 / { 48 description = "Zyxel FIT (Flattened Image Tree)"; 49 compat-models = [${models}]; 50 #address-cells = <1>; 51 52 images { 53 firmware { 54 data = /incbin/("${firmwareImage}"); 55 type = "firmware"; 56 compression = "none"; 57 hash@1 { 58 algo = "sha1"; 59 }; 60 }; 61 }; 62 }; 63 ''; 64 in 65 pkgs.runCommand "zyxel-nwa-fit-${config.boot.imageType}" { 66 nativeBuildInputs = [ pkgs.pkgsBuildBuild.ubootTools pkgs.pkgsBuildBuild.dtc ]; 67 } '' 68 mkimage -f ${dts} $out 69 ''; 70 }; 71 }