{ pkgs, ... }: {
  # Keep Raspberry Pi kernel cmdline in sync with current system profile.
  system.activationScripts.updateRpiCmdline.text = ''
    export PATH="${pkgs.gnused}/bin:''${PATH}"
    for cmdline in /boot/firmware/nixos/*/cmdline.txt; do
      [ -e "$cmdline" ] || continue
      current_init="$(readlink -f /nix/var/nix/profiles/system)/init"
      if grep -q 'init=/nix/store/' "$cmdline"; then
        sed -i "s#init=/nix/store/[^ ]*/init#init=$current_init#" "$cmdline"
      fi
      if ! grep -q 'root=' "$cmdline"; then
        sed -i 's/ init=/ root=PARTUUID=4d44c78a-ee3c-4e3e-9eee-0f2eb10347b6 rootfstype=ext4 init=/' "$cmdline"
      fi
    done
  '';
}
