mirror of
https://github.com/nix-community/home-manager
synced 2024-12-20 16:59:47 +01:00
home-manager: add home-manager option
This adds functionality much like that provided by `nixos-option`.
This commit is contained in:
parent
e92f5bb79e
commit
63af2d3e4c
5 changed files with 80 additions and 6 deletions
|
@ -41,6 +41,10 @@
|
||||||
news
|
news
|
||||||
</arg>
|
</arg>
|
||||||
|
|
||||||
|
<arg choice="plain">
|
||||||
|
option <replaceable>option.name</replaceable>
|
||||||
|
</arg>
|
||||||
|
|
||||||
<arg choice="plain">
|
<arg choice="plain">
|
||||||
packages
|
packages
|
||||||
</arg>
|
</arg>
|
||||||
|
@ -250,6 +254,18 @@
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</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>
|
<varlistentry>
|
||||||
<term>
|
<term>
|
||||||
<option>packages</option>
|
<option>packages</option>
|
||||||
|
|
|
@ -62,6 +62,7 @@
|
||||||
# generations
|
# generations
|
||||||
# help
|
# help
|
||||||
# news
|
# news
|
||||||
|
# option
|
||||||
# packages
|
# packages
|
||||||
# remove-generations
|
# remove-generations
|
||||||
# switch
|
# switch
|
||||||
|
@ -86,6 +87,7 @@
|
||||||
#
|
#
|
||||||
# help
|
# help
|
||||||
# edit
|
# edit
|
||||||
|
# option
|
||||||
# build
|
# build
|
||||||
# switch
|
# switch
|
||||||
# generations
|
# generations
|
||||||
|
@ -131,6 +133,9 @@
|
||||||
#
|
#
|
||||||
# edit Open the home configuration in $EDITOR
|
# edit Open the home configuration in $EDITOR
|
||||||
#
|
#
|
||||||
|
# option OPTION.NAME
|
||||||
|
# Inspect configuration option named OPTION.NAME.
|
||||||
|
#
|
||||||
# build Build configuration into result directory
|
# build Build configuration into result directory
|
||||||
#
|
#
|
||||||
# switch Build and activate configuration
|
# switch Build and activate configuration
|
||||||
|
@ -278,7 +283,7 @@ _home-manager_completions ()
|
||||||
#--------------------------#
|
#--------------------------#
|
||||||
|
|
||||||
local Subcommands
|
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.
|
# ^ « home-manager »'s subcommands.
|
||||||
|
|
||||||
|
@ -354,4 +359,4 @@ _home-manager_completions ()
|
||||||
|
|
||||||
complete -F _home-manager_completions -o default home-manager
|
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
|
||||||
|
|
|
@ -25,6 +25,7 @@ case "$state" in
|
||||||
_values 'command' \
|
_values 'command' \
|
||||||
'help[help]' \
|
'help[help]' \
|
||||||
'edit[edit]' \
|
'edit[edit]' \
|
||||||
|
'option[inspect option]' \
|
||||||
'build[build]' \
|
'build[build]' \
|
||||||
'switch[switch]' \
|
'switch[switch]' \
|
||||||
'generations[list generations]' \
|
'generations[list generations]' \
|
||||||
|
|
|
@ -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
|
# Extra path to Home Manager. If set then this path will be tried
|
||||||
# before `$HOME/.config/nixpkgs/home-manager` and
|
# before `$HOME/.config/nixpkgs/home-manager` and
|
||||||
|
@ -9,6 +11,9 @@ let
|
||||||
|
|
||||||
pathStr = if path == null then "" else path;
|
pathStr = if path == null then "" else path;
|
||||||
|
|
||||||
|
nixos-option =
|
||||||
|
callPackage "${pkgs.path}/nixos/modules/installer/tools/nixos-option" { };
|
||||||
|
|
||||||
in runCommand "home-manager" {
|
in runCommand "home-manager" {
|
||||||
preferLocalBuild = true;
|
preferLocalBuild = true;
|
||||||
allowSubstitutes = false;
|
allowSubstitutes = false;
|
||||||
|
@ -27,6 +32,7 @@ in runCommand "home-manager" {
|
||||||
--subst-var-by findutils "${findutils}" \
|
--subst-var-by findutils "${findutils}" \
|
||||||
--subst-var-by gnused "${gnused}" \
|
--subst-var-by gnused "${gnused}" \
|
||||||
--subst-var-by less "${less}" \
|
--subst-var-by less "${less}" \
|
||||||
|
--subst-var-by nixos-option "${nixos-option}" \
|
||||||
--subst-var-by HOME_MANAGER_PATH '${pathStr}'
|
--subst-var-by HOME_MANAGER_PATH '${pathStr}'
|
||||||
|
|
||||||
install -D -m755 ${./completion.bash} \
|
install -D -m755 ${./completion.bash} \
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!@bash@/bin/bash
|
#!@bash@/bin/bash
|
||||||
|
|
||||||
# Prepare to use tools from Nixpkgs.
|
# 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
|
set -euo pipefail
|
||||||
|
|
||||||
|
@ -97,6 +97,46 @@ function setFlakeAttribute() {
|
||||||
fi
|
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() {
|
function doInstantiate() {
|
||||||
setFlakeAttribute
|
setFlakeAttribute
|
||||||
if [[ -v FLAKE_CONFIG_URI ]]; then
|
if [[ -v FLAKE_CONFIG_URI ]]; then
|
||||||
|
@ -487,6 +527,9 @@ function doHelp() {
|
||||||
echo
|
echo
|
||||||
echo " edit Open the home configuration in \$EDITOR"
|
echo " edit Open the home configuration in \$EDITOR"
|
||||||
echo
|
echo
|
||||||
|
echo " option OPTION.NAME"
|
||||||
|
echo " Inspect configuration option named OPTION.NAME."
|
||||||
|
echo
|
||||||
echo " build Build configuration into result directory"
|
echo " build Build configuration into result directory"
|
||||||
echo
|
echo
|
||||||
echo " instantiate Instantiate the configuration and print the resulting derivation"
|
echo " instantiate Instantiate the configuration and print the resulting derivation"
|
||||||
|
@ -524,7 +567,7 @@ while [[ $# -gt 0 ]]; do
|
||||||
opt="$1"
|
opt="$1"
|
||||||
shift
|
shift
|
||||||
case $opt in
|
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"
|
COMMAND="$opt"
|
||||||
;;
|
;;
|
||||||
-A)
|
-A)
|
||||||
|
@ -586,7 +629,7 @@ while [[ $# -gt 0 ]]; do
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
case $COMMAND in
|
case $COMMAND in
|
||||||
expire-generations|remove-generations)
|
expire-generations|remove-generations|option)
|
||||||
COMMAND_ARGS+=("$opt")
|
COMMAND_ARGS+=("$opt")
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
@ -631,6 +674,9 @@ case $COMMAND in
|
||||||
doExpireGenerations "${COMMAND_ARGS[@]}"
|
doExpireGenerations "${COMMAND_ARGS[@]}"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
option)
|
||||||
|
doInspectOption "${COMMAND_ARGS[@]}"
|
||||||
|
;;
|
||||||
packages)
|
packages)
|
||||||
doListPackages
|
doListPackages
|
||||||
;;
|
;;
|
||||||
|
|
Loading…
Reference in a new issue