1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-12-20 00:39:47 +01:00

home-manager: add home-manager option

This adds functionality much like that provided by `nixos-option`.
This commit is contained in:
Dusk Banks 2020-08-20 22:53:03 -07:00 committed by Robert Helgesson
parent e92f5bb79e
commit 63af2d3e4c
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
5 changed files with 80 additions and 6 deletions

View file

@ -41,6 +41,10 @@
news
</arg>
<arg choice="plain">
option <replaceable>option.name</replaceable>
</arg>
<arg choice="plain">
packages
</arg>
@ -250,6 +254,18 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>option <replaceable>option.name</replaceable></option>
</term>
<listitem>
<para>
Inspect the given option name in the home configuration, like <citerefentry>
<refentrytitle>nixos-option</refentrytitle>
<manvolnum>8</manvolnum> </citerefentry>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>packages</option>

View file

@ -62,6 +62,7 @@
# generations
# help
# news
# option
# packages
# remove-generations
# switch
@ -86,6 +87,7 @@
#
# help
# edit
# option
# build
# switch
# generations
@ -131,6 +133,9 @@
#
# edit Open the home configuration in $EDITOR
#
# option OPTION.NAME
# Inspect configuration option named OPTION.NAME.
#
# build Build configuration into result directory
#
# switch Build and activate configuration
@ -278,7 +283,7 @@ _home-manager_completions ()
#--------------------------#
local Subcommands
Subcommands=( "help" "edit" "build" "instantiate" "switch" "generations" "remove-generations" "expire-generations" "packages" "news" "uninstall" )
Subcommands=( "help" "edit" "option" "build" "instantiate" "switch" "generations" "remove-generations" "expire-generations" "packages" "news" "uninstall" )
# ^ « home-manager »'s subcommands.
@ -354,4 +359,4 @@ _home-manager_completions ()
complete -F _home-manager_completions -o default home-manager
#complete -W "help edit build switch generations remove-generations expire-generations packages news" home-manager
#complete -W "help edit option build switch generations remove-generations expire-generations packages news" home-manager

View file

@ -25,6 +25,7 @@ case "$state" in
_values 'command' \
'help[help]' \
'edit[edit]' \
'option[inspect option]' \
'build[build]' \
'switch[switch]' \
'generations[list generations]' \

View file

@ -1,4 +1,6 @@
{ runCommand, lib, bash, coreutils, findutils, gnused, less
{ runCommand, lib, bash, callPackage, coreutils, findutils, gnused, less
# used for pkgs.path for nixos-option
, pkgs
# Extra path to Home Manager. If set then this path will be tried
# before `$HOME/.config/nixpkgs/home-manager` and
@ -9,6 +11,9 @@ let
pathStr = if path == null then "" else path;
nixos-option =
callPackage "${pkgs.path}/nixos/modules/installer/tools/nixos-option" { };
in runCommand "home-manager" {
preferLocalBuild = true;
allowSubstitutes = false;
@ -27,6 +32,7 @@ in runCommand "home-manager" {
--subst-var-by findutils "${findutils}" \
--subst-var-by gnused "${gnused}" \
--subst-var-by less "${less}" \
--subst-var-by nixos-option "${nixos-option}" \
--subst-var-by HOME_MANAGER_PATH '${pathStr}'
install -D -m755 ${./completion.bash} \

View file

@ -1,7 +1,7 @@
#!@bash@/bin/bash
# Prepare to use tools from Nixpkgs.
PATH=@coreutils@/bin:@findutils@/bin:@gnused@/bin:@less@/bin${PATH:+:}$PATH
PATH=@coreutils@/bin:@findutils@/bin:@gnused@/bin:@less@/bin:@nixos-option@/bin${PATH:+:}$PATH
set -euo pipefail
@ -97,6 +97,46 @@ function setFlakeAttribute() {
fi
}
function doInspectOption() {
setFlakeAttribute
if [[ -v FLAKE_CONFIG_URI ]]; then
errorEcho "Can't inspect options of a flake configuration"
exit 1
fi
setConfigFile
setHomeManagerNixPath
local extraArgs=("$@")
for p in "${EXTRA_NIX_PATH[@]}"; do
extraArgs=("${extraArgs[@]}" "-I" "$p")
done
if [[ -v VERBOSE ]]; then
extraArgs=("${extraArgs[@]}" "--show-trace")
fi
local HOME_MANAGER_CONFIG_NIX HOME_MANAGER_CONFIG_ATTRIBUTE_NIX
HOME_MANAGER_CONFIG_NIX=${HOME_MANAGER_CONFIG//'\'/'\\'}
HOME_MANAGER_CONFIG_NIX=${HOME_MANAGER_CONFIG_NIX//'"'/'\"'}
HOME_MANAGER_CONFIG_NIX=${HOME_MANAGER_CONFIG_NIX//$'\n'/$'\\n'}
HOME_MANAGER_CONFIG_ATTRIBUTE_NIX=${HOME_MANAGER_CONFIG_ATTRIBUTE//'\'/'\\'}
HOME_MANAGER_CONFIG_ATTRIBUTE_NIX=${HOME_MANAGER_CONFIG_ATTRIBUTE_NIX//'"'/'\"'}
HOME_MANAGER_CONFIG_ATTRIBUTE_NIX=${HOME_MANAGER_CONFIG_ATTRIBUTE_NIX//$'\n'/$'\\n'}
local modulesExpr
modulesExpr="let confPath = \"${HOME_MANAGER_CONFIG_NIX}\"; "
modulesExpr+="confAttr = \"${HOME_MANAGER_CONFIG_ATTRIBUTE_NIX}\"; in "
modulesExpr+="(import <home-manager/modules> {"
modulesExpr+=" configuration = if confAttr == \"\" then confPath else (import confPath).\${confAttr};"
modulesExpr+=" pkgs = import <nixpkgs> {}; check = true; })"
nixos-option \
--options_expr "$modulesExpr.options" \
--config_expr "$modulesExpr.config" \
"${extraArgs[@]}" \
"${PASSTHROUGH_OPTS[@]}"
}
function doInstantiate() {
setFlakeAttribute
if [[ -v FLAKE_CONFIG_URI ]]; then
@ -487,6 +527,9 @@ function doHelp() {
echo
echo " edit Open the home configuration in \$EDITOR"
echo
echo " option OPTION.NAME"
echo " Inspect configuration option named OPTION.NAME."
echo
echo " build Build configuration into result directory"
echo
echo " instantiate Instantiate the configuration and print the resulting derivation"
@ -524,7 +567,7 @@ while [[ $# -gt 0 ]]; do
opt="$1"
shift
case $opt in
build|instantiate|edit|expire-generations|generations|help|news|packages|remove-generations|switch|uninstall)
build|instantiate|option|edit|expire-generations|generations|help|news|packages|remove-generations|switch|uninstall)
COMMAND="$opt"
;;
-A)
@ -586,7 +629,7 @@ while [[ $# -gt 0 ]]; do
;;
*)
case $COMMAND in
expire-generations|remove-generations)
expire-generations|remove-generations|option)
COMMAND_ARGS+=("$opt")
;;
*)
@ -631,6 +674,9 @@ case $COMMAND in
doExpireGenerations "${COMMAND_ARGS[@]}"
fi
;;
option)
doInspectOption "${COMMAND_ARGS[@]}"
;;
packages)
doListPackages
;;