2.home-manager/home-manager/home-manager
Robert Helgesson 94fd39c41c
home-manager: add build command
This will build a configuration into an `result` output directory. Does
not create a new generation.
2017-01-15 23:42:46 +01:00

87 lines
2 KiB
Bash

#!@bash@/bin/bash
function doBuild() {
if [[ -z "$1" ]]; then
echo "Need to provide path to configuration file."
exit 1
fi
if [[ -z "$2" ]]; then
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
wrkdir="$(mktemp -d)"
if doBuild "$1" "$wrkdir/generation" ; then
"$wrkdir/generation/activate"
fi
rm -r "$wrkdir"
}
function doListGens() {
pushd "/nix/var/nix/profiles/per-user/$USER" > /dev/null
ls --color=yes -gG --sort time home-manager-*-link \
| cut -d' ' -f 4-
popd > /dev/null
}
function doListPackages() {
local outPath
outPath="$(nix-env -q --out-path | grep -o '/.*home-manager-path$')"
if [[ -n "$outPath" ]] ; then
nix-store -q --references "$outPath" | sed 's/[^-]*-//'
else
echo "No home-manager packages seem to be installed."
fi
}
function doHelp() {
echo "Usage: $0 {help | build CONF | rebuild CONF"
echo " | generations | packages}"
echo
echo "Commands"
echo " help Print this help"
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"
;;
generations)
doListGens
;;
packages)
doListPackages
;;
help|--help)
doHelp
;;
*)
echo "Unknown command: $1"
doHelp
exit 1
;;
esac