service.nix (1019B)
1 { 2 liminix, 3 lib, 4 zyxel-bootconfig, 5 }: 6 { 7 ensureActiveImage, 8 primaryMtdPartition, 9 secondaryMtdPartition, 10 bootConfigurationMtdPartition, 11 kernelCommandLineSource, 12 }: 13 let 14 inherit (liminix.services) oneshot; 15 activeImageIndex = if ensureActiveImage == "primary" then 0 else 1; 16 in 17 oneshot { 18 name = "zyxel-boot-configure"; 19 up = '' 20 set -- $(cat /proc/device-tree/chosen/bootargs) 21 for x in "$@"; do 22 case "$x" in 23 bootImage=*) 24 BOOT_IMAGE="''${x#bootImage=}" 25 echo "Current boot image is $BOOT_IMAGE." 26 ;; 27 esac 28 done 29 30 if test -z "$BOOT_IMAGE"; then 31 echo "No valid image was provided in the kernel command line." 32 exit 1 33 else 34 ${lib.getExe zyxel-bootconfig} ${bootConfigurationMtdPartition} set-image-status "$BOOT_IMAGE" valid 35 ${lib.getExe zyxel-bootconfig} ${bootConfigurationMtdPartition} set-active-image ${toString activeImageIndex} 36 37 echo "Active image is now ${ensureActiveImage}" 38 fi 39 ''; 40 }