summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--customized/factorio.nix148
-rw-r--r--ymir/factorio.nix1
2 files changed, 149 insertions, 0 deletions
diff --git a/customized/factorio.nix b/customized/factorio.nix
new file mode 100644
index 00000000..616c8aae
--- /dev/null
+++ b/customized/factorio.nix
@@ -0,0 +1,148 @@
1{ stdenv, callPackage, fetchurl, makeWrapper
2, alsaLib, libX11, libXcursor, libXinerama, libXrandr, libXi, mesa_noglu
3, factorio-utils
4, releaseType
5, mods ? []
6, username ? "" , password ? ""
7}:
8
9assert releaseType == "alpha" || releaseType == "headless";
10
11with stdenv.lib;
12let
13 version = "0.14.5";
14 isHeadless = releaseType == "headless";
15
16 arch = if stdenv.system == "x86_64-linux" then {
17 inUrl = "linux64";
18 inTar = "x64";
19 } else if stdenv.system == "i686-linux" then {
20 inUrl = "linux32";
21 inTar = "i386";
22 } else abort "Unsupported platform";
23
24 authenticatedFetch = callPackage ./fetch.nix { inherit username password; };
25
26 fetch = rec {
27 url = "https://www.factorio.com/get-download/${version}/${releaseType}/${arch.inUrl}";
28 name = "factorio_${releaseType}_${arch.inTar}-${version}.tar.gz";
29 x64 = {
30 headless = fetchurl { inherit name url; sha256 = "1ip0h2kh16s07nk6xqpm0i0yb0x32zn306414j15gqg3j0j0mzpn"; };
31 alpha = authenticatedFetch { inherit url; sha256 = "1hvj51cggp6cbxyndbl4z07kadzxxk3diiqkkv0jm9s0nrwvq9zr"; };
32 };
33 i386 = {
34 headless = abort "Factorio 32-bit headless binaries are not available for download.";
35 alpha = authenticatedFetch { inherit url; sha256 = "14dwlakn7z8jziy0hgm3nskr7chp7753z1dakxlymz9h5653cx8b"; };
36 };
37 };
38
39 configBaseCfg = ''
40 use-system-read-write-data-directories=false
41 [path]
42 read-data=$out/share/factorio/data/
43 [other]
44 check_updates=false
45 '';
46
47 updateConfigSh = ''
48 #! $SHELL
49 if [[ -e ~/.factorio/config.cfg ]]; then
50 # Config file exists, but may have wrong path.
51 # Try to edit it. I'm sure this is perfectly safe and will never go wrong.
52 sed -i 's|^read-data=.*|read-data=$out/share/factorio/data/|' ~/.factorio/config.cfg
53 else
54 # Config file does not exist. Phew.
55 install -D $out/share/factorio/config-base.cfg ~/.factorio/config.cfg
56 fi
57 '';
58
59 modDir = factorio-utils.mkModDirDrv mods;
60
61 base = {
62 name = "factorio-${releaseType}-${version}";
63
64 src = fetch.${arch.inTar}.${releaseType};
65
66 preferLocalBuild = true;
67 dontBuild = true;
68
69 installPhase = ''
70 mkdir -p $out/{bin,share/factorio}
71 cp -a data $out/share/factorio
72 cp -a bin/${arch.inTar}/factorio $out/bin/factorio
73 patchelf \
74 --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
75 $out/bin/factorio
76 '';
77
78 meta = {
79 description = "A game in which you build and maintain factories";
80 longDescription = ''
81 Factorio is a game in which you build and maintain factories.
82
83 You will be mining resources, researching technologies, building
84 infrastructure, automating production and fighting enemies. Use your
85 imagination to design your factory, combine simple elements into
86 ingenious structures, apply management skills to keep it working and
87 finally protect it from the creatures who don't really like you.
88
89 Factorio has been in development since spring of 2012 and it is
90 currently in late alpha.
91 '';
92 homepage = https://www.factorio.com/;
93 license = stdenv.lib.licenses.unfree;
94 maintainers = with stdenv.lib.maintainers; [ Baughn elitak ];
95 platforms = [ "i686-linux" "x86_64-linux" ];
96 };
97 };
98 headless = base;
99 alpha = base // {
100
101 buildInputs = [ makeWrapper ];
102
103 libPath = stdenv.lib.makeLibraryPath [
104 alsaLib
105 libX11
106 libXcursor
107 libXinerama
108 libXrandr
109 libXi
110 mesa_noglu
111 ];
112
113 installPhase = base.installPhase + ''
114 wrapProgram $out/bin/factorio \
115 --prefix LD_LIBRARY_PATH : /run/opengl-driver/lib:$libPath \
116 --run "$out/share/factorio/update-config.sh" \
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.
134
135 install -m0644 <(cat << EOF
136 ${configBaseCfg}
137 EOF
138 ) $out/share/factorio/config-base.cfg
139
140 install -m0755 <(cat << EOF
141 ${updateConfigSh}
142 EOF
143 ) $out/share/factorio/update-config.sh
144
145 cp -a doc-html $out/share/factorio
146 '';
147 };
148in stdenv.mkDerivation (if isHeadless then headless else alpha)
diff --git a/ymir/factorio.nix b/ymir/factorio.nix
index 3e021e8d..7c67eb66 100644
--- a/ymir/factorio.nix
+++ b/ymir/factorio.nix
@@ -83,5 +83,6 @@ in {
83 83
84 nixpkgs.config.packageOverrides = pkgs: { 84 nixpkgs.config.packageOverrides = pkgs: {
85 factorio-mkModDirDrv = pkgs.factorio-utils.mkModDirDrv; 85 factorio-mkModDirDrv = pkgs.factorio-utils.mkModDirDrv;
86 factorio = pkgs.callPackage ../customized/factorio.nix {};
86 }; 87 };
87} 88}