diff options
author | aszlig <aszlig@redmoonstudios.org> | 2015-04-17 12:31:27 +0200 |
---|---|---|
committer | aszlig <aszlig@redmoonstudios.org> | 2015-04-17 12:31:27 +0200 |
commit | 62d2888f937bbea915463da55db520710fb5e3fb (patch) | |
tree | 836f882c8b9cbcfb3d98ded0cdbe22976ede0d93 | |
parent | 4d3aa52331a080fa9d8bb2fa915ca4294ac09d22 (diff) |
Use the NixOS module system for configuration.
Let's use the module system to allow specifying things such as HumbleBundle or Steam or $whatnot's usernames and passwords, so we can not only typecheck these options but also modularize it before this whole repository is beginning to get very messy. Right now, if you use the default.nix without a configuration, you'll still get message saying that you may want to supply HumbleBundle credentials, even though it's no longer only about HumbleBundle anymore. Nevertheless, the only tree existing right now is the HumbleBundle one, so never mind about that :-) Signed-off-by: aszlig <aszlig@redmoonstudios.org>
-rw-r--r-- | base-module.nix | 15 | ||||
-rw-r--r-- | default.nix | 25 | ||||
-rw-r--r-- | humblebundle/default.nix | 32 | ||||
-rw-r--r-- | humblebundle/fetch-humble-bundle/default.nix | 26 |
4 files changed, 69 insertions, 29 deletions
diff --git a/base-module.nix b/base-module.nix new file mode 100644 index 00000000..08855379 --- /dev/null +++ b/base-module.nix @@ -0,0 +1,15 @@ +{ lib, ... }: + +with lib; + +{ + options = { + packages = mkOption { + type = types.attrsOf types.unspecified; + default = {}; + description = "Available NixGames packages."; + }; + }; + + config._module.args.pkgs = import <nixpkgs> {}; +} diff --git a/default.nix b/default.nix new file mode 100644 index 00000000..80420a8b --- /dev/null +++ b/default.nix @@ -0,0 +1,25 @@ +{ configuration ? null }: + +let + 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; + +in ((import <nixpkgs/lib>).evalModules { + modules = [ + (if configuration == null then configFilePath else configuration) + ./base-module.nix ./humblebundle + ]; +}).config.packages diff --git a/humblebundle/default.nix b/humblebundle/default.nix index 6e733603..953f3481 100644 --- a/humblebundle/default.nix +++ b/humblebundle/default.nix @@ -1,13 +1,13 @@ -{ email ? null, password ? null }: - -with import <nixpkgs> {}; +{ config, lib, pkgs, ... }: let + cfg = config.humblebundle; + self = rec { callPackage = pkgs.lib.callPackageWith (pkgs // self); fetchHumbleBundle = callPackage ./fetch-humble-bundle { - inherit email password; + inherit (config.humblebundle) email password; }; bastion = callPackage ./bastion.nix {}; @@ -21,4 +21,26 @@ let spaz = callPackage ./spaz.nix {}; swordsandsoldiers = callPackage ./swordsandsoldiers.nix {}; }; -in self +in with lib; { + options.humblebundle = { + email = mkOption { + type = types.nullOr types.str; + default = null; + description = '' + Email address for your HumbleBundle account. + ''; + }; + + password = mkOption { + type = types.nullOr types.str; + default = null; + description = '' + Password for your HumbleBundle account. + ''; + }; + }; + + config.packages = { + humblebundle = mkIf (cfg.email != null && cfg.password != null) self; + }; +} diff --git a/humblebundle/fetch-humble-bundle/default.nix b/humblebundle/fetch-humble-bundle/default.nix index b045d689..fb29cae6 100644 --- a/humblebundle/fetch-humble-bundle/default.nix +++ b/humblebundle/fetch-humble-bundle/default.nix @@ -1,7 +1,7 @@ { stdenv, curl, cacert, writeText, fetchFromGitHub, fetchpatch , python, buildPythonPackage, pythonPackages -, email ? null, password ? null +, email, password }: { machineName, downloadName ? "Download", suffix ? "humblebundle", md5 }: let @@ -21,28 +21,6 @@ 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 @@ -72,7 +50,7 @@ raise SystemExit(1) hb = humblebundle.HumbleApi() - hb.login('${credentials.email}', '${credentials.password}') + hb.login('${email}', '${password}') products = dict(get_products(hb)) dstruct = find_download(products) |