Add --file argument for nix-on-droid

This commit is contained in:
Tobias Happ 2020-01-06 01:03:07 +01:00 committed by Alexander Sosedkin
parent 38e7b238ae
commit daf69b959d
3 changed files with 19 additions and 10 deletions

View file

@ -1,26 +1,26 @@
# Licensed under GNU Lesser General Public License v3 or later, see COPYING. # Licensed under GNU Lesser General Public License v3 or later, see COPYING.
# Copyright (c) 2019 Alexander Sosedkin and other contributors, see AUTHORS. # Copyright (c) 2019 Alexander Sosedkin and other contributors, see AUTHORS.
{ pkgs ? import <nixpkgs> { }, initialBuild ? false, config ? { } }: { pkgs ? import <nixpkgs> { }, config ? null }:
with pkgs.lib; with pkgs.lib;
let let
homeDir = builtins.getEnv "HOME"; defaultConfigFile = "${builtins.getEnv "HOME"}/.config/nixpkgs/nix-on-droid.nix";
configFile = homeDir + "/.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 { rawModule = evalModules {
modules = [ modules = [
{ {
_module.args = { inherit pkgs; }; _module.args = { inherit pkgs; };
} }
] configModule
++ optional (!initialBuild && hasConfigFile) configFile ] ++ import ./module-list.nix;
++ optional (!initialBuild && !hasConfigFile && pkgs.config ? nix-on-droid) pkgs.config.nix-on-droid
++ optional initialBuild config
++ import ./module-list.nix;
}; };
failedAssertions = map (x: x.message) (filter (x: !x.assertion) rawModule.config.assertions); failedAssertions = map (x: x.message) (filter (x: !x.assertion) rawModule.config.assertions);

View file

@ -23,6 +23,7 @@ function doHelp() {
echo " -h|--help Print this help" echo " -h|--help Print this help"
echo " -n|--dry-run Do a dry run, only prints what actions would be taken" echo " -n|--dry-run Do a dry run, only prints what actions would be taken"
echo " -v|--verbose Verbose output" echo " -v|--verbose Verbose output"
echo " -f|--file Path to config file"
echo echo
echo "Options passed on to nix build" echo "Options passed on to nix build"
echo echo
@ -52,6 +53,10 @@ function doSwitch() {
PASSTHROUGH_OPTS+=(--show-trace) PASSTHROUGH_OPTS+=(--show-trace)
fi fi
if [[ -n "$CONFIG_FILE" ]]; then
PASSTHROUGH_OPTS+=(--argstr config "$(realpath "$CONFIG_FILE")")
fi
echo "Building activation package..." echo "Building activation package..."
nix build \ nix build \
--no-link \ --no-link \
@ -86,6 +91,7 @@ function doSwitchGeneration() {
COMMAND= COMMAND=
COMMAND_ARGS=() COMMAND_ARGS=()
PASSTHROUGH_OPTS=() PASSTHROUGH_OPTS=()
CONFIG_FILE=
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
opt="$1" opt="$1"
@ -94,6 +100,10 @@ while [[ $# -gt 0 ]]; do
generations|help|rollback|switch|switch-generation) generations|help|rollback|switch|switch-generation)
COMMAND="$opt" COMMAND="$opt"
;; ;;
-f|--file)
CONFIG_FILE="$1"
shift
;;
-h|--help) -h|--help)
doHelp doHelp
exit 0 exit 0

View file

@ -10,7 +10,6 @@ let
modules = import ../modules { modules = import ../modules {
pkgs = nixpkgs; pkgs = nixpkgs;
initialBuild = true;
config = { config = {
imports = [ ../modules/build/initial-build.nix ]; imports = [ ../modules/build/initial-build.nix ];