anchor.diff:          wrapProgram $out/bin/factorio                                \
             --prefix LD_LIBRARY_PATH : /run/opengl-driver/lib:$libPath \
             --run "$out/share/factorio/update-config.sh"               \
  -          --argv0 "" \
  -          --add-flags "-c \$HOME/.factorio/config.cfg ${optionalString (mods != []) "--mod-directory=${modDir}"}"
  +          --argv0 ""                                                 \
  +          --add-flags "-c \$HOME/.factorio/config.cfg"               \
  +          ${if mods!=[] then "--add-flags --mod-directory=${modDir}" else ""}
   
             # TODO Currently, every time a mod is changed/added/removed using the
             # modlist, a new derivation will take up the entire footprint of the
  
positive.code:       '';
      };
    };
  in stdenv.mkDerivation (releases.${releaseType})
  
negative.code: , username ? "" , password ? ""
  }:
  
  assert releaseType == "alpha"
      || releaseType == "headless"
      || releaseType == "demo";
  
  let
  
    # NB If you nix-prefetch-url any of these, be sure to add a --name arg,
    #    where the ultimate "_" (before the version) is changed to a "-".
    binDists = {
      x86_64-linux = let bdist = bdistForArch { inUrl = "linux64"; inTar = "x64"; }; in {
        alpha    = bdist { sha256 = "1m2r0n99ngqq47s9fzr09d347i15an6x9v1qlij8yf8w7lyrdy4z"; fetcher = authenticatedFetch; };
        headless = bdist { sha256 = "17x0dlmfd7jwmpmn5i8wag28rl01iysqz3ri6g6msxjnvj5l6byn"; };
        demo     = bdist { sha256 = "03nwn4838yhqq0r76pf2m4wxi32rsq0knsxmq3qq4ycji89q1dyc"; };
      };
      i686-linux = let bdist = bdistForArch { inUrl = "linux32"; inTar = "i386"; }; in {
        alpha    = bdist { sha256 = "0nnfkxxqnywx1z05xnndgh71gp4izmwdk026nnjih74m2k5j086l"; version = "0.14.23"; nameMut = asGz; };
        headless = bdist { };
        demo     = bdist { };
      };
    };
    actual = binDists.${stdenv.system}.${releaseType};
  
    bdistForArch = arch: { sha256 ? null
                         , version ? "0.15.33"
                         , fetcher ? fetchurl
                         , nameMut ? x: x
                         }:
      if sha256 == null then
        abort "Factorio ${releaseType}-${arch.inTar} binaries are not (and were never?) available to download"
      else {
        inherit version arch;
        src = fetcher {
          inherit sha256;
          url = "https://www.factorio.com/get-download/${version}/${releaseType}/${arch.inUrl}";
          name = nameMut "factorio_${releaseType}_${arch.inTar}-${version}.tar.xz";
        };
      };
    authenticatedFetch = callPackage ./fetch.nix { inherit username password; };
    asGz = builtins.replaceStrings [".xz"] [".gz"];
  
  
    configBaseCfg = ''
      use-system-read-write-data-directories=false
  