about summary refs log tree commit diff
diff options
context:
space:
mode:
authoraszlig <aszlig@redmoonstudios.org>2014-12-31 15:09:04 +0100
committeraszlig <aszlig@redmoonstudios.org>2014-12-31 15:17:16 +0100
commitdab1530b60f41d964fefff210717a50564e52edf (patch)
treec99d3868ad8a10a8dc1d3de2fa5207e373799d36
parentcf44e8ef6c0d6a5c80290d84df55d8e04c5a0eb8 (diff)
humblebundle: Allow config file for email/passwd.
Rather than passing email and password using --argstr to nix-build, we
now read them from a config file in XDG_CONFIG_HOME (or ~/.config if
unset).

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
-rw-r--r--humblebundle/default.nix2
-rw-r--r--humblebundle/fetch-humble-bundle/default.nix30
2 files changed, 28 insertions, 4 deletions
diff --git a/humblebundle/default.nix b/humblebundle/default.nix
index 30d341f3..6e733603 100644
--- a/humblebundle/default.nix
+++ b/humblebundle/default.nix
@@ -1,4 +1,4 @@
-{ email, password }:
+{ email ? null, password ? null }:
 
 with import <nixpkgs> {};
 
diff --git a/humblebundle/fetch-humble-bundle/default.nix b/humblebundle/fetch-humble-bundle/default.nix
index 3ef2cbe6..b5b15bb6 100644
--- a/humblebundle/fetch-humble-bundle/default.nix
+++ b/humblebundle/fetch-humble-bundle/default.nix
@@ -1,5 +1,7 @@
-{ stdenv, curl, cacert, email, password, writeText, fetchFromGitHub
-, python, buildPythonPackage, pythonPackages, fetchpatch
+{ stdenv, curl, cacert, writeText, fetchFromGitHub, fetchpatch
+, python, buildPythonPackage, pythonPackages
+
+, email ? null, password ? null
 }:
 
 { machineName, downloadName ? "Download", suffix ? "humblebundle", md5 }: let
@@ -24,6 +26,28 @@
     propagatedBuildInputs = with pythonPackages; [ requests2 ];
   };
 
+  configFilePath = let
+    xdgConfig = builtins.getEnv "XDG_CONFIG_HOME";
+    fallback = "${builtins.getEnv "HOME"}/.config";
+    basedir = if xdgConfig == "" then fallback else xdgConfig;
+  in "${basedir}/nixgames.nix";
+
+  configFile = if !builtins.pathExists configFilePath then throw ''
+    The config file "${configFilePath}" doesn't exist! Be sure to create it and
+    put your HumbleBundle email address and password in it, like this:
+
+    {
+      humblebundle.email = "fancyuser@example.com";
+      humblebundle.password = "my_super_secret_password";
+    }
+  '' else configFilePath;
+
+  credentials = if email != null && password != null then {
+    inherit email password;
+  } else {
+    inherit ((import configFile).humblebundle) email password;
+  };
+
   getDownloadURL = writeText "gethburl.py" ''
     import sys, humblebundle
 
@@ -53,7 +77,7 @@
           raise SystemExit(1)
 
     hb = humblebundle.HumbleApi()
-    hb.login('${email}', '${password}')
+    hb.login('${credentials.email}', '${credentials.password}')
     products = dict(get_products(hb))
     dstruct = find_download(products)