2024-01-24 17:05:52 +03:00
|
|
|
# Find Nix package path.
|
2024-01-24 18:49:45 +03:00
|
|
|
# Usage: nix_find <PACKAGE>
|
|
|
|
function nix_find() {
|
2024-01-24 17:05:52 +03:00
|
|
|
local IFS=$'\n'
|
|
|
|
local package="${1}"
|
|
|
|
|
|
|
|
if [[ "${package}" = "" ]]; then
|
|
|
|
help find_nix
|
|
|
|
return 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
local found=$(ls --classify /nix/store/ | grep "${package}".*/)
|
|
|
|
|
|
|
|
if [[ "${found}" != "" ]]; then
|
|
|
|
echo "/nix/store/${found%/}"
|
|
|
|
else
|
|
|
|
false
|
|
|
|
fi
|
|
|
|
}
|
2024-01-24 18:56:14 +03:00
|
|
|
|
|
|
|
# Switch to Unstable branch.
|
|
|
|
function nix_unstable() {
|
2024-01-25 19:45:47 +03:00
|
|
|
nix-channel --remove nixos
|
2024-01-24 18:56:14 +03:00
|
|
|
nix-channel --add https://nixos.org/channels/nixos-unstable nixos
|
2024-01-25 19:49:45 +03:00
|
|
|
nix-channel --update
|
2024-01-24 18:56:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
# Switch to Small Unstable branch (for server).
|
|
|
|
function nix_unstable_small() {
|
2024-01-25 19:45:47 +03:00
|
|
|
nix-channel --remove nixos
|
2024-01-24 18:56:14 +03:00
|
|
|
nix-channel --add https://nixos.org/channels/nixos-unstable-small nixos
|
2024-01-25 19:49:45 +03:00
|
|
|
nix-channel --update
|
2024-01-24 18:56:14 +03:00
|
|
|
}
|
|
|
|
|
2024-01-25 00:39:42 +03:00
|
|
|
# Display current channel.
|
|
|
|
function nix_channel() {
|
|
|
|
nix-channel --list
|
|
|
|
}
|
|
|
|
|
2024-01-24 19:06:50 +03:00
|
|
|
# Update system (rebuild).
|
2024-01-26 03:06:39 +03:00
|
|
|
# Optionally force the hostname.
|
|
|
|
# Usage: nix_update [HOSTNAME]
|
2024-01-24 18:56:14 +03:00
|
|
|
function nix_update() {
|
2024-01-26 03:06:39 +03:00
|
|
|
local target="${1}"
|
|
|
|
[[ "${target}" = "" ]] && target="${HOSTNAME}"
|
|
|
|
|
|
|
|
nixos-rebuild switch -I nixos-config=/root/.config/linux/system/${target}/Configuration.nix
|
2024-01-24 19:06:50 +03:00
|
|
|
}
|
|
|
|
|
2024-01-27 18:55:01 +03:00
|
|
|
# Upgrade system. Applies after reboot.
|
2024-01-26 03:06:39 +03:00
|
|
|
# Optionally force the hostname.
|
|
|
|
# Usage: nix_upgrade [HOSTNAME]
|
2024-01-24 19:06:50 +03:00
|
|
|
function nix_upgrade() {
|
2024-01-26 03:06:39 +03:00
|
|
|
local target="${1}"
|
|
|
|
[[ "${target}" = "" ]] && target="${HOSTNAME}"
|
|
|
|
|
2024-01-27 18:55:01 +03:00
|
|
|
nixos-rebuild boot --upgrade-all -I nixos-config=/root/.config/linux/system/${target}/Configuration.nix
|
2024-01-24 18:56:14 +03:00
|
|
|
}
|
2024-01-24 19:42:52 +03:00
|
|
|
|
|
|
|
# Free up root space.
|
|
|
|
function nix_clean() {
|
|
|
|
nix-collect-garbage -d
|
|
|
|
[[ "${UID}" = 0 ]] && nix-store --gc
|
|
|
|
}
|
2024-01-24 23:58:03 +03:00
|
|
|
|
2024-01-25 19:45:47 +03:00
|
|
|
# Spawn shell with nix environment, like LD support.
|
2024-01-25 17:21:51 +03:00
|
|
|
function nix_shell() {
|
|
|
|
nix-shell ~/.config/linux/Shell.nix
|
|
|
|
}
|
|
|
|
|
2024-01-24 23:58:03 +03:00
|
|
|
# Spawn temporary shell.
|
|
|
|
function shell() {
|
|
|
|
nix-shell -p "${@}"
|
|
|
|
}
|
2024-01-26 03:06:39 +03:00
|
|
|
|
|
|
|
# Autocomplete with available hosts.
|
|
|
|
function _comp_hosts() {
|
|
|
|
local IFS=$'\n'
|
|
|
|
local targets=($(ls --classify ~/.config/linux/system/ | grep /$ | sed -e "s/\/$//"))
|
|
|
|
|
|
|
|
_autocomplete_first ${targets[@]}
|
|
|
|
}
|
|
|
|
|
|
|
|
complete -F _comp_hosts nix_update nix_upgrade
|