2017-01-07 19:16:26 +01:00
|
|
|
#!@bash@/bin/bash
|
|
|
|
|
2017-01-11 22:55:31 +01:00
|
|
|
function doBuild() {
|
|
|
|
if [[ -z "$1" ]]; then
|
2017-01-07 19:16:26 +01:00
|
|
|
echo "Need to provide path to configuration file."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-01-11 22:55:31 +01:00
|
|
|
if [[ -z "$2" ]]; then
|
|
|
|
echo "Need to provide generation output path."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-01-14 13:02:58 +01:00
|
|
|
if [[ -e "$2" ]]; then
|
|
|
|
echo "The output path $2 already exists."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-01-11 22:55:31 +01:00
|
|
|
local confFile output
|
2017-01-08 10:24:16 +01:00
|
|
|
confFile="$(realpath "$1")"
|
2017-01-15 21:07:39 +01:00
|
|
|
|
|
|
|
if [[ $? -ne 0 ]]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-01-11 22:55:31 +01:00
|
|
|
output="$(realpath "$2")"
|
2017-01-08 10:24:16 +01:00
|
|
|
|
2017-01-15 21:07:39 +01:00
|
|
|
if [[ $? -ne 0 ]]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-01-11 22:55:31 +01:00
|
|
|
nix-build --show-trace \
|
|
|
|
"@HOME_MANAGER_EXPR_PATH@" \
|
|
|
|
--argstr modulesPath "@MODULES_PATH@" \
|
|
|
|
--argstr confPath "$confFile" \
|
|
|
|
-A activation-script \
|
|
|
|
-o "$output"
|
|
|
|
}
|
|
|
|
|
2017-01-11 22:58:55 +01:00
|
|
|
function doSwitch() {
|
2017-01-07 19:16:26 +01:00
|
|
|
local wrkdir
|
|
|
|
wrkdir="$(mktemp -d)"
|
|
|
|
|
2017-01-11 22:55:31 +01:00
|
|
|
if doBuild "$1" "$wrkdir/generation" ; then
|
2017-01-11 00:36:05 +01:00
|
|
|
"$wrkdir/generation/activate"
|
|
|
|
fi
|
2017-01-07 19:16:26 +01:00
|
|
|
|
2017-01-08 22:06:53 +01:00
|
|
|
rm -r "$wrkdir"
|
2017-01-07 19:16:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function doListGens() {
|
2017-01-08 22:06:53 +01:00
|
|
|
pushd "/nix/var/nix/profiles/per-user/$USER" > /dev/null
|
|
|
|
ls --color=yes -gG --sort time home-manager-*-link \
|
2017-01-07 19:16:26 +01:00
|
|
|
| cut -d' ' -f 4-
|
2017-01-08 22:06:53 +01:00
|
|
|
popd > /dev/null
|
2017-01-07 19:16:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function doListPackages() {
|
|
|
|
local outPath
|
|
|
|
outPath="$(nix-env -q --out-path | grep -o '/.*home-manager-path$')"
|
2017-01-07 19:36:39 +01:00
|
|
|
if [[ -n "$outPath" ]] ; then
|
|
|
|
nix-store -q --references "$outPath" | sed 's/[^-]*-//'
|
|
|
|
else
|
|
|
|
echo "No home-manager packages seem to be installed."
|
|
|
|
fi
|
2017-01-07 19:16:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function doHelp() {
|
2017-01-12 22:26:24 +01:00
|
|
|
echo "Usage: $0 COMMAND"
|
2017-01-07 19:16:26 +01:00
|
|
|
echo
|
|
|
|
echo "Commands"
|
2017-01-12 22:26:24 +01:00
|
|
|
echo " help Print this help"
|
|
|
|
echo " build CONF Build configuration into result directory"
|
|
|
|
echo " switch CONF Build and activate configuration"
|
|
|
|
echo " generations List all home environment generations"
|
|
|
|
echo " packages List all packages installed in home-manager-path"
|
2017-01-07 19:16:26 +01:00
|
|
|
}
|
|
|
|
|
2017-01-08 22:08:17 +01:00
|
|
|
case "$1" in
|
2017-01-11 22:55:31 +01:00
|
|
|
build)
|
|
|
|
doBuild "$2" "result"
|
|
|
|
;;
|
2017-01-11 22:58:55 +01:00
|
|
|
switch)
|
|
|
|
doSwitch "$2"
|
2017-01-07 19:16:26 +01:00
|
|
|
;;
|
|
|
|
generations)
|
|
|
|
doListGens
|
|
|
|
;;
|
|
|
|
packages)
|
|
|
|
doListPackages
|
|
|
|
;;
|
|
|
|
help|--help)
|
|
|
|
doHelp
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unknown command: $1"
|
|
|
|
doHelp
|
|
|
|
exit 1
|
2017-01-08 22:08:17 +01:00
|
|
|
;;
|
2017-01-07 19:16:26 +01:00
|
|
|
esac
|