diff --git a/modules/default.nix b/modules/default.nix index f6a3ee5..b921445 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -1,26 +1,26 @@ # Licensed under GNU Lesser General Public License v3 or later, see COPYING. # Copyright (c) 2019 Alexander Sosedkin and other contributors, see AUTHORS. -{ pkgs ? import { }, initialBuild ? false, config ? { } }: +{ pkgs ? import { }, config ? null }: with pkgs.lib; let - homeDir = builtins.getEnv "HOME"; - configFile = homeDir + "/.config/nixpkgs/nix-on-droid.nix"; + defaultConfigFile = "${builtins.getEnv "HOME"}/.config/nixpkgs/nix-on-droid.nix"; - hasConfigFile = builtins.pathExists configFile; + configModule = + if config != null then config + else if builtins.pathExists defaultConfigFile then defaultConfigFile + else if pkgs.config ? nix-on-droid then pkgs.config.nix-on-droid + else throw "No config file found! Create one in ~/.config/nixpkgs/nix-on-droid.nix"; rawModule = evalModules { modules = [ { _module.args = { inherit pkgs; }; } - ] - ++ optional (!initialBuild && hasConfigFile) configFile - ++ optional (!initialBuild && !hasConfigFile && pkgs.config ? nix-on-droid) pkgs.config.nix-on-droid - ++ optional initialBuild config - ++ import ./module-list.nix; + configModule + ] ++ import ./module-list.nix; }; failedAssertions = map (x: x.message) (filter (x: !x.assertion) rawModule.config.assertions); diff --git a/nix-on-droid/nix-on-droid.sh b/nix-on-droid/nix-on-droid.sh index 784ec6a..9cef2cb 100644 --- a/nix-on-droid/nix-on-droid.sh +++ b/nix-on-droid/nix-on-droid.sh @@ -23,6 +23,7 @@ function doHelp() { echo " -h|--help Print this help" echo " -n|--dry-run Do a dry run, only prints what actions would be taken" echo " -v|--verbose Verbose output" + echo " -f|--file Path to config file" echo echo "Options passed on to nix build" echo @@ -52,6 +53,10 @@ function doSwitch() { PASSTHROUGH_OPTS+=(--show-trace) fi + if [[ -n "$CONFIG_FILE" ]]; then + PASSTHROUGH_OPTS+=(--argstr config "$(realpath "$CONFIG_FILE")") + fi + echo "Building activation package..." nix build \ --no-link \ @@ -86,6 +91,7 @@ function doSwitchGeneration() { COMMAND= COMMAND_ARGS=() PASSTHROUGH_OPTS=() +CONFIG_FILE= while [[ $# -gt 0 ]]; do opt="$1" @@ -94,6 +100,10 @@ while [[ $# -gt 0 ]]; do generations|help|rollback|switch|switch-generation) COMMAND="$opt" ;; + -f|--file) + CONFIG_FILE="$1" + shift + ;; -h|--help) doHelp exit 0 diff --git a/pkgs/default.nix b/pkgs/default.nix index d6bd45a..b8f70af 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -10,7 +10,6 @@ let modules = import ../modules { pkgs = nixpkgs; - initialBuild = true; config = { imports = [ ../modules/build/initial-build.nix ];