git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #17479 from elitak/factorio

Factorio: 0.13.8 -> 0.13.13, mod support

commita741978f200a6627bfcb6325e340db09464a1af9 authorRok Garbas <rok@garbas.si> dateSun 7 Aug 2016, 04:09 (10 years ago) parent17e8ddad76aa6e
5 files changed+331−19
nixos/modules/services/games/factorio.nix+38−10 pkgs/games/factorio/default.nix+27−9 pkgs/games/factorio/mods.nix+213 pkgs/games/factorio/utils.nix+49 pkgs/top-level/all-packages.nix+4
nixos/modules/services/games/factorio.nix+38−10
@@ -4,14 +4,17 @@ with lib;
44
55let
66 cfg = config.services.factorio;
7+ factorio = pkgs.factorio-headless;
78 name = "Factorio";
89 stateDir = "/var/lib/factorio";
10+ mkSavePath = name: "${stateDir}/saves/${name}.zip";
911 configFile = pkgs.writeText "factorio.conf" ''
1012 use-system-read-write-data-directories=true
1113 [path]
12− read-data=${pkgs.factorio-headless}/share/factorio/data
14+ read-data=${factorio}/share/factorio/data
1315 write-data=${stateDir}
1416 '';
17+ modDir = pkgs.factorio-mkModDirDrv cfg.mods;
1518in
1619{
1720 options = {
@@ -32,7 +35,8 @@ in
3235 description = ''
3336 The name of the savegame that will be used by the server.
3437
35− When not present in ${stateDir}/saves, it will be generated before starting the service.
38+ When not present in ${stateDir}/saves, a new map with default
39+ settings will be generated before starting the service.
3640 '';
3741 };
3842 # TODO Add more individual settings as nixos-options?
@@ -51,6 +55,26 @@ in
5155 customizations.
5256 '';
5357 };
58+ mods = mkOption {
59+ type = types.listOf types.package;
60+ default = [];
61+ description = ''
62+ Mods the server should install and activate.
63+
64+ The derivations in this list must "build" the mod by simply copying
65+ the .zip, named correctly, into the output directory. Eventually,
66+ there will be a way to pull in the most up-to-date list of
67+ derivations via nixos-channel. Until then, this is for experts only.
68+ '';
69+ };
70+ autosave-interval = mkOption {
71+ type = types.nullOr types.int;
72+ default = null;
73+ example = 2;
74+ description = ''
75+ The time, in minutes, between autosaves.
76+ '';
77+ };
5478 };
5579 };
5680
@@ -74,12 +98,14 @@ in
7498 wantedBy = [ "multi-user.target" ];
7599 after = [ "network.target" ];
76100
77− preStart = ''
78− test -e ${stateDir}/saves/${cfg.saveName}.zip || \
79− ${pkgs.factorio-headless}/bin/factorio \
80− --config=${cfg.configFile} \
81− --create=${stateDir}/saves/${cfg.saveName}.zip
82− '';
101+ preStart = toString [
102+ "test -e ${stateDir}/saves/${cfg.saveName}.zip"
103+ "||"
104+ "${factorio}/bin/factorio"
105+ "--config=${cfg.configFile}"
106+ "--create=${mkSavePath cfg.saveName}"
107+ (optionalString (cfg.mods != []) "--mod-directory=${modDir}")
108+ ];
83109
84110 serviceConfig = {
85111 User = "factorio";
@@ -90,10 +116,12 @@ in
90116 PrivateTmp = true;
91117 UMask = "0007";
92118 ExecStart = toString [
93− "${pkgs.factorio-headless}/bin/factorio"
119+ "${factorio}/bin/factorio"
94120 "--config=${cfg.configFile}"
95121 "--port=${toString cfg.port}"
96− "--start-server=${stateDir}/saves/${cfg.saveName}.zip"
122+ "--start-server=${mkSavePath cfg.saveName}"
123+ (optionalString (cfg.mods != []) "--mod-directory=${modDir}")
124+ (optionalString (cfg.autosave-interval != null) "--autosave-interval ${toString cfg.autosave-interval}")
97125 ];
98126 };
99127 };
pkgs/games/factorio/default.nix+27−9
@@ -1,6 +1,8 @@
11{ stdenv, callPackage, fetchurl, makeWrapper
22, alsaLib, libX11, libXcursor, libXinerama, libXrandr, libXi, mesa_noglu
3+, factorio-utils
34, releaseType
5+, mods ? []
46, username ? "" , password ? ""
57}:
68
@@ -8,7 +10,7 @@ assert releaseType == "alpha" || releaseType == "headless";
810
911with stdenv.lib;
1012let
11− version = "0.13.8";
13+ version = "0.13.13";
1214 isHeadless = releaseType == "headless";
1315
1416 arch = if stdenv.system == "x86_64-linux" then {
@@ -23,14 +25,14 @@ let
2325
2426 fetch = rec {
2527 url = "https://www.factorio.com/get-download/${version}/${releaseType}/${arch.inUrl}";
26− name = "factorio_${releaseType}_${arch.inTar}-${version}.tar.gz"; # TODO take this from 302 redirection somehow? fetchurl doesn't help.
28+ name = "factorio_${releaseType}_${arch.inTar}-${version}.tar.gz";
2729 x64 = {
28− headless = fetchurl { inherit name url; sha256 = "0dliympqnnawfw65n5gnda9mljyqwshmq2hvplf1h8nrp1rw3pgj"; };
29− alpha = authenticatedFetch { inherit url; sha256 = "12safa8b4g5cpwxbkf8ldkb17lgf33rslr7p81l7gr1lyzfnf82c"; };
30+ headless = fetchurl { inherit name url; sha256 = "1ip0h2kh16s07nk6xqpm0i0yb0x32zn306414j15gqg3j0j0mzpn"; };
31+ alpha = authenticatedFetch { inherit url; sha256 = "1hvj51cggp6cbxyndbl4z07kadzxxk3diiqkkv0jm9s0nrwvq9zr"; };
3032 };
3133 i386 = {
3234 headless = abort "Factorio 32-bit headless binaries are not available for download.";
33− alpha = authenticatedFetch { inherit url; sha256 = "0m4m183avnqxkw28vb7za14dsmcd01sdldgga0br1clilxmgph2w"; };
35+ alpha = authenticatedFetch { inherit url; sha256 = "14dwlakn7z8jziy0hgm3nskr7chp7753z1dakxlymz9h5653cx8b"; };
3436 };
3537 };
3638
@@ -54,14 +56,16 @@ let
5456 fi
5557 '';
5658
59+ modDir = factorio-utils.mkModDirDrv mods;
60+
5761 base = {
5862 name = "factorio-${releaseType}-${version}";
5963
6064 src = fetch.${arch.inTar}.${releaseType};
6165
66+ preferLocalBuild = true;
6267 dontBuild = true;
6368
64− # TODO detangle headless/normal mode wrapping, libs, etc. test all urls 32/64/headless/gfx
6569 installPhase = ''
6670 mkdir -p $out/{bin,share/factorio}
6771 cp -a data $out/share/factorio
@@ -71,8 +75,6 @@ let
7175 $out/bin/factorio
7276 '';
7377
74− preferLocalBuild = true;
75−
7678 meta = {
7779 description = "A game in which you build and maintain factories";
7880 longDescription = ''
@@ -112,7 +114,23 @@ let
112114 wrapProgram $out/bin/factorio \
113115 --prefix LD_LIBRARY_PATH : /run/opengl-driver/lib:$libPath \
114116 --run "$out/share/factorio/update-config.sh" \
115− --add-flags "-c \$HOME/.factorio/config.cfg"
117+ --add-flags "-c \$HOME/.factorio/config.cfg ${optionalString (mods != []) "--mod-directory=${modDir}"}"
118+
119+ # TODO Currently, every time a mod is changed/added/removed using the
120+ # modlist, a new derivation will take up the entire footprint of the
121+ # client. The only way to avoid this is to remove the mods arg from the
122+ # package function. The modsDir derivation will have to be built
123+ # separately and have the user specify it in the .factorio config or
124+ # right along side it using a symlink into the store I think i will
125+ # just remove mods for the client derivation entirely. this is much
126+ # cleaner and more useful for headless mode.
127+
128+ # TODO: trying to toggle off a mod will result in read-only-fs-error.
129+ # not much we can do about that except warn the user somewhere. In
130+ # fact, no exit will be clean, since this error will happen on close
131+ # regardless. just prints an ugly stacktrace but seems to be otherwise
132+ # harmless, unless maybe the user forgets and tries to use the mod
133+ # manager.
116134
117135 install -m0644 <(cat << EOF
118136 ${configBaseCfg}
pkgs/games/factorio/mods.nixnew file+213
@@ -0,0 +1,213 @@
1+# This file is here for demo purposes only, populated with a small sampling of
2+# mods. It will eventually be replaced by a nixos-channel that will provide
3+# derivations for most or all of the mods tracked through the official mod
4+# manager site.
5+{ stdenv, fetchurl
6+, factorio-utils
7+, allRecommendedMods ? true
8+, allOptionalMods ? false
9+}:
10+with stdenv.lib;
11+let
12+ modDrv = factorio-utils.modDrv { inherit allRecommendedMods allOptionalMods; };
13+in
14+rec {
15+
16+ bobassembly = modDrv {
17+ src = fetchurl {
18+ urls = [
19+ https://f.xor.us/factorio-mods/bobassembly_0.13.0.zip
20+ ];
21+ sha256 = "0c0m7sb45r37g882x0aq8mc82yhfh9j9h8g018d4s5pf93vzr6d1";
22+ };
23+ deps = [ boblibrary ];
24+ optionalDeps = [ bobconfig ];
25+ recommendedDeps = [ bobplates ];
26+ };
27+
28+ bobconfig = modDrv {
29+ src = fetchurl {
30+ urls = [
31+ https://f.xor.us/factorio-mods/bobconfig_0.13.1.zip
32+ ];
33+ sha256 = "0z4kmggm1slbr3qiy5xahc9nhdffllp21n9nv5gh1zbzv72sb1rp";
34+ };
35+ };
36+
37+ bobelectronics = modDrv {
38+ src = fetchurl {
39+ urls = [
40+ https://f.xor.us/factorio-mods/bobelectronics_0.13.1.zip
41+ ];
42+ sha256 = "16sn5w33s0ckiwqxx7b2pcsqmhxbxjm2w4h4vd99hwpvdpjyav52";
43+ };
44+ deps = [ boblibrary ];
45+ optionalDeps = [ bobconfig ];
46+ recommendedDeps = [ bobplates ];
47+ };
48+
49+ bobenemies = modDrv {
50+ src = fetchurl {
51+ urls = [
52+ https://f.xor.us/factorio-mods/bobenemies_0.13.1.zip
53+ ];
54+ sha256 = "1wnb5wsvh9aa3i9mj17f36ybbd13qima3iwshw60i6xkzzqfk44d";
55+ };
56+ optionalDeps = [ bobconfig ];
57+ };
58+
59+ bobgreenhouse = modDrv {
60+ src = fetchurl {
61+ urls = [
62+ https://f.xor.us/factorio-mods/bobgreenhouse_0.13.2.zip
63+ ];
64+ sha256 = "1ql26875dvz2lqln289jg1w6yjzsd0x0pqmd570jffwi5m320rrw";
65+ };
66+ deps = [ boblibrary ];
67+ optionalDeps = [ bobconfig ];
68+ recommendedDeps = [ bobplates ];
69+ };
70+
71+ bobinserters = modDrv {
72+ src = fetchurl {
73+ urls = [
74+ https://f.xor.us/factorio-mods/bobinserters_0.13.3.zip
75+ ];
76+ sha256 = "0nys9zhaw0v3w2xzrhawr8g2hcxkzdmyqd4s8xm5bnbrgrq86g9z";
77+ };
78+ deps = [ boblibrary ];
79+ optionalDeps = [ bobconfig ];
80+ recommendedDeps = [ ];
81+ };
82+
83+ boblibrary = modDrv {
84+ src = fetchurl {
85+ urls = [
86+ https://f.xor.us/factorio-mods/boblibrary_0.13.1.zip
87+ ];
88+ sha256 = "04fybs626lzxf0p21jl8kakh2mddah7l9m57srk7a87jw5bj1zx8";
89+ };
90+ };
91+
92+ boblogistics = modDrv {
93+ src = fetchurl {
94+ urls = [
95+ https://f.xor.us/factorio-mods/boblogistics_0.13.7.zip
96+ ];
97+ sha256 = "0c91zmyxwsmyv6vm6gp498vb7flqlcyzkbp9s5q1651hpyd378hx";
98+ };
99+ deps = [ boblibrary ];
100+ optionalDeps = [ bobconfig ];
101+ recommendedDeps = [ bobplates ];
102+ };
103+
104+ bobmining = modDrv {
105+ src = fetchurl {
106+ urls = [
107+ https://f.xor.us/factorio-mods/bobmining_0.13.1.zip
108+ ];
109+ sha256 = "1l7k3v4aizihppgi802fr5b8zbnq2h05c2bbsk5hds239qgxy80m";
110+ };
111+ deps = [ boblibrary ];
112+ optionalDeps = [ bobconfig bobores bobplates ];
113+ };
114+
115+ bobmodules = modDrv {
116+ src = fetchurl {
117+ urls = [
118+ https://f.xor.us/factorio-mods/bobmodules_0.13.0.zip
119+ ];
120+ sha256 = "0ggd2gc4s5sbld7gyncbzdgq8gc00mvxjcfv7i2dchcrdzrlr556";
121+ };
122+ deps = [ boblibrary ];
123+ optionalDeps = [ bobconfig ];
124+ recommendedDeps = [ bobplates bobassembly bobelectronics ];
125+ };
126+
127+ bobores = modDrv {
128+ src = fetchurl {
129+ urls = [
130+ https://f.xor.us/factorio-mods/bobores_0.13.1.zip
131+ ];
132+ sha256 = "1rri70655kj77sdr3zgp56whmcl0gfjmw90jm7lj1jp8l1pdfzb9";
133+ };
134+ deps = [ boblibrary ];
135+ optionalDeps = [ bobconfig ];
136+ };
137+
138+ bobplates = modDrv {
139+ src = fetchurl {
140+ urls = [
141+ https://f.xor.us/factorio-mods/bobplates_0.13.2.zip
142+ ];
143+ sha256 = "0iczpa26hflj17k84p4n6wz0pwhbbrfk86dgac4bfz28kqg58nj1";
144+ };
145+ deps = [ boblibrary ];
146+ optionalDeps = [ bobconfig bobenemies ];
147+ recommendedDeps = [ bobores bobtech ];
148+ };
149+
150+ bobpower = modDrv {
151+ src = fetchurl {
152+ urls = [
153+ https://f.xor.us/factorio-mods/bobpower_0.13.1.zip
154+ ];
155+ sha256 = "18sblnlvprrm2vzlczlki09yj9lr4y64808zrwmcasf7470skar3";
156+ };
157+ deps = [ boblibrary ];
158+ optionalDeps = [ bobconfig ];
159+ recommendedDeps = [ bobplates ];
160+ };
161+
162+ bobrevamp = modDrv {
163+ src = fetchurl {
164+ urls = [
165+ https://f.xor.us/factorio-mods/bobrevamp_0.13.0.zip
166+ ];
167+ sha256 = "0rkyf61clh8fjg72z9i7r4skvdzgd49ky6s0486xxljhbil4nxb7";
168+ };
169+ deps = [ boblibrary ];
170+ };
171+
172+ bobtech = modDrv {
173+ src = fetchurl {
174+ urls = [
175+ https://f.xor.us/factorio-mods/bobtech_0.13.0.zip
176+ ];
177+ sha256 = "0arc9kilxzdpapn3gh5h8269ssgsjxib4ny0qissq2sg95gxlsn0";
178+ };
179+ deps = [ boblibrary ];
180+ optionalDeps = [ bobenemies ];
181+ };
182+
183+ bobtechsave = modDrv {
184+ src = fetchurl {
185+ urls = [
186+ https://f.xor.us/factorio-mods/bobtechsave_0.13.0.zip
187+ ];
188+ sha256 = "1vlv4sgdfd9ldjm8y79n95ms5k6x2i7khjc422lp9080m03v1hcl";
189+ };
190+ };
191+
192+ bobwarfare = modDrv {
193+ src = fetchurl {
194+ urls = [
195+ https://f.xor.us/factorio-mods/bobwarfare_0.13.4.zip
196+ ];
197+ sha256 = "07wzn16i4r0qjm41wfyl17rrhry2vrph08a0kq8w5iy6qcbqqfd3";
198+ };
199+ deps = [ boblibrary ];
200+ optionalDeps = [ boblibrary bobplates ];
201+ recommendedDeps = [ bobtech ];
202+ };
203+
204+ clock = modDrv {
205+ src = fetchurl {
206+ urls = [
207+ https://f.xor.us/factorio-mods/clock_0.13.0.zip
208+ ];
209+ sha256 = "0nflywbj6p2kz2w9wff78vskzljrzaf32ib56k3z456d9y8mlxfd";
210+ };
211+ };
212+
213+}
pkgs/games/factorio/utils.nixnew file+49
@@ -0,0 +1,49 @@
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+{ stdenv }:
4+with stdenv.lib;
5+{
6+ mkModDirDrv = mods: # a list of mod derivations
7+ let
8+ recursiveDeps = modDrv: [modDrv] ++ optionals (modDrv.deps == []) (map recursiveDeps modDrv.deps);
9+ modDrvs = unique (flatten (map recursiveDeps mods));
10+ in
11+ stdenv.mkDerivation {
12+ name = "factorio-mod-directory";
13+
14+ preferLocalBuild = true;
15+ buildCommand = ''
16+ mkdir -p $out
17+ for modDrv in ${toString modDrvs}; do
18+ # NB: there will only ever be a single zip file in each mod derivation's output dir
19+ ln -s $modDrv/*.zip $out
20+ done
21+ '';
22+ };
23+
24+ modDrv = { allRecommendedMods, allOptionalMods }:
25+ { src
26+ , name ? null
27+ , deps ? []
28+ , optionalDeps ? []
29+ , recommendedDeps ? []
30+ }: stdenv.mkDerivation {
31+
32+ inherit src;
33+
34+ # Use the name of the zip, but endstrip ".zip" and possibly the querystring that gets left in by fetchurl
35+ name = replaceStrings ["_"] ["-"] (if name != null then name else removeSuffix ".zip" (head (splitString "?" src.name)));
36+
37+ deps = deps ++ optionals allOptionalMods optionalDeps
38+ ++ optionals allRecommendedMods recommendedDeps;
39+
40+ preferLocalBuild = true;
41+ buildCommand = ''
42+ mkdir -p $out
43+ srcBase=$(basename $src)
44+ srcBase=''${srcBase#*-} # strip nix hash
45+ srcBase=''${srcBase%\?*} # strip querystring leftover from fetchurl
46+ cp $src $out/$srcBase
47+ '';
48+ };
49+}
pkgs/top-level/all-packages.nix+4
@@ -15612,6 +15612,10 @@ in
1561215612
1561315613 factorio-headless = callPackage ../games/factorio { releaseType = "headless"; };
1561415614
15615+ factorio-mods = callPackage ../games/factorio/mods.nix { };
15616+
15617+ factorio-utils = callPackage ../games/factorio/utils.nix { };
15618+
1561515619 fairymax = callPackage ../games/fairymax {};
1561615620
1561715621 fish-fillets-ng = callPackage ../games/fish-fillets-ng {};