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-31 01:39:51 +03:00
|
|
|
# nix-channel --remove home-manager
|
2024-01-31 01:38:16 +03:00
|
|
|
|
2024-01-24 18:56:14 +03:00
|
|
|
nix-channel --add https://nixos.org/channels/nixos-unstable nixos
|
2024-01-31 01:39:51 +03:00
|
|
|
# nix-channel --add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager
|
2024-01-24 18:56:14 +03:00
|
|
|
|
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-31 03:32:45 +03:00
|
|
|
# Rebuild system.
|
2024-01-26 03:06:39 +03:00
|
|
|
# Optionally force the hostname.
|
2024-01-31 03:32:45 +03:00
|
|
|
# Usage: nix_rebuild [HOSTNAME]
|
|
|
|
function nix_rebuild() {
|
2024-01-26 03:06:39 +03:00
|
|
|
local target="${1}"
|
|
|
|
[[ "${target}" = "" ]] && target="${HOSTNAME}"
|
|
|
|
|
2024-01-30 22:23:58 +03:00
|
|
|
cd ${HOME}/.config/linux/system
|
2024-01-31 17:34:34 +03:00
|
|
|
nixos-rebuild boot --flake .#${target}
|
2024-01-31 03:32:45 +03:00
|
|
|
cd -
|
2024-01-24 19:06:50 +03:00
|
|
|
}
|
|
|
|
|
2024-02-03 00:04:38 +03:00
|
|
|
# Rebuild and switch system.
|
|
|
|
# Optionally force the hostname.
|
|
|
|
# Usage: nix_switch [HOSTNAME]
|
|
|
|
function nix_switch() {
|
|
|
|
local target="${1}"
|
|
|
|
[[ "${target}" = "" ]] && target="${HOSTNAME}"
|
|
|
|
|
|
|
|
cd ${HOME}/.config/linux/system
|
|
|
|
nixos-rebuild switch --flake .#${target}
|
|
|
|
cd -
|
|
|
|
}
|
|
|
|
|
2024-01-31 03:32:45 +03:00
|
|
|
# Update system.
|
2024-01-26 03:06:39 +03:00
|
|
|
# Optionally force the hostname.
|
2024-01-31 03:32:45 +03:00
|
|
|
# Usage: nix_update [HOSTNAME]
|
|
|
|
function nix_update() {
|
2024-01-26 03:06:39 +03:00
|
|
|
local target="${1}"
|
|
|
|
[[ "${target}" = "" ]] && target="${HOSTNAME}"
|
|
|
|
|
2024-01-30 22:23:58 +03:00
|
|
|
cd ${HOME}/.config/linux/system
|
2024-01-31 03:32:45 +03:00
|
|
|
nix flake update
|
|
|
|
cd -
|
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
|
2024-01-28 21:27:27 +03:00
|
|
|
_is_root && nix-store --gc
|
2024-01-24 19:42:52 +03:00
|
|
|
}
|
2024-01-24 23:58:03 +03:00
|
|
|
|
2024-01-28 20:57:01 +03:00
|
|
|
# Spawn shell with specified nix environment. `Main` is default.
|
|
|
|
# Usage: nix_shell [NAME]
|
2024-01-25 17:21:51 +03:00
|
|
|
function nix_shell() {
|
2024-01-28 20:57:01 +03:00
|
|
|
local name="${1,,}"
|
|
|
|
[[ "${name}" = "" ]] && name="main"
|
2024-01-25 17:21:51 +03:00
|
|
|
|
2024-01-28 20:57:01 +03:00
|
|
|
nix_shell="${name}" nix-shell ~/.config/linux/shell/"${name^}".nix
|
2024-01-24 23:58:03 +03:00
|
|
|
}
|
2024-01-28 21:27:27 +03:00
|
|
|
alias shell="nix_shell"
|
2024-01-28 21:21:35 +03:00
|
|
|
|
|
|
|
# Spawn nix-shell with specified packages.
|
2024-01-28 21:27:27 +03:00
|
|
|
# Usage: nix_tmpshell <PACKAGES>
|
|
|
|
function nix_tmpshell() {
|
2024-01-29 00:53:09 +03:00
|
|
|
local pkgs="${@}"
|
2024-01-28 21:21:35 +03:00
|
|
|
|
|
|
|
if [[ "${pkgs}" = "" ]]; then
|
2024-01-28 21:27:27 +03:00
|
|
|
help nix_tmpshell
|
2024-01-28 21:21:35 +03:00
|
|
|
return 2
|
|
|
|
fi
|
|
|
|
|
2024-01-29 02:53:42 +03:00
|
|
|
nix_shell="${1}" nix-shell -p ${pkgs}
|
2024-01-28 21:21:35 +03:00
|
|
|
}
|
2024-01-28 21:27:27 +03:00
|
|
|
alias tmpshell="nix_tmpshell"
|
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[@]}
|
|
|
|
}
|
|
|
|
|
2024-01-28 20:57:01 +03:00
|
|
|
# Autocomplete with available shells.
|
|
|
|
function _comp_shells() {
|
|
|
|
local IFS=$'\n'
|
|
|
|
local targets=($(ls ~/.config/linux/shell/ | sed -e "s/.nix$//" | tr '[:upper:]' '[:lower:]'))
|
|
|
|
|
|
|
|
_autocomplete_first ${targets[@]}
|
|
|
|
}
|
|
|
|
|
2024-01-26 03:06:39 +03:00
|
|
|
complete -F _comp_hosts nix_update nix_upgrade
|
2024-01-28 21:27:27 +03:00
|
|
|
complete -F _comp_shells nix_shell shell
|