anchor.diff:      # keys
       install -D -m0644 keys/* $out/share/refind/keys/
   
  -    # fix sharp-bang paths
  -    patchShebangs $out/bin/refind-*
  +    # The refind-install script assumes that all resource files are
  +    # installed under the same directory as the script itself. To avoid
  +    # having to patch around this assumption, generate a wrapper that
  +    # cds into $out/share/refind and executes the real script from
  +    # there.
  +    cat >$out/bin/refind-install <<EOF
  +#! ${stdenv.shell}
  +cd $out/share/refind && exec -a $out/bin/refind-install ./refind-install \$*
  +EOF
  +    chmod +x $out/bin/refind-install
   
  -    # Post-install fixes
  -    sed -e "s|^ThisDir=.*|ThisDir=$out/share/refind/|g" -i $out/bin/refind-install
  -    sed -e "s|^RefindDir=.*|RefindDir=$out/share/refind/|g" -i $out/bin/refind-install
  +    # Patch uses of `which`.  We could patch in calls to efibootmgr,
  +    # openssl, convert, and openssl, but that would greatly enlarge
  +    # refind's closure (from ca 28MB to over 400MB).
  +    sed -i 's,`which \(.*\)`,`type -p \1`,g' $out/share/refind/refind-install
  +    sed -i 's,`which \(.*\)`,`type -p \1`,g' $out/bin/refind-mvrefind
  +    sed -i 's,`which \(.*\)`,`type -p \1`,g' $out/bin/refind-mkfont
     '';
   
     meta = with stdenv.lib; {
  -    version = "0.10.3";
       description = "A graphical {,U}EFI boot manager";
       longDescription = ''
         rEFInd is a graphical boot manager for EFI- and UEFI-based
  
positive.code:     sed -e 's|-m64|-maccumulate-outgoing-args -m64|g' -i filesystems/Make.gnuefi
    '';
  
    buildPhase =
      let ldScript =
        if stdenv.system == "x86_64-linux" then "elf_x86_64_efi.lds"
        else if stdenv.system == "i686-linux" then "elf_ia32_efi.lds" else "null";
      in ''
        make prefix= EFIINC=${gnu-efi}/include/efi EFILIB=${gnu-efi}/lib GNUEFILIB=${gnu-efi}/lib EFICRT0=${gnu-efi}/lib LDSCRIPT=${gnu-efi}/lib/${ldScript} gnuefi fs_gnuefi
      '';
  
    installPhase = ''
      install -d $out/bin/
      install -d $out/share/refind/drivers_${HOSTARCH}/
      install -d $out/share/refind/tools_${HOSTARCH}/
      install -d $out/share/refind/docs/html/
      install -d $out/share/refind/docs/Styles/
      install -d $out/share/refind/fonts/
  
negative.code: { stdenv, fetchurl, fetchpatch, gnu-efi }:
  
  let
    archids = {
      "x86_64-linux" = { hostarch = "x86_64"; efiPlatform = "x64"; };
      "i686-linux" = rec { hostarch = "ia32"; efiPlatform = hostarch; };
    };
  
    inherit
      (archids.${stdenv.system} or (throw "unsupported system: ${stdenv.system}"))
      hostarch efiPlatform;
  in
  
  stdenv.mkDerivation rec {
    name = "refind-${version}";
    version = "0.10.3";
    srcName = "refind-src-${version}";
  
    src = fetchurl {
      url = "mirror://sourceforge/project/refind/${version}/${srcName}.tar.gz";
      sha256 = "1r2qp29mz08lx36i7x52i2598773bxvfhwryd954ssq2baifjav5";
    };
  
  