final: prev: {
  blesh = prev.blesh.overrideAttrs (oldAttrs: rec {
    inherit (prev.sources.blesh-nvfetcher) version src;

    dontBuild = false;
    buildInputs = [
      prev.gitMinimal
    ];

    patchPhase = ''
      substituteInPlace GNUmakefile \
        --replace "git submodule update --init --recursive" ""
    '';

    installFlags = [
      "PREFIX=$(out)"
    ];

    installPhase = ''
      source $stdenv/setup
      installPhase
    '';

    postInstall = ''
      mkdir -p "$out/bin"
      cat <<EOF >"$out/bin/blesh-share"
      #!${prev.runtimeShell}
      # Run this script to find the ble.sh shared folder
      # where all the shell scripts are living.
      echo "$out/share/blesh"
      EOF
      chmod +x "$out/bin/blesh-share"

      cat <<EOF >"$out/share/blesh/lib/_package.sh"
      _ble_base_package_type=nix

      function ble/base/package:nix/update {
        echo "Ble.sh is installed by Nix. You can update it there." >&2
        return 1
      }
      EOF
    '';
  });
}