diff options
author | Gregor Kleen <pngwjpgh@users.noreply.github.com> | 2016-09-13 03:56:49 +0200 |
---|---|---|
committer | Gregor Kleen <pngwjpgh@users.noreply.github.com> | 2016-09-13 03:56:49 +0200 |
commit | b88de6a31fd97816342382080be6db3f503435f1 (patch) | |
tree | 71067de0ca3c2f90e61c26a48e033ada747c6e03 | |
parent | 3fb5091353265436783aa8c1379590652bfb542c (diff) | |
download | nixos-b88de6a31fd97816342382080be6db3f503435f1.tar nixos-b88de6a31fd97816342382080be6db3f503435f1.tar.gz nixos-b88de6a31fd97816342382080be6db3f503435f1.tar.bz2 nixos-b88de6a31fd97816342382080be6db3f503435f1.tar.xz nixos-b88de6a31fd97816342382080be6db3f503435f1.zip |
newer version of factorio
-rw-r--r-- | customized/factorio.nix | 148 | ||||
-rw-r--r-- | ymir/factorio.nix | 2 |
2 files changed, 150 insertions, 0 deletions
diff --git a/customized/factorio.nix b/customized/factorio.nix new file mode 100644 index 00000000..a718c9c7 --- /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 | |||
9 | assert releaseType == "alpha" || releaseType == "headless"; | ||
10 | |||
11 | with stdenv.lib; | ||
12 | let | ||
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 = "153sx7rvh9s5nsq0jyw0mnzqwlvhy4qrs4zqz0639akb2j4kcjvk"; }; | ||
31 | alpha = authenticatedFetch { inherit url; sha256 = null; }; | ||
32 | }; | ||
33 | i386 = { | ||
34 | headless = abort "Factorio 32-bit headless binaries are not available for download."; | ||
35 | alpha = authenticatedFetch { inherit url; sha256 = null; }; | ||
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 | }; | ||
148 | in stdenv.mkDerivation (if isHeadless then headless else alpha) | ||
diff --git a/ymir/factorio.nix b/ymir/factorio.nix index 037b7722..0379c452 100644 --- a/ymir/factorio.nix +++ b/ymir/factorio.nix | |||
@@ -84,5 +84,7 @@ in { | |||
84 | 84 | ||
85 | nixpkgs.config.packageOverrides = pkgs: { | 85 | nixpkgs.config.packageOverrides = pkgs: { |
86 | factorio-mkModDirDrv = pkgs.factorio-utils.mkModDirDrv; | 86 | factorio-mkModDirDrv = pkgs.factorio-utils.mkModDirDrv; |
87 | factorio = pkgs.callPackage ../customized/factorio.nix { releaseType = "alpha"; }; | ||
88 | factorio-headless = pkgs.callPackage ../customized/factorio.nix { releaseType = "headless"; }; | ||
87 | }; | 89 | }; |
88 | } | 90 | } |