1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-09-27 16:57:29 +02:00

home-manager: add support for the nix tool

This adds an experimantal, undocumented, and unsupported flag `-2` for
the `home-manager` command that enables the use of the new `nix`
command instead of `nix-build`.
This commit is contained in:
Robert Helgesson 2018-06-13 21:00:26 +02:00
parent e365943a70
commit dadfaed829
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89

View file

@ -58,6 +58,8 @@ function doBuildAttr() {
setConfigFile setConfigFile
setHomeManagerNixPath setHomeManagerNixPath
local subCommand="$1"
shift
local extraArgs="$*" local extraArgs="$*"
for p in "${EXTRA_NIX_PATH[@]}"; do for p in "${EXTRA_NIX_PATH[@]}"; do
@ -69,11 +71,25 @@ function doBuildAttr() {
fi fi
# shellcheck disable=2086 # shellcheck disable=2086
nix-build \ if [[ -v USE_NIX2_COMMAND ]]; then
"<home-manager/home-manager/home-manager.nix>" \ if [[ $subCommand == 'eval' ]]; then
$extraArgs \ extraArgs="$extraArgs --raw"
--argstr confPath "$HOME_MANAGER_CONFIG" \ fi
--argstr confAttr "$HOME_MANAGER_CONFIG_ATTRIBUTE" nix $subCommand \
-f "<home-manager/home-manager/home-manager.nix>" \
$extraArgs \
--argstr confPath "$HOME_MANAGER_CONFIG" \
--argstr confAttr "$HOME_MANAGER_CONFIG_ATTRIBUTE"
else
if [[ $subCommand == 'eval' ]]; then
extraArgs="$extraArgs --no-out-link"
fi
nix-build \
"<home-manager/home-manager/home-manager.nix>" \
$extraArgs \
--argstr confPath "$HOME_MANAGER_CONFIG" \
--argstr confAttr "$HOME_MANAGER_CONFIG_ATTRIBUTE"
fi
} }
# Presents news to the user. Takes as argument the path to a "news # Presents news to the user. Takes as argument the path to a "news
@ -125,8 +141,14 @@ function doBuild() {
newsInfo=$(buildNews) newsInfo=$(buildNews)
local exitCode local exitCode
doBuildAttr -A activationPackage \
&& exitCode=0 || exitCode=1 if [[ -v USE_NIX2_COMMAND ]]; then
doBuildAttr build activationPackage \
&& exitCode=0 || exitCode=1
else
doBuildAttr build --attr activationPackage \
&& exitCode=0 || exitCode=1
fi
presentNews "$newsInfo" presentNews "$newsInfo"
@ -145,9 +167,21 @@ function doSwitch() {
# specify an output link so that it is treated as a GC root. This # specify an output link so that it is treated as a GC root. This
# prevents an unfortunately timed GC from removing the generation # prevents an unfortunately timed GC from removing the generation
# before activation completes. # before activation completes.
wrkdir="$(mktemp -d)" wrkdir="$(mktemp -d home-manager-build.XXXXXXXXXX)"
generation=$(doBuildAttr -o "$wrkdir/result" -A activationPackage) \ generation="$wrkdir/result"
&& $generation/activate || exitCode=1
if [[ -v USE_NIX2_COMMAND ]]; then
doBuildAttr build \
--out-link "$generation" \
activationPackage \
&& "$generation/activate" || exitCode=1
else
doBuildAttr build \
--out-link "$generation" \
--no-build-output \
--attr activationPackage > /dev/null \
&& "$generation/activate" || exitCode=1
fi
# Because the previous command never fails, the script keeps # Because the previous command never fails, the script keeps
# running and $wrkdir is always removed. # running and $wrkdir is always removed.
@ -237,11 +271,19 @@ function newsReadIdsFile() {
# (although this exposes the risk of GC removing the result before we # (although this exposes the risk of GC removing the result before we
# manage to source it). # manage to source it).
function buildNews() { function buildNews() {
doBuildAttr --quiet \ if [[ -v USE_NIX2_COMMAND ]]; then
--attr newsInfo \ doBuildAttr eval \
--no-out-link \ --quiet \
--arg check false \ --arg check false \
--argstr newsReadIdsFile "$(newsReadIdsFile)" --argstr newsReadIdsFile "$(newsReadIdsFile)" \
newsInfo
else
doBuildAttr eval \
--quiet \
--arg check false \
--argstr newsReadIdsFile "$(newsReadIdsFile)" \
--attr newsInfo
fi
} }
function doShowNews() { function doShowNews() {
@ -317,8 +359,11 @@ for arg in "$@"; do
fi fi
done done
while getopts f:I:A:vnh opt; do while getopts 2f:I:A:vnh opt; do
case $opt in case $opt in
2)
USE_NIX2_COMMAND=1
;;
f) f)
HOME_MANAGER_CONFIG="$OPTARG" HOME_MANAGER_CONFIG="$OPTARG"
;; ;;