diff options
Diffstat (limited to 'customized/factorio.nix')
-rw-r--r-- | customized/factorio.nix | 147 |
1 files changed, 0 insertions, 147 deletions
diff --git a/customized/factorio.nix b/customized/factorio.nix deleted file mode 100644 index bab0d3d2..00000000 --- a/customized/factorio.nix +++ /dev/null | |||
@@ -1,147 +0,0 @@ | |||
1 | { stdenv, callPackage, fetchurl, makeWrapper | ||
2 | , alsaLib, libX11, libXcursor, libXinerama, libXrandr, libXi, mesa_noglu | ||
3 | , factorio-utils, factorio-fetch | ||
4 | , releaseType | ||
5 | , mods ? [] | ||
6 | }: | ||
7 | |||
8 | assert releaseType == "alpha" || releaseType == "headless"; | ||
9 | |||
10 | with stdenv.lib; | ||
11 | let | ||
12 | version = "0.14.5"; | ||
13 | isHeadless = releaseType == "headless"; | ||
14 | |||
15 | arch = if stdenv.system == "x86_64-linux" then { | ||
16 | inUrl = "linux64"; | ||
17 | inTar = "x64"; | ||
18 | } else if stdenv.system == "i686-linux" then { | ||
19 | inUrl = "linux32"; | ||
20 | inTar = "i386"; | ||
21 | } else abort "Unsupported platform"; | ||
22 | |||
23 | authenticatedFetch = factorio-fetch; | ||
24 | |||
25 | fetch = rec { | ||
26 | url = "https://www.factorio.com/get-download/${version}/${releaseType}/${arch.inUrl}"; | ||
27 | name = "factorio_${releaseType}_${arch.inTar}-${version}.tar.gz"; | ||
28 | x64 = { | ||
29 | headless = fetchurl { inherit name url; sha256 = "153sx7rvh9s5nsq0jyw0mnzqwlvhy4qrs4zqz0639akb2j4kcjvk"; }; | ||
30 | alpha = authenticatedFetch { inherit name url; sha256 = null; }; | ||
31 | }; | ||
32 | i386 = { | ||
33 | headless = abort "Factorio 32-bit headless binaries are not available for download."; | ||
34 | alpha = authenticatedFetch { inherit name url; sha256 = null; }; | ||
35 | }; | ||
36 | }; | ||
37 | |||
38 | configBaseCfg = '' | ||
39 | use-system-read-write-data-directories=false | ||
40 | [path] | ||
41 | read-data=$out/share/factorio/data/ | ||
42 | [other] | ||
43 | check_updates=false | ||
44 | ''; | ||
45 | |||
46 | updateConfigSh = '' | ||
47 | #! $SHELL | ||
48 | if [[ -e ~/.factorio/config.cfg ]]; then | ||
49 | # Config file exists, but may have wrong path. | ||
50 | # Try to edit it. I'm sure this is perfectly safe and will never go wrong. | ||
51 | sed -i 's|^read-data=.*|read-data=$out/share/factorio/data/|' ~/.factorio/config.cfg | ||
52 | else | ||
53 | # Config file does not exist. Phew. | ||
54 | install -D $out/share/factorio/config-base.cfg ~/.factorio/config.cfg | ||
55 | fi | ||
56 | ''; | ||
57 | |||
58 | modDir = factorio-utils.mkModDirDrv mods; | ||
59 | |||
60 | base = { | ||
61 | name = "factorio-${releaseType}-${version}"; | ||
62 | |||
63 | src = fetch.${arch.inTar}.${releaseType}; | ||
64 | |||
65 | preferLocalBuild = true; | ||
66 | dontBuild = true; | ||
67 | |||
68 | installPhase = '' | ||
69 | mkdir -p $out/{bin,share/factorio} | ||
70 | cp -a data $out/share/factorio | ||
71 | cp -a bin/${arch.inTar}/factorio $out/bin/factorio | ||
72 | patchelf \ | ||
73 | --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \ | ||
74 | $out/bin/factorio | ||
75 | ''; | ||
76 | |||
77 | meta = { | ||
78 | description = "A game in which you build and maintain factories"; | ||
79 | longDescription = '' | ||
80 | Factorio is a game in which you build and maintain factories. | ||
81 | |||
82 | You will be mining resources, researching technologies, building | ||
83 | infrastructure, automating production and fighting enemies. Use your | ||
84 | imagination to design your factory, combine simple elements into | ||
85 | ingenious structures, apply management skills to keep it working and | ||
86 | finally protect it from the creatures who don't really like you. | ||
87 | |||
88 | Factorio has been in development since spring of 2012 and it is | ||
89 | currently in late alpha. | ||
90 | ''; | ||
91 | homepage = https://www.factorio.com/; | ||
92 | license = stdenv.lib.licenses.unfree; | ||
93 | maintainers = with stdenv.lib.maintainers; [ Baughn elitak ]; | ||
94 | platforms = [ "i686-linux" "x86_64-linux" ]; | ||
95 | }; | ||
96 | }; | ||
97 | headless = base; | ||
98 | alpha = base // { | ||
99 | |||
100 | buildInputs = [ makeWrapper ]; | ||
101 | |||
102 | libPath = stdenv.lib.makeLibraryPath [ | ||
103 | alsaLib | ||
104 | libX11 | ||
105 | libXcursor | ||
106 | libXinerama | ||
107 | libXrandr | ||
108 | libXi | ||
109 | mesa_noglu | ||
110 | ]; | ||
111 | |||
112 | installPhase = base.installPhase + '' | ||
113 | wrapProgram $out/bin/factorio \ | ||
114 | --prefix LD_LIBRARY_PATH : /run/opengl-driver/lib:$libPath \ | ||
115 | --run "$out/share/factorio/update-config.sh" \ | ||
116 | --add-flags "-c \$HOME/.factorio/config.cfg ${optionalString (mods != []) "--mod-directory=${modDir}"}" | ||
117 | |||
118 | # TODO Currently, every time a mod is changed/added/removed using the | ||
119 | # modlist, a new derivation will take up the entire footprint of the | ||
120 | # client. The only way to avoid this is to remove the mods arg from the | ||
121 | # package function. The modsDir derivation will have to be built | ||
122 | # separately and have the user specify it in the .factorio config or | ||
123 | # right along side it using a symlink into the store I think i will | ||
124 | # just remove mods for the client derivation entirely. this is much | ||
125 | # cleaner and more useful for headless mode. | ||
126 | |||
127 | # TODO: trying to toggle off a mod will result in read-only-fs-error. | ||
128 | # not much we can do about that except warn the user somewhere. In | ||
129 | # fact, no exit will be clean, since this error will happen on close | ||
130 | # regardless. just prints an ugly stacktrace but seems to be otherwise | ||
131 | # harmless, unless maybe the user forgets and tries to use the mod | ||
132 | # manager. | ||
133 | |||
134 | install -m0644 <(cat << EOF | ||
135 | ${configBaseCfg} | ||
136 | EOF | ||
137 | ) $out/share/factorio/config-base.cfg | ||
138 | |||
139 | install -m0755 <(cat << EOF | ||
140 | ${updateConfigSh} | ||
141 | EOF | ||
142 | ) $out/share/factorio/update-config.sh | ||
143 | |||
144 | cp -a doc-html $out/share/factorio | ||
145 | ''; | ||
146 | }; | ||
147 | in stdenv.mkDerivation (if isHeadless then headless else alpha) | ||