Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s
70 lines
1.8 KiB
Nix
70 lines
1.8 KiB
Nix
# 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.
|
|
{ lib, stdenv }:
|
|
let
|
|
inherit (lib)
|
|
flatten
|
|
head
|
|
optionals
|
|
optionalString
|
|
removeSuffix
|
|
replaceStrings
|
|
splitString
|
|
unique
|
|
;
|
|
in
|
|
{
|
|
mkModDirDrv =
|
|
mods: modsDatFile: # a list of mod derivations
|
|
let
|
|
recursiveDeps = modDrv: [ modDrv ] ++ 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
|
|
''
|
|
+ (optionalString (modsDatFile != null) ''
|
|
cp ${modsDatFile} $out/mod-settings.dat
|
|
'');
|
|
};
|
|
|
|
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
|
|
'';
|
|
};
|
|
}
|