1 # This file provides a top-level function that will be used by both nixpkgs and nixos
2 # to generate mod directories for use at runtime by factorio.
17 mkModDirDrv = mods: modsDatFile: # a list of mod derivations
19 recursiveDeps = modDrv: [modDrv] ++ map recursiveDeps modDrv.deps;
20 modDrvs = unique (flatten (map recursiveDeps mods));
23 name = "factorio-mod-directory";
25 preferLocalBuild = true;
28 for modDrv in ${toString modDrvs}; do
29 # NB: there will only ever be a single zip file in each mod derivation's output dir
30 ln -s $modDrv/*.zip $out
32 '' + (optionalString (modsDatFile != null) ''
33 cp ${modsDatFile} $out/mod-settings.dat
37 modDrv = { allRecommendedMods, allOptionalMods }:
42 , recommendedDeps ? []
43 }: stdenv.mkDerivation {
47 # Use the name of the zip, but endstrip ".zip" and possibly the querystring that gets left in by fetchurl
48 name = replaceStrings ["_"] ["-"] (if name != null then name else removeSuffix ".zip" (head (splitString "?" src.name)));
50 deps = deps ++ optionals allOptionalMods optionalDeps
51 ++ optionals allRecommendedMods recommendedDeps;
53 preferLocalBuild = true;
56 srcBase=$(basename $src)
57 srcBase=''${srcBase#*-} # strip nix hash
58 srcBase=''${srcBase%\?*} # strip querystring leftover from fetchurl