Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
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. 3{ lib, stdenv }: 4let 5 inherit (lib) 6 flatten 7 head 8 optionals 9 optionalString 10 removeSuffix 11 replaceStrings 12 splitString 13 unique 14 ; 15in 16{ 17 mkModDirDrv = 18 mods: modsDatFile: # a list of mod derivations 19 let 20 recursiveDeps = modDrv: [ modDrv ] ++ map recursiveDeps modDrv.deps; 21 modDrvs = unique (flatten (map recursiveDeps mods)); 22 in 23 stdenv.mkDerivation { 24 name = "factorio-mod-directory"; 25 26 preferLocalBuild = true; 27 buildCommand = '' 28 mkdir -p $out 29 for modDrv in ${toString modDrvs}; do 30 # NB: there will only ever be a single zip file in each mod derivation's output dir 31 ln -s $modDrv/*.zip $out 32 done 33 '' 34 + (optionalString (modsDatFile != null) '' 35 cp ${modsDatFile} $out/mod-settings.dat 36 ''); 37 }; 38 39 modDrv = 40 { allRecommendedMods, allOptionalMods }: 41 { 42 src, 43 name ? null, 44 deps ? [ ], 45 optionalDeps ? [ ], 46 recommendedDeps ? [ ], 47 }: 48 stdenv.mkDerivation { 49 50 inherit src; 51 52 # Use the name of the zip, but endstrip ".zip" and possibly the querystring that gets left in by fetchurl 53 name = replaceStrings [ "_" ] [ "-" ] ( 54 if name != null then name else removeSuffix ".zip" (head (splitString "?" src.name)) 55 ); 56 57 deps = 58 deps ++ optionals allOptionalMods optionalDeps ++ optionals allRecommendedMods recommendedDeps; 59 60 preferLocalBuild = true; 61 buildCommand = '' 62 mkdir -p $out 63 srcBase=$(basename $src) 64 srcBase=''${srcBase#*-} # strip nix hash 65 srcBase=''${srcBase%\?*} # strip querystring leftover from fetchurl 66 cp $src $out/$srcBase 67 ''; 68 }; 69}