1
0
mirror of https://github.com/nix-community/home-manager synced 2024-06-23 15:08:31 +02:00
home-manager/home-manager/home-manager

101 lines
2.1 KiB
Plaintext
Raw Normal View History

2017-01-07 19:16:26 +01:00
#!@bash@/bin/bash
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
if [[ -z "$2" ]]; then
echo "Need to provide generation output path."
exit 1
fi
if [[ -e "$2" ]]; then
echo "The output path $2 already exists."
exit 1
fi
local confFile output
confFile="$(realpath "$1")"
if [[ $? -ne 0 ]]; then
exit 1
fi
output="$(realpath "$2")"
if [[ $? -ne 0 ]]; then
exit 1
fi
nix-build --show-trace \
"@HOME_MANAGER_EXPR_PATH@" \
--argstr modulesPath "@MODULES_PATH@" \
--argstr confPath "$confFile" \
-A activation-script \
-o "$output"
}
function doSwitch() {
2017-01-07 19:16:26 +01:00
local wrkdir
wrkdir="$(mktemp -d)"
if doBuild "$1" "$wrkdir/generation" ; then
"$wrkdir/generation/activate"
fi
2017-01-07 19:16:26 +01:00
rm -r "$wrkdir"
2017-01-07 19:16:26 +01:00
}
function doListGens() {
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-
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$')"
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
build)
doBuild "$2" "result"
;;
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