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
function doRebuild() {
function doBuild() {
if [[ -z "$1" ]]; then
echo "Need to provide path to configuration file."
exit 1
fi
local confFile
if [[ -z "$2" ]]; then
echo "Need to provide generation output path."
exit 1
fi
local confFile output
confFile="$(realpath "$1")"
output="$(realpath "$2")"
local wrkdir
wrkdir="$(mktemp -d)"
if nix-build --show-trace \
nix-build --show-trace \
"@HOME_MANAGER_EXPR_PATH@" \
--argstr modulesPath "@MODULES_PATH@" \
--argstr confPath "$confFile" \
-A activation-script \
-o "$wrkdir/generation" ; then
-o "$output"
}
function doRebuild() {
local wrkdir
wrkdir="$(mktemp -d)"
if doBuild "$1" "$wrkdir/generation" ; then
"$wrkdir/generation/activate"
fi
@ -42,16 +52,21 @@ function doListPackages() {
}
function doHelp() {
echo "Usage: $0 {help | rebuild CONF | generations | packages}"
echo "Usage: $0 {help | build CONF | rebuild CONF"
echo " | generations | packages}"
echo
echo "Commands"
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 " packages List all packages installed in home-manager-path"
}
case "$1" in
build)
doBuild "$2" "result"
;;
rebuild)
doRebuild "$2"
;;