diff options
author | Eric Litak <elitak@gmail.com> | 2016-08-03 06:44:15 -0700 |
---|---|---|
committer | Eric Litak <elitak@gmail.com> | 2016-08-03 16:44:51 -0700 |
commit | d33540734ffd5da87fc01fdc959463b77fc267bf (patch) | |
tree | 45580d9e8e88a6d7824cc139f2f7f0a6291a4c4c /pkgs/games | |
parent | 4b96a2d14825f4cc3138b23c25d1b3d8c1d68ab2 (diff) | |
download | nixlib-d33540734ffd5da87fc01fdc959463b77fc267bf.tar nixlib-d33540734ffd5da87fc01fdc959463b77fc267bf.tar.gz nixlib-d33540734ffd5da87fc01fdc959463b77fc267bf.tar.bz2 nixlib-d33540734ffd5da87fc01fdc959463b77fc267bf.tar.lz nixlib-d33540734ffd5da87fc01fdc959463b77fc267bf.tar.xz nixlib-d33540734ffd5da87fc01fdc959463b77fc267bf.tar.zst nixlib-d33540734ffd5da87fc01fdc959463b77fc267bf.zip |
factorio: rudimentary mod support for factorio's nixos module
Diffstat (limited to 'pkgs/games')
-rw-r--r-- | pkgs/games/factorio/default.nix | 26 | ||||
-rw-r--r-- | pkgs/games/factorio/utils.nix | 49 |
2 files changed, 71 insertions, 4 deletions
diff --git a/pkgs/games/factorio/default.nix b/pkgs/games/factorio/default.nix index ace8dc658f22..bb6cffdb1224 100644 --- a/pkgs/games/factorio/default.nix +++ b/pkgs/games/factorio/default.nix @@ -1,6 +1,8 @@ { stdenv, callPackage, fetchurl, makeWrapper , alsaLib, libX11, libXcursor, libXinerama, libXrandr, libXi, mesa_noglu +, factorio-utils , releaseType +, mods ? [] , username ? "" , password ? "" }: @@ -54,14 +56,16 @@ let fi ''; + modDir = factorio-utils.mkModDirDrv mods; + base = { name = "factorio-${releaseType}-${version}"; src = fetch.${arch.inTar}.${releaseType}; + preferLocalBuild = true; dontBuild = true; - # TODO detangle headless/normal mode wrapping, libs, etc. test all urls 32/64/headless/gfx installPhase = '' mkdir -p $out/{bin,share/factorio} cp -a data $out/share/factorio @@ -71,8 +75,6 @@ let $out/bin/factorio ''; - preferLocalBuild = true; - meta = { description = "A game in which you build and maintain factories"; longDescription = '' @@ -112,7 +114,23 @@ let wrapProgram $out/bin/factorio \ --prefix LD_LIBRARY_PATH : /run/opengl-driver/lib:$libPath \ --run "$out/share/factorio/update-config.sh" \ - --add-flags "-c \$HOME/.factorio/config.cfg" + --add-flags "-c \$HOME/.factorio/config.cfg ${optionalString (mods != []) "--mod-directory=${modDir}"}" + + # TODO Currently, every time a mod is changed/added/removed using the + # modlist, a new derivation will take up the entire footprint of the + # client. The only way to avoid this is to remove the mods arg from the + # package function. The modsDir derivation will have to be built + # separately and have the user specify it in the .factorio config or + # right along side it using a symlink into the store I think i will + # just remove mods for the client derivation entirely. this is much + # cleaner and more useful for headless mode. + + # TODO: trying to toggle off a mod will result in read-only-fs-error. + # not much we can do about that except warn the user somewhere. In + # fact, no exit will be clean, since this error will happen on close + # regardless. just prints an ugly stacktrace but seems to be otherwise + # harmless, unless maybe the user forgets and tries to use the mod + # manager. install -m0644 <(cat << EOF ${configBaseCfg} diff --git a/pkgs/games/factorio/utils.nix b/pkgs/games/factorio/utils.nix new file mode 100644 index 000000000000..563ece6cb9c2 --- /dev/null +++ b/pkgs/games/factorio/utils.nix @@ -0,0 +1,49 @@ +# This file provides a top-level function that will be used by both nixpkgs and nixos +# to generate mod directories for use at runtime by factorio. +{ stdenv }: +with stdenv.lib; +{ + mkModDirDrv = mods: # a list of mod derivations + let + recursiveDeps = modDrv: [modDrv] ++ optionals (modDrv.deps == []) (map recursiveDeps modDrv.deps); + modDrvs = unique (flatten (map recursiveDeps mods)); + in + stdenv.mkDerivation { + name = "factorio-mod-directory"; + + preferLocalBuild = true; + buildCommand = '' + mkdir -p $out + for modDrv in ${toString modDrvs}; do + # NB: there will only ever be a single zip file in each mod derivation's output dir + ln -s $modDrv/*.zip $out + done + ''; + }; + + modDrv = { allRecommendedMods, allOptionalMods }: + { src + , name ? null + , deps ? [] + , optionalDeps ? [] + , recommendedDeps ? [] + }: stdenv.mkDerivation { + + inherit src; + + # Use the name of the zip, but endstrip ".zip" and possibly the querystring that gets left in by fetchurl + name = replaceStrings ["_"] ["-"] (if name != null then name else removeSuffix ".zip" (head (splitString "?" src.name))); + + deps = deps ++ optionals allOptionalMods optionalDeps + ++ optionals allRecommendedMods recommendedDeps; + + preferLocalBuild = true; + buildCommand = '' + mkdir -p $out + srcBase=$(basename $src) + srcBase=''${srcBase#*-} # strip nix hash + srcBase=''${srcBase%\?*} # strip querystring leftover from fetchurl + cp $src $out/$srcBase + ''; + }; +} |