home-manager: add build command

This will build a configuration into an `result` output directory. Does
not create a new generation.
This commit is contained in:
Robert Helgesson 2017-01-11 22:55:31 +01:00
parent 5cb1ede034
commit 94fd39c41c
No known key found for this signature in database
GPG key ID: C3DB11069E65DC86

View file

@ -1,23 +1,33 @@
#!@bash@/bin/bash #!@bash@/bin/bash
function doRebuild() { function doBuild() {
if [[ -z "$1" ]] ; then if [[ -z "$1" ]]; then
echo "Need to provide path to configuration file." echo "Need to provide path to configuration file."
exit 1 exit 1
fi fi
local confFile if [[ -z "$2" ]]; then
confFile="$(realpath "$1")" echo "Need to provide generation output path."
exit 1
fi
local confFile output
confFile="$(realpath "$1")"
output="$(realpath "$2")"
nix-build --show-trace \
"@HOME_MANAGER_EXPR_PATH@" \
--argstr modulesPath "@MODULES_PATH@" \
--argstr confPath "$confFile" \
-A activation-script \
-o "$output"
}
function doRebuild() {
local wrkdir local wrkdir
wrkdir="$(mktemp -d)" wrkdir="$(mktemp -d)"
if nix-build --show-trace \ if doBuild "$1" "$wrkdir/generation" ; then
"@HOME_MANAGER_EXPR_PATH@" \
--argstr modulesPath "@MODULES_PATH@" \
--argstr confPath "$confFile" \
-A activation-script \
-o "$wrkdir/generation" ; then
"$wrkdir/generation/activate" "$wrkdir/generation/activate"
fi fi
@ -42,16 +52,21 @@ function doListPackages() {
} }
function doHelp() { function doHelp() {
echo "Usage: $0 {help | rebuild CONF | generations | packages}" echo "Usage: $0 {help | build CONF | rebuild CONF"
echo " | generations | packages}"
echo echo
echo "Commands" echo "Commands"
echo " help Print this help" echo " help Print this help"
echo " rebuild Rebuild the current environment" echo " build Build configuration into result directory"
echo " rebuild Build and activate environment"
echo " generations List all home environment generations" echo " generations List all home environment generations"
echo " packages List all packages installed in home-manager-path" echo " packages List all packages installed in home-manager-path"
} }
case "$1" in case "$1" in
build)
doBuild "$2" "result"
;;
rebuild) rebuild)
doRebuild "$2" doRebuild "$2"
;; ;;