depot/third_party/nixpkgs/patches/pr104732-factorio-fail-early-without-creds.patch

42 lines
1.8 KiB
Diff

From 86aa2a57d3a60d68af8689c4a1eb4da306f90c98 Mon Sep 17 00:00:00 2001
From: Luke Granger-Brown <git@lukegb.com>
Date: Tue, 24 Nov 2020 01:27:34 +0000
Subject: [PATCH] factorio: fail fetch early if no credentials provided
The download URL will redirect to the login page if credentials are not
present, but will return an error if the credentials are wrong.
Since we know we always expect credentials, we can fail the fetch in
the preHook if they're not provided.
We can't use e.g. builtins.throw because we want the fetchurl derivation
to be evaluated in all cases - because that's the mechanism which allows
you to just manually add the tarball to the Nix store.
---
pkgs/games/factorio/default.nix | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/pkgs/games/factorio/default.nix b/pkgs/games/factorio/default.nix
index 0226acf160460..e5527c9d4ef70 100644
--- a/pkgs/games/factorio/default.nix
+++ b/pkgs/games/factorio/default.nix
@@ -104,10 +104,15 @@ let
];
})
(_: { # This preHook hides the credentials from /proc
- preHook = ''
- echo -n "${username}" >username
- echo -n "${token}" >token
- '';
+ preHook =
+ if username != "" && token != "" then ''
+ echo -n "${username}" >username
+ echo -n "${token}" >token
+ '' else ''
+ # Deliberately failing since username/token was not provided, so we can't fetch.
+ # We can't use builtins.throw since we want the result to be used if the tar is in the store already.
+ exit 1
+ '';
failureHook = ''
cat <<EOF
${helpMsg}