2017-01-07 19:16:26 +01:00
#!@bash@/bin/bash
2018-10-02 06:42:46 +02:00
# Prepare to use tools from Nixpkgs.
2021-04-30 01:29:39 +02:00
PATH=@DEP_PATH@${PATH:+:}$PATH
2017-05-16 16:09:18 +02:00
2017-05-14 14:02:15 +02:00
set -euo pipefail
2021-04-30 01:29:39 +02:00
export TEXTDOMAIN=home-manager
export TEXTDOMAINDIR=@OUT@/share/locale
# shellcheck disable=1091
source @HOME_MANAGER_LIB@
2017-09-01 10:24:01 +02:00
2024-04-18 17:25:13 +02:00
function errMissingOptArg() {
# translators: For example: "home-manager: missing argument for --cores"
_iError "%s: missing argument for %s" "$0" "$1" >&2
exit 1
}
2021-11-10 19:23:33 +01:00
function setNixProfileCommands() {
2023-09-08 07:02:56 +02:00
if [[ -e $HOME/.nix-profile/manifest.json \
|| -e ${XDG_STATE_HOME:-$HOME/.local/state}/nix/profile/manifest.json ]] ; then
2021-11-10 19:23:33 +01:00
LIST_OUTPATH_CMD="nix profile list"
else
2022-03-27 09:43:19 +02:00
LIST_OUTPATH_CMD="nix-env -q --out-path"
2021-11-10 19:23:33 +01:00
fi
}
2024-01-13 23:15:00 +01:00
function setVerboseArg() {
2019-04-28 00:33:41 +02:00
if [[ -v VERBOSE ]]; then
export VERBOSE_ARG="--verbose"
else
export VERBOSE_ARG=""
fi
}
2018-07-31 13:42:56 +02:00
function setWorkDir() {
if [[ ! -v WORK_DIR ]]; then
WORK_DIR="$(mktemp --tmpdir -d home-manager-build.XXXXXXXXXX)"
# shellcheck disable=2064
trap "rm -r '$WORK_DIR'" EXIT
fi
}
2023-02-26 23:10:06 +01:00
# Checks whether the 'flakes' and 'nix-command' Nix options are enabled.
function hasFlakeSupport() {
type -p nix > /dev/null \
2023-05-21 23:07:55 +02:00
&& nix show-config 2> /dev/null \
2023-02-26 23:10:06 +01:00
| grep experimental-features \
| grep flakes \
| grep -q nix-command
}
2017-05-20 23:39:54 +02:00
# Attempts to set the HOME_MANAGER_CONFIG global variable.
#
# If no configuration file can be found then this function will print
# an error message and exit with an error code.
function setConfigFile() {
if [[ -v HOME_MANAGER_CONFIG ]] ; then
2023-03-13 23:16:03 +01:00
if [[ -e "$HOME_MANAGER_CONFIG" ]] ; then
HOME_MANAGER_CONFIG="$(realpath "$HOME_MANAGER_CONFIG")"
else
_i 'No configuration file found at %s' \
2021-04-30 01:29:39 +02:00
"$HOME_MANAGER_CONFIG" >&2
2017-05-20 23:39:54 +02:00
exit 1
fi
2023-03-13 23:16:03 +01:00
elif [[ ! -v HOME_MANAGER_CONFIG ]]; then
local configHome="${XDG_CONFIG_HOME:-$HOME/.config}"
local hmConfigHome="$configHome/home-manager"
local nixpkgsConfigHome="$configHome/nixpkgs"
local defaultConfFile="$hmConfigHome/home.nix"
2023-04-21 12:23:36 +02:00
local configFile
2023-03-13 23:16:03 +01:00
if [[ -e "$defaultConfFile" ]]; then
configFile="$defaultConfFile"
elif [[ -e "$nixpkgsConfigHome/home.nix" ]]; then
configFile="$nixpkgsConfigHome/home.nix"
# translators: The first '%s' specifier will be replaced by either
# 'home.nix' or 'flake.nix'.
_iWarn $'Keeping your Home Manager %s in %s is deprecated,\nplease move it to %s' \
'home.nix' "$nixpkgsConfigHome" "$hmConfigHome" >&2
elif [[ -e "$HOME/.nixpkgs/home.nix" ]]; then
configFile="$HOME/.nixpkgs/home.nix"
_iWarn $'Keeping your Home Manager %s in %s is deprecated,\nplease move it to %s' \
'home.nix' "$HOME/.nixpkgs" "$hmConfigHome" >&2
2017-05-20 23:39:54 +02:00
fi
2017-01-14 13:02:58 +01:00
2023-04-21 11:40:20 +02:00
if [[ -v configFile ]]; then
2023-03-13 23:16:03 +01:00
HOME_MANAGER_CONFIG="$(realpath "$configFile")"
else
_i 'No configuration file found. Please create one at %s' \
"$defaultConfFile" >&2
exit 1
fi
fi
2017-05-20 23:39:54 +02:00
}
2017-01-15 21:07:39 +01:00
2017-10-21 20:51:28 +02:00
function setHomeManagerNixPath() {
2023-06-17 01:10:48 +02:00
local path="@HOME_MANAGER_PATH@"
if [[ -n "$path" ]] ; then
2017-10-21 20:51:28 +02:00
if [[ -e "$path" || "$path" =~ ^https?:// ]] ; then
2023-01-10 10:35:00 +01:00
EXTRA_NIX_PATH+=("home-manager=$path")
2017-05-20 23:39:54 +02:00
return
2023-06-17 01:10:48 +02:00
else
_iWarn 'Home Manager not found at %s.' "$path"
fi
fi
for p in "${XDG_CONFIG_HOME:-$HOME/.config}/nixpkgs/home-manager" \
"$HOME/.nixpkgs/home-manager" ; do
if [[ -e "$p" ]] ; then
# translators: This message will be seen by very few users that likely are familiar with English. So feel free to leave this untranslated.
_iWarn $'The fallback Home Manager path %s has been deprecated and a file/directory was found there.' \
"$p"
# translators: This message will be seen by very few users that likely are familiar with English. So feel free to leave this untranslated.
2023-09-13 00:06:33 +02:00
_i $'To remove this warning, do one of the following.
2023-06-17 01:10:48 +02:00
1. Explicitly tell Home Manager to use the path, for example by adding
{ programs.home-manager.path = "%s"; }
to your configuration.
If you import Home Manager directly, you can use the `path` parameter
pkgs.callPackage /path/to/home-manager-package { path = "%s"; }
when calling the Home Manager package.
2. Remove the deprecated path.
$ rm -r "%s"' "$p" "$p" "$p"
2017-05-20 23:39:54 +02:00
fi
done
}
2023-03-04 10:39:02 +01:00
# Sets some useful Home Manager related paths as global read-only variables.
function setHomeManagerPathVariables() {
2023-10-04 00:07:05 +02:00
# If called twice then just exit early.
if [[ -v HM_DATA_HOME ]]; then
return
fi
2024-02-15 13:10:23 +01:00
_iVerbose "Sanity checking Nix"
2024-03-22 19:44:27 +01:00
nix-build --quiet --expr '{}' --no-out-link > /dev/null 2>&1 || true
2024-02-15 13:10:23 +01:00
nix-env -q > /dev/null 2>&1 || true
2023-04-07 14:01:45 +02:00
declare -r globalNixStateDir="${NIX_STATE_DIR:-/nix/var/nix}"
declare -r globalProfilesDir="$globalNixStateDir/profiles/per-user/$USER"
declare -r globalGcrootsDir="$globalNixStateDir/gcroots/per-user/$USER"
declare -r stateHome="${XDG_STATE_HOME:-$HOME/.local/state}"
declare -r userNixStateDir="$stateHome/nix"
2023-03-04 10:39:02 +01:00
declare -gr HM_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}/home-manager"
2023-04-07 14:01:45 +02:00
declare -gr HM_STATE_DIR="$stateHome/home-manager"
2023-03-04 10:39:02 +01:00
declare -gr HM_GCROOT_LEGACY_PATH="$globalGcrootsDir/current-home"
2023-04-07 14:01:45 +02:00
if [[ -d $userNixStateDir/profiles ]]; then
declare -gr HM_PROFILE_DIR="$userNixStateDir/profiles"
elif [[ -d $globalProfilesDir ]]; then
2023-03-04 10:39:02 +01:00
declare -gr HM_PROFILE_DIR="$globalProfilesDir"
else
2023-04-07 14:01:45 +02:00
_iError 'Could not find suitable profile directory, tried %s and %s' \
2024-02-15 13:10:07 +01:00
"$userNixStateDir/profiles" "$globalProfilesDir" >&2
2023-04-07 14:01:45 +02:00
exit 1
2023-03-04 10:39:02 +01:00
fi
}
2021-04-07 19:17:39 +02:00
function setFlakeAttribute() {
2023-03-13 23:16:03 +01:00
if [[ -z $FLAKE_ARG && ! -v HOME_MANAGER_CONFIG ]]; then
local configHome="${XDG_CONFIG_HOME:-$HOME/.config}"
local hmConfigHome="$configHome/home-manager"
local nixpkgsConfigHome="$configHome/nixpkgs"
local configFlake
if [[ -e "$hmConfigHome/flake.nix" ]]; then
configFlake="$hmConfigHome/flake.nix"
elif [[ -e "$nixpkgsConfigHome/flake.nix" ]]; then
configFlake="$nixpkgsConfigHome/flake.nix"
_iWarn $'Keeping your Home Manager %s in %s is deprecated,\nplease move it to %s' \
'flake.nix' "$nixpkgsConfigHome" "$hmConfigHome" >&2
fi
if [[ -v configFlake ]]; then
2023-07-03 17:00:10 +02:00
FLAKE_ARG="path:$(dirname "$(readlink -f "$configFlake")")"
2023-03-13 23:16:03 +01:00
fi
2021-04-07 19:17:39 +02:00
fi
if [[ -n "$FLAKE_ARG" ]]; then
local flake="${FLAKE_ARG%#*}"
case $FLAKE_ARG in
*#*)
local name="${FLAKE_ARG#*#}"
2023-03-13 23:16:03 +01:00
;;
2021-04-07 19:17:39 +02:00
*)
2022-11-29 22:26:00 +01:00
local name="$USER"
# Check both long and short hostnames; long first to preserve
# pre-existing behaviour in case both happen to be defined.
for n in "$USER@$(hostname)" "$USER@$(hostname -s)"; do
if [[ "$(nix eval "$flake#homeConfigurations" --apply "x: x ? \"$n\"")" == "true" ]]; then
name="$n"
if [[ -v VERBOSE ]]; then
echo "Using flake homeConfiguration for $name"
fi
fi
done
2023-03-13 23:16:03 +01:00
;;
2021-04-07 19:17:39 +02:00
esac
export FLAKE_CONFIG_URI="$flake#homeConfigurations.\"$name\""
fi
}
2020-08-21 07:53:03 +02:00
function doInspectOption() {
setFlakeAttribute
if [[ -v FLAKE_CONFIG_URI ]]; then
2023-04-11 22:43:52 +02:00
# translators: Here "flake" is a noun that refers to the Nix Flakes feature.
2021-04-30 01:29:39 +02:00
_iError "Can't inspect options of a flake configuration"
2020-08-21 07:53:03 +02:00
exit 1
fi
setConfigFile
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[@]}"
}
2023-02-26 23:10:06 +01:00
function doInit() {
# The directory where we should place the initial configuration.
local confDir
# Whether we should immediate activate the configuration.
local switch
# Whether we should create a flake file.
local withFlake
if hasFlakeSupport; then
withFlake=1
fi
2024-02-12 23:40:15 +01:00
local homeManagerUrl="github:nix-community/home-manager"
local nixpkgsUrl="github:nixos/nixpkgs/nixos-unstable"
2023-02-26 23:10:06 +01:00
while (( $# > 0 )); do
local opt="$1"
shift
case $opt in
--no-flake)
unset withFlake
;;
--switch)
switch=1
;;
2024-02-12 23:40:15 +01:00
--home-manager-url)
2024-04-18 17:25:13 +02:00
[[ -v 1 && $1 != -* ]] || errMissingOptArg "$opt"
2024-02-12 23:40:15 +01:00
homeManagerUrl="$1"
shift
;;
--nixpkgs-url)
2024-04-18 17:25:13 +02:00
[[ -v 1 && $1 != -* ]] || errMissingOptArg "$opt"
2024-02-12 23:40:15 +01:00
nixpkgsUrl="$1"
shift
;;
2023-02-26 23:10:06 +01:00
-*)
_iError "%s: unknown option '%s'" "$0" "$opt" >&2
exit 1
;;
*)
if [[ -v confDir ]]; then
_i "Run '%s --help' for usage help" "$0" >&2
exit 1
else
confDir="$opt"
fi
;;
esac
done
if [[ ! -v confDir ]]; then
confDir="${XDG_CONFIG_HOME:-$HOME/.config}/home-manager"
fi
if [[ ! -e $confDir ]]; then
mkdir -p "$confDir"
fi
if [[ ! -d $confDir ]]; then
_iError "%s: unknown option '%s'" "$0" "$opt" >&2
exit 1
fi
local confFile="$confDir/home.nix"
local flakeFile="$confDir/flake.nix"
if [[ -e $confFile ]]; then
_i 'The file %s already exists, leaving it unchanged...' "$confFile"
else
_i 'Creating %s...' "$confFile"
local nl=$'\n'
local xdgVars=""
if [[ -v XDG_CACHE_HOME && $XDG_CACHE_HOME != "$HOME/.cache" ]]; then
xdgVars="$xdgVars xdg.cacheHome = \"$XDG_CACHE_HOME\";$nl"
fi
if [[ -v XDG_CONFIG_HOME && $XDG_CONFIG_HOME != "$HOME/.config" ]]; then
xdgVars="$xdgVars xdg.configHome = \"$XDG_CONFIG_HOME\";$nl"
fi
if [[ -v XDG_DATA_HOME && $XDG_DATA_HOME != "$HOME/.local/share" ]]; then
xdgVars="$xdgVars xdg.dataHome = \"$XDG_DATA_HOME\";$nl"
fi
if [[ -v XDG_STATE_HOME && $XDG_STATE_HOME != "$HOME/.local/state" ]]; then
xdgVars="$xdgVars xdg.stateHome = \"$XDG_STATE_HOME\";$nl"
fi
mkdir -p "$confDir"
cat > "$confFile" <<EOF
{ config, pkgs, ... }:
{
2023-03-18 15:47:33 +01:00
# Home Manager needs a bit of information about you and the paths it should
# manage.
2023-02-26 23:10:06 +01:00
home.username = "$USER";
home.homeDirectory = "$HOME";
$xdgVars
2023-03-18 15:47:33 +01:00
# This value determines the Home Manager release that your configuration is
# compatible with. This helps avoid breakage when a new Home Manager release
# introduces backwards incompatible changes.
2023-02-26 23:10:06 +01:00
#
2023-03-18 15:47:33 +01:00
# You should not change this value, even if you update Home Manager. If you do
# want to update the value, then make sure to first check the Home Manager
# release notes.
2023-11-24 08:41:17 +01:00
home.stateVersion = "23.11"; # Please read the comment before changing.
2023-03-18 15:47:33 +01:00
# The home.packages option allows you to install Nix packages into your
# environment.
home.packages = [
# # Adds the 'hello' command to your environment. It prints a friendly
# # "Hello, world!" when run.
# pkgs.hello
# # It is sometimes useful to fine-tune packages, for example, by applying
# # overrides. You can do that directly here, just don't forget the
# # parentheses. Maybe you want to install Nerd Fonts with a limited number of
# # fonts?
# (pkgs.nerdfonts.override { fonts = [ "FantasqueSansMono" ]; })
# # You can also create simple shell scripts directly inside your
# # configuration. For example, this adds a command 'my-hello' to your
# # environment:
# (pkgs.writeShellScriptBin "my-hello" ''
# echo "Hello, \${config.home.username}!"
# '')
];
# Home Manager is pretty good at managing dotfiles. The primary way to manage
# plain files is through 'home.file'.
home.file = {
# # Building this configuration will create a copy of 'dotfiles/screenrc' in
# # the Nix store. Activating the configuration will then make '~/.screenrc' a
# # symlink to the Nix store copy.
# ".screenrc".source = dotfiles/screenrc;
# # You can also set the file content immediately.
# ".gradle/gradle.properties".text = ''
# org.gradle.console=verbose
# org.gradle.daemon.idletimeout=3600000
# '';
};
2023-08-13 23:21:16 +02:00
# Home Manager can also manage your environment variables through
2024-04-23 19:49:42 +02:00
# 'home.sessionVariables'. These will be explicitly sourced when using a
# shell provided by Home Manager. If you don't want to manage your shell
# through Home Manager then you have to manually source 'hm-session-vars.sh'
# located at either
2023-03-18 15:47:33 +01:00
#
# ~/.nix-profile/etc/profile.d/hm-session-vars.sh
#
# or
#
2023-09-08 07:02:56 +02:00
# ~/.local/state/nix/profiles/profile/etc/profile.d/hm-session-vars.sh
#
# or
#
2023-03-18 15:47:33 +01:00
# /etc/profiles/per-user/$USER/etc/profile.d/hm-session-vars.sh
#
home.sessionVariables = {
# EDITOR = "emacs";
};
2023-02-26 23:10:06 +01:00
# Let Home Manager install and manage itself.
programs.home-manager.enable = true;
}
EOF
fi
if [[ ! -v withFlake ]]; then
HOME_MANAGER_CONFIG="$confFile"
else
FLAKE_ARG="$confDir"
if [[ -e $flakeFile ]]; then
_i 'The file %s already exists, leaving it unchanged...' "$flakeFile"
else
_i 'Creating %s...' "$flakeFile"
local nixSystem
nixSystem=$(nix eval --expr builtins.currentSystem --raw --impure)
mkdir -p "$confDir"
cat > "$flakeFile" <<EOF
{
description = "Home Manager configuration of $USER";
inputs = {
# Specify the source of Home Manager and Nixpkgs.
2024-02-12 23:40:15 +01:00
nixpkgs.url = "$nixpkgsUrl";
2023-02-26 23:10:06 +01:00
home-manager = {
2024-02-12 23:40:15 +01:00
url = "$homeManagerUrl";
2023-02-26 23:10:06 +01:00
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { nixpkgs, home-manager, ... }:
let
system = "$nixSystem";
pkgs = nixpkgs.legacyPackages.\${system};
in {
2023-04-19 15:08:50 +02:00
homeConfigurations."$USER" = home-manager.lib.homeManagerConfiguration {
2023-02-26 23:10:06 +01:00
inherit pkgs;
# Specify your home configuration modules here, for example,
# the path to your home.nix.
modules = [ ./home.nix ];
# Optionally use extraSpecialArgs
# to pass through arguments to home.nix
};
};
}
EOF
fi
fi
if [[ -v switch ]]; then
echo
_i "Creating initial Home Manager generation..."
echo
if doSwitch; then
# translators: The "%s" specifier will be replaced by a file path.
_i $'All done! The home-manager tool should now be installed and you can edit\n\n %s\n\nto configure Home Manager. Run \'man home-configuration.nix\' to\nsee all available options.' \
"$confFile"
exit 0
else
# translators: The "%s" specifier will be replaced by a URL.
_i $'Uh oh, the installation failed! Please create an issue at\n\n %s\n\nif the error seems to be the fault of Home Manager.' \
"https://github.com/nix-community/home-manager/issues"
exit 1
fi
fi
}
2020-03-18 00:02:38 +01:00
function doInstantiate() {
2021-04-07 19:17:39 +02:00
setFlakeAttribute
if [[ -v FLAKE_CONFIG_URI ]]; then
2023-04-11 22:43:52 +02:00
# translators: Here "flake" is a noun that refers to the Nix Flakes feature.
2021-04-30 01:29:39 +02:00
_i "Can't instantiate a flake configuration" >&2
2021-04-07 19:17:39 +02:00
exit 1
fi
2020-03-18 00:02:38 +01:00
setConfigFile
2020-04-18 10:53:41 +02:00
local extraArgs=()
2020-03-18 00:02:38 +01:00
for p in "${EXTRA_NIX_PATH[@]}"; do
extraArgs=("${extraArgs[@]}" "-I" "$p")
done
if [[ -v VERBOSE ]]; then
extraArgs=("${extraArgs[@]}" "--show-trace")
fi
nix-instantiate \
"<home-manager/home-manager/home-manager.nix>" \
"${extraArgs[@]}" \
"${PASSTHROUGH_OPTS[@]}" \
--argstr confPath "$HOME_MANAGER_CONFIG" \
--argstr confAttr "$HOME_MANAGER_CONFIG_ATTRIBUTE"
}
2017-08-26 22:24:40 +02:00
function doBuildAttr() {
2017-05-20 23:39:54 +02:00
setConfigFile
2020-02-23 11:37:03 +01:00
local extraArgs=("$@")
2017-02-14 18:25:30 +01:00
for p in "${EXTRA_NIX_PATH[@]}"; do
2020-02-23 11:37:03 +01:00
extraArgs=("${extraArgs[@]}" "-I" "$p")
2017-02-14 18:25:30 +01:00
done
2017-03-25 21:48:17 +01:00
if [[ -v VERBOSE ]]; then
2020-02-23 11:37:03 +01:00
extraArgs=("${extraArgs[@]}" "--show-trace")
2017-02-21 21:49:12 +01:00
fi
2020-04-18 10:54:40 +02:00
nix-build \
"<home-manager/home-manager/home-manager.nix>" \
"${extraArgs[@]}" \
"${PASSTHROUGH_OPTS[@]}" \
--argstr confPath "$HOME_MANAGER_CONFIG" \
--argstr confAttr "$HOME_MANAGER_CONFIG_ATTRIBUTE"
2017-08-26 22:24:40 +02:00
}
2021-11-25 01:09:53 +01:00
function doBuildFlake() {
local extraArgs=("$@")
if [[ -v VERBOSE ]]; then
extraArgs=("${extraArgs[@]}" "--verbose")
fi
nix build \
"${extraArgs[@]}" \
"${PASSTHROUGH_OPTS[@]}"
}
2023-07-29 19:56:00 +02:00
# Presents news to the user as specified by the `news.display` option.
2017-08-26 22:24:40 +02:00
function presentNews() {
2023-07-29 19:56:00 +02:00
local newsNixFile="$WORK_DIR/news.nix"
buildNews "$newsNixFile"
2017-08-26 22:24:40 +02:00
2023-07-29 19:56:00 +02:00
local newsDisplay
newsDisplay="$(nix-instantiate --eval --expr "(import ${newsNixFile}).meta.display" | xargs)"
local newsNumUnread
newsNumUnread="$(nix-instantiate --eval --expr "(import ${newsNixFile}).meta.numUnread" | xargs)"
2017-08-26 22:24:40 +02:00
2018-01-27 09:43:57 +01:00
# shellcheck disable=2154
2017-08-26 22:24:40 +02:00
if [[ $newsNumUnread -eq 0 ]]; then
return
elif [[ "$newsDisplay" == "silent" ]]; then
return
elif [[ "$newsDisplay" == "notify" ]]; then
2021-04-30 01:29:39 +02:00
local cmd msg
cmd="$(basename "$0")"
msg="$(_ip \
$'There is %d unread and relevant news item.\nRead it by running the command "%s news".' \
$'There are %d unread and relevant news items.\nRead them by running the command "%s news".' \
"$newsNumUnread" "$newsNumUnread" "$cmd")"
2017-08-26 22:24:40 +02:00
# Not actually an error but here stdout is reserved for
# nix-build output.
2021-04-30 01:29:39 +02:00
echo $'\n'"$msg"$'\n' >&2
2017-08-26 22:24:40 +02:00
if [[ -v DISPLAY ]] && type -P notify-send > /dev/null; then
2023-04-17 00:46:17 +02:00
notify-send "Home Manager" "$msg" > /dev/null 2>&1 || true
2017-08-26 22:24:40 +02:00
fi
elif [[ "$newsDisplay" == "show" ]]; then
doShowNews --unread
else
2021-04-30 01:29:39 +02:00
_i 'Unknown "news.display" setting "%s".' "$newsDisplay" >&2
2017-08-26 22:24:40 +02:00
fi
}
2018-12-03 11:19:22 +01:00
function doEdit() {
2024-02-05 23:22:43 +01:00
if [[ ! -v VISUAL || -z $VISUAL ]]; then
if [[ ! -v EDITOR || -z $EDITOR ]]; then
# shellcheck disable=2016
_i 'Please set the $EDITOR or $VISUAL environment variable' >&2
return 1
fi
else
EDITOR=$VISUAL
2018-12-03 11:19:22 +01:00
fi
setConfigFile
2020-09-20 01:22:26 +02:00
# Don't quote $EDITOR in order to support values including options, e.g.,
# "code --wait".
#
# shellcheck disable=2086
exec $EDITOR "$HOME_MANAGER_CONFIG"
2018-12-03 11:19:22 +01:00
}
2017-08-26 22:24:40 +02:00
function doBuild() {
2017-11-05 19:31:07 +01:00
if [[ ! -w . ]]; then
2021-04-30 01:29:39 +02:00
_i 'Cannot run build in read-only directory' >&2
2017-11-05 19:31:07 +01:00
return 1
fi
2021-11-25 01:09:53 +01:00
setWorkDir
2021-04-07 19:17:39 +02:00
setFlakeAttribute
if [[ -v FLAKE_CONFIG_URI ]]; then
2021-11-25 01:09:53 +01:00
doBuildFlake \
2021-04-07 19:17:39 +02:00
"$FLAKE_CONFIG_URI.activationPackage" \
2021-11-29 02:48:21 +01:00
${DRY_RUN+--dry-run} \
${NO_OUT_LINK+--no-link} \
2022-12-25 07:48:45 +01:00
${PRINT_BUILD_LOGS+--print-build-logs} \
2021-11-14 13:53:14 +01:00
|| return
2021-11-25 01:09:53 +01:00
else
doBuildAttr \
${NO_OUT_LINK+--no-out-link} \
--attr activationPackage \
2021-11-14 13:53:14 +01:00
|| return
2021-04-07 19:17:39 +02:00
fi
2023-07-29 19:56:00 +02:00
presentNews
2021-11-25 01:09:53 +01:00
}
2021-04-07 19:17:39 +02:00
2021-11-25 01:09:53 +01:00
function doSwitch() {
2018-07-31 13:42:56 +02:00
setWorkDir
2017-08-17 10:16:26 +02:00
local generation
2017-09-04 22:19:56 +02:00
# Build the generation and run the activate script. Note, we
2017-10-24 12:41:28 +02:00
# specify an output link so that it is treated as a GC root. This
2017-09-04 22:19:56 +02:00
# prevents an unfortunately timed GC from removing the generation
# before activation completes.
2018-07-31 13:42:56 +02:00
generation="$WORK_DIR/generation"
2018-06-13 21:00:26 +02:00
2021-11-25 01:09:53 +01:00
setFlakeAttribute
if [[ -v FLAKE_CONFIG_URI ]]; then
doBuildFlake \
"$FLAKE_CONFIG_URI.activationPackage" \
2021-11-29 02:48:21 +01:00
--out-link "$generation" \
2022-12-25 07:48:45 +01:00
${PRINT_BUILD_LOGS+--print-build-logs} \
2021-11-25 01:09:53 +01:00
&& "$generation/activate" || return
else
doBuildAttr \
--out-link "$generation" \
--attr activationPackage \
&& "$generation/activate" || return
fi
2023-07-29 19:56:00 +02:00
presentNews
2017-01-07 19:16:26 +01:00
}
function doListGens() {
2023-09-14 04:13:15 +02:00
setHomeManagerPathVariables
2018-03-03 21:58:22 +01:00
# Whether to colorize the generations output.
local color="never"
2021-03-01 13:22:33 +01:00
if [[ ! -v NO_COLOR && -t 1 ]]; then
2018-03-03 21:58:22 +01:00
color="always"
fi
2023-03-04 10:39:02 +01:00
pushd "$HM_PROFILE_DIR" > /dev/null
2018-01-27 09:43:57 +01:00
# shellcheck disable=2012
2018-03-03 21:58:22 +01:00
ls --color=$color -gG --time-style=long-iso --sort time home-manager-*-link \
2017-11-12 13:37:59 +01:00
| cut -d' ' -f 4- \
2018-01-27 09:39:45 +01:00
| sed -E 's/home-manager-([[:digit:]]*)-link/: id \1/'
2017-01-08 22:06:53 +01:00
popd > /dev/null
2017-01-07 19:16:26 +01:00
}
2017-11-12 14:07:41 +01:00
# Removes linked generations. Takes as arguments identifiers of
# generations to remove.
function doRmGenerations() {
2023-09-14 04:13:15 +02:00
setHomeManagerPathVariables
2024-01-13 23:15:00 +01:00
setVerboseArg
2017-11-12 14:07:41 +01:00
2023-03-04 10:39:02 +01:00
pushd "$HM_PROFILE_DIR" > /dev/null
2017-11-12 14:07:41 +01:00
for generationId in "$@"; do
local linkName="home-manager-$generationId-link"
if [[ ! -e $linkName ]]; then
2021-04-30 01:29:39 +02:00
_i 'No generation with ID %s' "$generationId" >&2
2017-11-12 14:07:41 +01:00
elif [[ $linkName == $(readlink home-manager) ]]; then
2021-04-30 01:29:39 +02:00
_i 'Cannot remove the current generation %s' "$generationId" >&2
2017-11-12 14:07:41 +01:00
else
2021-04-30 01:29:39 +02:00
_i 'Removing generation %s' "$generationId"
2024-01-13 23:15:00 +01:00
run rm $VERBOSE_ARG $linkName
2017-11-12 14:07:41 +01:00
fi
done
popd > /dev/null
}
2018-10-02 06:42:46 +02:00
function doExpireGenerations() {
2023-09-14 04:13:15 +02:00
setHomeManagerPathVariables
2018-10-02 06:42:46 +02:00
local generations
generations="$( \
2023-03-04 10:39:02 +01:00
find "$HM_PROFILE_DIR" -name 'home-manager-*-link' -not -newermt "$1" \
2018-10-02 06:42:46 +02:00
| sed 's/^.*-\([0-9]*\)-link$/\1/' \
)"
if [[ -n $generations ]]; then
# shellcheck disable=2086
doRmGenerations $generations
elif [[ -v VERBOSE ]]; then
2021-04-30 01:29:39 +02:00
_i "No generations to expire"
2018-10-02 06:42:46 +02:00
fi
}
2017-01-07 19:16:26 +01:00
function doListPackages() {
2021-11-10 19:23:33 +01:00
setNixProfileCommands
2017-01-07 19:16:26 +01:00
local outPath
2021-11-10 19:23:33 +01:00
outPath="$($LIST_OUTPATH_CMD | grep -o '/.*home-manager-path$')"
2017-01-07 19:36:39 +01:00
if [[ -n "$outPath" ]] ; then
2023-12-18 23:05:17 +01:00
nix-store -q --references "$outPath" | sed 's/[^-]*-//' | sort --ignore-case
2017-01-07 19:36:39 +01:00
else
2021-04-30 01:29:39 +02:00
_i 'No home-manager packages seem to be installed.' >&2
2017-01-07 19:36:39 +01:00
fi
2017-01-07 19:16:26 +01:00
}
2017-08-26 22:24:40 +02:00
function newsReadIdsFile() {
local dataDir="${XDG_DATA_HOME:-$HOME/.local/share}/home-manager"
local path="$dataDir/news-read-ids"
# If the path doesn't exist then we should create it, otherwise
# Nix will error out when we attempt to use builtins.readFile.
if [[ ! -f "$path" ]]; then
mkdir -p "$dataDir"
touch "$path"
fi
2024-04-23 18:52:19 +02:00
# Remove duplicate slashes in case $HOME or $XDG_DATA_HOME have a trailing
# slash. Double slashes causes Nix to error out with
#
# error: syntax error, unexpected PATH_END, expecting DOLLAR_CURLY".
echo "$path" | tr -s /
2017-08-26 22:24:40 +02:00
}
2023-07-29 19:56:00 +02:00
# Builds the Home Manager news data file.
2017-09-06 23:44:58 +02:00
#
# Note, we suppress build output to remove unnecessary verbosity. We
2018-07-31 13:42:56 +02:00
# put the output in the work directory to avoid the risk of an
# unfortunately timed GC removing it.
2017-09-06 23:44:58 +02:00
function buildNews() {
2023-07-29 19:56:00 +02:00
local newsNixFile="$1"
local newsJsonFile="$WORK_DIR/news.json"
2023-03-25 16:16:34 +01:00
if [[ -v FLAKE_CONFIG_URI ]]; then
2023-07-29 19:56:00 +02:00
# TODO: Use check=false to make it more likely that the build succeeds.
doBuildFlake \
"$FLAKE_CONFIG_URI.config.news.json.output" \
--quiet \
--out-link "$newsJsonFile" \
|| return
else
doBuildAttr \
--out-link "$newsJsonFile" \
--arg check false \
--attr config.news.json.output \
> /dev/null \
|| return
2023-03-25 16:16:34 +01:00
fi
2023-07-29 19:56:00 +02:00
local extraArgs=()
for p in "${EXTRA_NIX_PATH[@]}"; do
extraArgs=("${extraArgs[@]}" "-I" "$p")
done
2018-07-31 13:42:56 +02:00
2023-07-29 19:56:00 +02:00
local readIdsFile
2024-04-23 18:52:19 +02:00
readIdsFile="$(newsReadIdsFile)"
2018-07-31 13:42:56 +02:00
2023-07-29 19:56:00 +02:00
nix-instantiate \
--no-build-output --strict \
--eval '<home-manager/home-manager/build-news.nix>' \
--arg newsJsonFile "$newsJsonFile" \
--arg newsReadIdsFile "$readIdsFile" \
"${extraArgs[@]}" \
> "$newsNixFile"
2017-08-26 22:24:40 +02:00
}
function doShowNews() {
2018-07-31 13:42:56 +02:00
setWorkDir
2023-07-29 19:56:00 +02:00
setFlakeAttribute
2018-07-31 13:42:56 +02:00
2023-07-29 19:56:00 +02:00
local newsNixFile="$WORK_DIR/news.nix"
buildNews "$newsNixFile"
2017-08-26 22:24:40 +02:00
2023-07-29 19:56:00 +02:00
local readIdsFile
2024-04-23 18:52:19 +02:00
readIdsFile="$(newsReadIdsFile)"
2017-08-26 22:24:40 +02:00
2023-07-29 19:56:00 +02:00
local news
# shellcheck disable=2154,2046
2017-08-26 22:24:40 +02:00
case $1 in
--all)
2023-07-29 19:56:00 +02:00
news="$(nix-instantiate --quiet --eval --expr "(import ${newsNixFile}).news.all")"
2017-08-26 22:24:40 +02:00
;;
--unread)
2023-07-29 19:56:00 +02:00
news="$(nix-instantiate --quiet --eval --expr "(import ${newsNixFile}).news.unread")"
2017-08-26 22:24:40 +02:00
;;
*)
2021-04-30 01:29:39 +02:00
_i 'Unknown argument %s' "$1"
2017-08-26 22:24:40 +02:00
return 1
esac
2023-07-29 19:56:00 +02:00
# Prints the news without surrounding quotes.
echo -e "${news:1:-1}" | ${PAGER:-less}
local allIds
allIds="$(nix-instantiate --quiet --eval --expr "(import ${newsNixFile}).meta.ids")"
allIds="${allIds:1:-1}" # Trim surrounding quotes.
local readIdsFileNew="$WORK_DIR/news-read-ids.new"
{
cat "$readIdsFile"
echo -e "$allIds"
} | sort | uniq > "$readIdsFileNew"
mv -f "$readIdsFileNew" "$readIdsFile"
2017-08-26 22:24:40 +02:00
}
2019-04-28 00:33:41 +02:00
function doUninstall() {
2023-09-14 04:13:15 +02:00
setHomeManagerPathVariables
2021-11-10 19:23:33 +01:00
setNixProfileCommands
2019-04-28 00:33:41 +02:00
2021-04-30 01:29:39 +02:00
_i 'This will remove Home Manager from your system.'
2019-04-28 00:33:41 +02:00
if [[ -v DRY_RUN ]]; then
2021-04-30 01:29:39 +02:00
_i 'This is a dry run, nothing will actually be uninstalled.'
2019-04-28 00:33:41 +02:00
fi
local confirmation
2021-04-30 01:29:39 +02:00
read -r -n 1 -p "$(_i 'Really uninstall Home Manager?') [y/n] " confirmation
2019-04-28 00:33:41 +02:00
echo
2023-03-04 10:39:02 +01:00
# shellcheck disable=2086
2019-04-28 00:33:41 +02:00
case $confirmation in
y|Y)
2021-04-30 01:29:39 +02:00
_i "Switching to empty Home Manager configuration..."
2019-04-28 00:33:41 +02:00
HOME_MANAGER_CONFIG="$(mktemp --tmpdir home-manager.XXXXXXXXXX)"
2024-01-06 00:22:27 +01:00
cat > "$HOME_MANAGER_CONFIG" <<EOF
{
uninstall = true;
home.username = "$USER";
home.homeDirectory = "$HOME";
home.stateVersion = "23.11";
}
EOF
# shellcheck disable=2064
trap "rm '$HOME_MANAGER_CONFIG'" EXIT
doSwitch --switch
2019-04-28 00:33:41 +02:00
;;
*)
2023-03-04 10:39:02 +01:00
_i "Yay!"
exit 0
2019-04-28 00:33:41 +02:00
;;
esac
2021-04-30 01:29:39 +02:00
_i "Home Manager is uninstalled but your home.nix is left untouched."
2019-04-28 00:33:41 +02:00
}
2017-01-07 19:16:26 +01:00
function doHelp() {
2017-01-15 23:32:57 +01:00
echo "Usage: $0 [OPTION] COMMAND"
echo
echo "Options"
echo
2021-04-07 19:17:39 +02:00
echo " -f FILE The home configuration file."
echo " Default is '~/.config/nixpkgs/home.nix'."
echo " -A ATTRIBUTE Optional attribute that selects a configuration"
echo " expression in the configuration file."
echo " -I PATH Add a path to the Nix expression search path."
2022-01-02 08:31:07 +01:00
echo " --flake flake-uri Use Home Manager configuration at flake-uri"
2023-02-26 23:10:06 +01:00
echo " Default is '~/.config/home-manager'."
2021-04-07 19:17:39 +02:00
echo " -b EXT Move existing files to new path rather than fail."
echo " -v Verbose output"
echo " -n Do a dry run, only prints what actions would be taken"
echo " -h Print this help"
2022-01-02 08:31:07 +01:00
echo " --version Print the Home Manager version"
2017-01-07 19:16:26 +01:00
echo
2019-08-26 22:45:31 +02:00
echo "Options passed on to nix-build(1)"
echo
2021-03-31 19:40:37 +02:00
echo " --arg(str) NAME VALUE Override inputs passed to home-manager.nix"
2019-08-26 22:45:31 +02:00
echo " --cores NUM"
2021-06-06 00:11:06 +02:00
echo " --debug"
2021-06-20 09:19:55 +02:00
echo " --impure"
2019-08-26 22:45:31 +02:00
echo " --keep-failed"
echo " --keep-going"
2020-11-13 23:56:57 +01:00
echo " -j, --max-jobs NUM"
2019-08-30 00:52:09 +02:00
echo " --option NAME VALUE"
2022-12-25 07:48:45 +01:00
echo " -L, --print-build-logs"
2019-08-26 22:45:31 +02:00
echo " --show-trace"
2019-12-01 10:43:39 +01:00
echo " --(no-)substitute"
2021-07-26 14:58:26 +02:00
echo " --no-out-link Do not create a symlink to the output path"
2021-11-15 05:00:26 +01:00
echo " --no-write-lock-file"
2021-08-17 22:53:44 +02:00
echo " --builders VALUE"
2023-02-05 11:14:03 +01:00
echo " --refresh Consider all previously downloaded files out-of-date"
2019-08-26 22:45:31 +02:00
echo
2017-01-07 19:16:26 +01:00
echo "Commands"
2017-11-12 14:07:41 +01:00
echo
2017-01-12 22:26:24 +01:00
echo " help Print this help"
2017-11-12 14:07:41 +01:00
echo
2024-02-05 23:22:43 +01:00
echo " edit Open the home configuration in \$VISUAL or \$EDITOR"
2018-12-03 11:19:22 +01:00
echo
2020-08-21 07:53:03 +02:00
echo " option OPTION.NAME"
echo " Inspect configuration option named OPTION.NAME."
echo
2017-01-15 23:32:57 +01:00
echo " build Build configuration into result directory"
2017-11-12 14:07:41 +01:00
echo
2023-02-26 23:10:06 +01:00
echo " init [--switch] [DIR]"
echo " Initializes a configuration in the given directory. If the directory"
echo " does not exist, then it will be created. The default directory is"
echo " '~/.config/home-manager'."
echo
echo " --switch Immediately activate the generated configuration."
echo
2020-03-18 00:02:38 +01:00
echo " instantiate Instantiate the configuration and print the resulting derivation"
echo
2017-01-15 23:32:57 +01:00
echo " switch Build and activate configuration"
2017-11-12 14:07:41 +01:00
echo
2017-01-12 22:26:24 +01:00
echo " generations List all home environment generations"
2017-11-12 14:07:41 +01:00
echo
echo " remove-generations ID..."
echo " Remove indicated generations. Use 'generations' command to"
echo " find suitable generation numbers."
echo
2018-10-02 06:42:46 +02:00
echo " expire-generations TIMESTAMP"
echo " Remove generations older than TIMESTAMP where TIMESTAMP is"
echo " interpreted as in the -d argument of the date tool. For"
echo " example \"-30 days\" or \"2018-01-01\"."
echo
2017-01-12 22:26:24 +01:00
echo " packages List all packages installed in home-manager-path"
2017-11-12 14:07:41 +01:00
echo
2017-08-26 22:24:40 +02:00
echo " news Show news entries in a pager"
2019-04-28 00:33:41 +02:00
echo
echo " uninstall Remove Home Manager"
2017-01-07 19:16:26 +01:00
}
2017-02-14 18:25:30 +01:00
EXTRA_NIX_PATH=()
2017-08-17 10:16:27 +02:00
HOME_MANAGER_CONFIG_ATTRIBUTE=""
2019-06-09 01:47:43 +02:00
PASSTHROUGH_OPTS=()
COMMAND=""
COMMAND_ARGS=()
2021-04-07 19:17:39 +02:00
FLAKE_ARG=""
2017-01-15 23:32:57 +01:00
2019-06-09 01:47:43 +02:00
while [[ $# -gt 0 ]]; do
opt="$1"
shift
2017-01-15 23:32:57 +01:00
case $opt in
2023-02-26 23:10:06 +01:00
build|init|instantiate|option|edit|expire-generations|generations|help|news|packages|remove-generations|switch|uninstall)
2019-06-09 01:47:43 +02:00
COMMAND="$opt"
;;
-A)
2024-04-18 17:25:13 +02:00
[[ -v 1 && $1 != -* ]] || errMissingOptArg "$opt"
2019-06-09 01:47:43 +02:00
HOME_MANAGER_CONFIG_ATTRIBUTE="$1"
shift
2017-01-15 23:32:57 +01:00
;;
2019-06-09 01:47:43 +02:00
-I)
2024-04-18 17:25:13 +02:00
[[ -v 1 && $1 != -* ]] || errMissingOptArg "$opt"
2019-06-09 01:47:43 +02:00
EXTRA_NIX_PATH+=("$1")
shift
2017-02-14 18:25:30 +01:00
;;
2019-06-09 01:47:43 +02:00
-b)
2024-04-18 17:25:13 +02:00
[[ -v 1 && $1 != -* ]] || errMissingOptArg "$opt"
2019-06-09 01:47:43 +02:00
export HOME_MANAGER_BACKUP_EXT="$1"
shift
2017-08-17 10:16:27 +02:00
;;
2019-06-09 01:47:43 +02:00
-f|--file)
2024-04-18 17:25:13 +02:00
[[ -v 1 && $1 != -* ]] || errMissingOptArg "$opt"
2019-06-09 01:47:43 +02:00
HOME_MANAGER_CONFIG="$1"
shift
2019-04-17 21:15:38 +02:00
;;
2021-04-07 19:17:39 +02:00
--flake)
2024-04-18 17:25:13 +02:00
[[ -v 1 && $1 != -* ]] || errMissingOptArg "$opt"
2021-04-07 19:17:39 +02:00
FLAKE_ARG="$1"
shift
;;
2023-02-05 11:14:03 +01:00
--recreate-lock-file|--no-update-lock-file|--no-write-lock-file|--no-registries|--commit-lock-file|--refresh)
2021-04-07 19:17:39 +02:00
PASSTHROUGH_OPTS+=("$opt")
;;
--update-input)
2024-04-18 17:25:13 +02:00
[[ -v 1 && $1 != -* ]] || errMissingOptArg "$opt"
2021-04-07 19:17:39 +02:00
PASSTHROUGH_OPTS+=("$opt" "$1")
shift
;;
--override-input)
2024-04-18 17:25:13 +02:00
[[ -v 1 && $1 != -* ]] || errMissingOptArg "$opt"
[[ -v 2 && $2 != -* ]] || errMissingOptArg "$opt $1"
2021-04-07 19:17:39 +02:00
PASSTHROUGH_OPTS+=("$opt" "$1" "$2")
shift 2
;;
2022-02-12 19:50:51 +01:00
--experimental-features)
2024-04-18 17:25:13 +02:00
[[ -v 1 && $1 != -* ]] || errMissingOptArg "$opt"
2022-02-12 19:50:51 +01:00
PASSTHROUGH_OPTS+=("$opt" "$1")
shift
;;
--extra-experimental-features)
2024-04-18 17:25:13 +02:00
[[ -v 1 && $1 != -* ]] || errMissingOptArg "$opt"
2022-02-12 19:50:51 +01:00
PASSTHROUGH_OPTS+=("$opt" "$1")
shift
;;
2021-07-26 14:58:26 +02:00
--no-out-link)
NO_OUT_LINK=1
;;
2022-12-25 07:48:45 +01:00
-L|--print-build-logs)
PRINT_BUILD_LOGS=1
;;
2019-06-09 01:47:43 +02:00
-h|--help)
doHelp
2019-08-26 23:06:20 +02:00
exit 0
2017-01-21 12:27:50 +01:00
;;
2019-06-09 01:47:43 +02:00
-n|--dry-run)
2017-01-15 23:32:57 +01:00
export DRY_RUN=1
;;
2021-03-31 19:40:37 +02:00
--option|--arg|--argstr)
2024-04-18 17:25:13 +02:00
[[ -v 1 && $1 != -* ]] || errMissingOptArg "$opt"
[[ -v 2 ]] || errMissingOptArg "$opt $1"
2019-08-30 00:52:09 +02:00
PASSTHROUGH_OPTS+=("$opt" "$1" "$2")
shift 2
;;
2021-08-17 22:53:44 +02:00
-j|--max-jobs|--cores|--builders)
2024-04-18 17:25:13 +02:00
[[ -v 1 && $1 != -* ]] || errMissingOptArg "$opt"
2019-08-26 22:45:31 +02:00
PASSTHROUGH_OPTS+=("$opt" "$1")
shift
;;
2021-06-06 00:11:06 +02:00
--debug|--keep-failed|--keep-going|--show-trace\
2021-11-25 01:09:53 +01:00
|--substitute|--no-substitute|--impure)
2019-06-09 01:47:43 +02:00
PASSTHROUGH_OPTS+=("$opt")
;;
-v|--verbose)
export VERBOSE=1
2017-01-15 23:32:57 +01:00
;;
2020-11-03 23:10:21 +01:00
--version)
2024-01-06 00:16:14 +01:00
echo 24.05-pre
2020-11-03 23:10:21 +01:00
exit 0
;;
2017-01-15 23:32:57 +01:00
*)
2019-06-09 01:47:43 +02:00
case $COMMAND in
2023-02-26 23:10:06 +01:00
init|expire-generations|remove-generations|option)
2019-06-09 01:47:43 +02:00
COMMAND_ARGS+=("$opt")
;;
*)
2021-04-30 01:29:39 +02:00
_iError "%s: unknown option '%s'" "$0" "$opt" >&2
_i "Run '%s --help' for usage help" "$0" >&2
2019-06-09 01:47:43 +02:00
exit 1
;;
esac
2017-01-15 23:32:57 +01:00
;;
esac
done
2023-06-17 01:18:26 +02:00
setHomeManagerNixPath
2019-06-09 01:47:43 +02:00
if [[ -z $COMMAND ]]; then
2018-01-22 06:46:33 +01:00
doHelp >&2
exit 1
fi
2019-06-09 01:47:43 +02:00
case $COMMAND in
2018-12-03 11:19:22 +01:00
edit)
doEdit
;;
2017-01-11 22:55:31 +01:00
build)
2017-08-26 22:24:40 +02:00
doBuild
2017-01-11 22:55:31 +01:00
;;
2023-02-26 23:10:06 +01:00
init)
doInit "${COMMAND_ARGS[@]}"
;;
2020-03-18 00:02:38 +01:00
instantiate)
doInstantiate
;;
2017-01-11 22:58:55 +01:00
switch)
2017-05-20 23:39:54 +02:00
doSwitch
2017-01-07 19:16:26 +01:00
;;
generations)
doListGens
;;
2017-11-12 14:07:41 +01:00
remove-generations)
2019-06-09 01:47:43 +02:00
doRmGenerations "${COMMAND_ARGS[@]}"
2017-11-12 14:07:41 +01:00
;;
2018-10-02 06:42:46 +02:00
expire-generations)
2019-06-09 01:47:43 +02:00
if [[ ${#COMMAND_ARGS[@]} != 1 ]]; then
2021-04-30 01:29:39 +02:00
_i 'expire-generations expects one argument, got %d.' "${#COMMAND_ARGS[@]}" >&2
2019-06-09 01:47:43 +02:00
exit 1
else
doExpireGenerations "${COMMAND_ARGS[@]}"
fi
2018-10-02 06:42:46 +02:00
;;
2020-08-21 07:53:03 +02:00
option)
doInspectOption "${COMMAND_ARGS[@]}"
;;
2017-01-07 19:16:26 +01:00
packages)
doListPackages
;;
2017-08-26 22:24:40 +02:00
news)
doShowNews --all
;;
2019-04-28 00:33:41 +02:00
uninstall)
doUninstall
;;
2019-06-09 01:47:43 +02:00
help)
2017-01-07 19:16:26 +01:00
doHelp
;;
*)
2021-04-30 01:29:39 +02:00
_iError 'Unknown command: %s' "$COMMAND" >&2
2017-01-15 23:32:57 +01:00
doHelp >&2
2017-01-07 19:16:26 +01:00
exit 1
2017-01-08 22:08:17 +01:00
;;
2017-01-07 19:16:26 +01:00
esac
2021-07-26 14:58:26 +02:00
# vim: ft=bash