summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregor Kleen <pngwjpgh@users.noreply.github.com>2016-09-13 04:45:37 +0200
committerGregor Kleen <pngwjpgh@users.noreply.github.com>2016-09-13 04:45:37 +0200
commit7f0f97c06245b21a51210054e25fceab4b577cea (patch)
tree71d2b033d348f6741d417d1a3578c3b98b3c6925
parent7b7ef4e9ba4d3c77bd874f4851f5165c06a27a5a (diff)
downloadnixos-7f0f97c06245b21a51210054e25fceab4b577cea.tar
nixos-7f0f97c06245b21a51210054e25fceab4b577cea.tar.gz
nixos-7f0f97c06245b21a51210054e25fceab4b577cea.tar.bz2
nixos-7f0f97c06245b21a51210054e25fceab4b577cea.tar.xz
nixos-7f0f97c06245b21a51210054e25fceab4b577cea.zip
simplify factorio again
-rw-r--r--.gitignore3
-rw-r--r--customized/factorio-fetch.nix32
-rw-r--r--customized/factorio.nix147
-rw-r--r--customized/fetch.sh55
-rw-r--r--ymir/factorio.nix17
5 files changed, 10 insertions, 244 deletions
diff --git a/.gitignore b/.gitignore
index 15eafda5..3b10a887 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,3 @@
1configuration.nix 1configuration.nix
2config.nix 2config.nix
3**/\#*\# 3**/\#*\# \ No newline at end of file
4factorio-credentials.nix \ No newline at end of file
diff --git a/customized/factorio-fetch.nix b/customized/factorio-fetch.nix
deleted file mode 100644
index 4b9b9995..00000000
--- a/customized/factorio-fetch.nix
+++ /dev/null
@@ -1,32 +0,0 @@
1{ stdenv, curl, xidel, cacert
2# Begin download parameters
3, username ? ""
4, password ? ""
5}:
6
7{
8 # URL to fetch.
9 url ? ""
10
11 # Login URL.
12, loginUrl ? "https://www.factorio.com/login"
13
14 # SHA256 of the fetched URL.
15, sha256 ? ""
16, name
17}:
18
19stdenv.mkDerivation {
20 buildInputs = [ curl xidel ];
21
22 inherit name url loginUrl username password cacert;
23
24 builder = ./fetch.sh;
25
26 outputHashAlgo = "sha256";
27 outputHash = sha256;
28 outputHashMode = "flat";
29
30 # There's no point in downloading remotely, we'd just slow things down.
31 preferLocalBuild = true;
32}
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
8assert releaseType == "alpha" || releaseType == "headless";
9
10with stdenv.lib;
11let
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 };
147in stdenv.mkDerivation (if isHeadless then headless else alpha)
diff --git a/customized/fetch.sh b/customized/fetch.sh
deleted file mode 100644
index 8ea615a1..00000000
--- a/customized/fetch.sh
+++ /dev/null
@@ -1,55 +0,0 @@
1source $stdenv/setup
2
3# Curl flags to increase reliability a bit.
4#
5# Can't use fetchurl, for several reasons. One is that we definitely
6# don't want --insecure for the login, though we need it for the
7# download as their download cert isn't in the standard linux bundle.
8curl="curl \
9 --max-redirs 20 \
10 --retry 3 \
11 --cacert $cacert/etc/ssl/certs/ca-bundle.crt \
12 -b cookies \
13 -c cookies \
14 $curlOpts \
15 $NIX_CURL_FLAGS"
16
17# We don't want the password to be on any program's argv, as it may be
18# visible in /proc. Writing it to file with echo should be safe, since
19# it's a shell builtin.
20echo -n "$password" > password
21# Might as well hide the username as well.
22echo -n "$username" > username
23
24# Get a CSRF token.
25csrf=$($curl $loginUrl | xidel - -e '//input[@id="csrf_token"]/@value')
26
27# Log in. We don't especially care about the result, but let's check if login failed.
28$curl --data-urlencode csrf_token="$csrf" \
29 --data-urlencode username@username \
30 --data-urlencode password@password \
31 -d action=Login \
32 $loginUrl -D headers > /dev/null
33
34if grep -q 'Location: https://' headers; then
35 # Now download. We need --insecure for this, but the sha256 should cover us.
36 $curl --insecure --location $url > $out
37 set +x
38else
39 set +x
40 echo "Login failed (username: ‘$username’)"
41 echo 'Please set username and password with config.nix,'
42 echo 'or /etc/nix/nixpkgs-config.nix if on NixOS.'
43 echo
44 echo 'Example:'
45 echo '{'
46 echo ' packageOverrides = pkgs: rec {'
47 echo ' factorio = pkgs.factorio.override {'
48 echo ' username = "<username or email address>";'
49 echo ' password = "<password>";'
50 echo ' };'
51 echo ' };'
52 echo '}'
53
54 exit 1
55fi
diff --git a/ymir/factorio.nix b/ymir/factorio.nix
index 6c0dc246..a7bac033 100644
--- a/ymir/factorio.nix
+++ b/ymir/factorio.nix
@@ -6,10 +6,15 @@ let
6 allOptionalMods = false; 6 allOptionalMods = false;
7 }; 7 };
8 modPortalDrv = { id, name, version, sha256, deps ? [], optionalDeps ? [], recommendedDeps ? [] }: modDrv { 8 modPortalDrv = { id, name, version, sha256, deps ? [], optionalDeps ? [], recommendedDeps ? [] }: modDrv {
9 src = pkgs.factorio-fetch { 9 # src = pkgs.factorio-fetch {
10 name = ''${name}_${version}.zip''; 10 # name = ''${name}_${version}.zip'';
11 url = ''https://mods.factorio.com/api/downloads/data/mods/${id}_${version}.zip''; 11 # url = ''https://mods.factorio.com/api/downloads/data/mods/${id}_${version}.zip'';
12 inherit sha256; 12 # inherit sha256;
13 # loginUrl = "";
14 # };
15 src = pkgs.fetchurl {
16 url = ''https://f.141.li/${name}_${version}.zip'';
17 inherit name sha256;
13 }; 18 };
14 inherit deps optionalDeps recommendedDeps; 19 inherit deps optionalDeps recommendedDeps;
15 }; 20 };
@@ -65,8 +70,6 @@ let
65 }; 70 };
66 }; 71 };
67in { 72in {
68 imports = [ ../factorio-credentials.nix ];
69
70 services.factorio = { 73 services.factorio = {
71 enable = true; 74 enable = true;
72 saveName = config.networking.hostName; 75 saveName = config.networking.hostName;
@@ -87,7 +90,5 @@ in {
87 90
88 nixpkgs.config.packageOverrides = pkgs: { 91 nixpkgs.config.packageOverrides = pkgs: {
89 factorio-mkModDirDrv = pkgs.factorio-utils.mkModDirDrv; 92 factorio-mkModDirDrv = pkgs.factorio-utils.mkModDirDrv;
90 factorio = pkgs.callPackage ../customized/factorio.nix { releaseType = "alpha"; };
91 factorio-headless = pkgs.callPackage ../customized/factorio.nix { releaseType = "headless"; };
92 }; 93 };
93} 94}