Nix : Cleanup.

This commit is contained in:
Dmitry Voronin 2024-02-08 06:36:40 +03:00
parent f3a7815971
commit 3f7ce3a1a6
2 changed files with 10 additions and 47 deletions

View file

@ -1,23 +1,3 @@
# Find Nix package path.
# Usage: nix_find <PACKAGE>
function nix_find() {
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
}
# Rebuild system. # Rebuild system.
# Optionally force the hostname. # Optionally force the hostname.
# Usage: nix_rebuild [HOSTNAME] # Usage: nix_rebuild [HOSTNAME]
@ -26,7 +6,7 @@ function nix_rebuild() {
[[ "${target}" = "" ]] && target="${HOSTNAME}" [[ "${target}" = "" ]] && target="${HOSTNAME}"
cd ${HOME}/.config/linux/system cd ${HOME}/.config/linux/system
nixos-rebuild boot --flake .#${target} nixos-rebuild boot --flake ".#${target}"
cd - cd -
} }
@ -37,19 +17,15 @@ function nix_switch() {
local target="${1}" local target="${1}"
[[ "${target}" = "" ]] && target="${HOSTNAME}" [[ "${target}" = "" ]] && target="${HOSTNAME}"
cd ${HOME}/.config/linux/system cd "${HOME}/.config/linux/system"
nixos-rebuild switch --flake .#${target} nixos-rebuild switch --flake ".#${target}"
cd - cd -
} }
# Update system. # Update system versions.
# Optionally force the hostname. # Usage: nix_update
# Usage: nix_update [HOSTNAME]
function nix_update() { function nix_update() {
local target="${1}" cd "${HOME}/.config/linux/system"
[[ "${target}" = "" ]] && target="${HOSTNAME}"
cd ${HOME}/.config/linux/system
nix flake update nix flake update
cd - cd -
} }
@ -64,13 +40,10 @@ function nix_clean() {
# Uses flake.nix in current dir by default. # Uses flake.nix in current dir by default.
# Usage: nix_shell [NAME] # Usage: nix_shell [NAME]
function nix_shell() { function nix_shell() {
local name="${1,,}" local target="${1}"
[[ "${target}" = "" ]] && target="default"
if [[ "${name}" = "" ]]; then NIX_SHELL="${target}" nix develop ".#${target}"
NIX_SHELL=$(parse_alnum "${PWD##*/}") nix develop
else
NIX_SHELL="${name}" nix develop -f ~/.config/linux/shell/"${name^}".nix
fi
} }
alias shell="nix_shell" alias shell="nix_shell"
@ -102,13 +75,4 @@ function _comp_hosts() {
_autocomplete_first ${targets[@]} _autocomplete_first ${targets[@]}
} }
# Autocomplete with available shells. complete -F _comp_hosts nix_switch nix_rebuild
function _comp_shells() {
local IFS=$'\n'
local targets=($(ls ~/.config/linux/shell/ | sed -e "s/.nix$//" | tr '[:upper:]' '[:lower:]'))
_autocomplete_first ${targets[@]}
}
complete -F _comp_hosts nix_update nix_switch nix_rebuild
complete -F _comp_shells nix_shell shell

View file

@ -1 +0,0 @@
Use flakes here with devShell