liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

service.nix (1005B)


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