fish: add nix_upgrade function

This commit is contained in:
Charles Gould 2021-12-14 22:23:38 -05:00
parent 56ca1b02dd
commit 2ee1f047a6
6 changed files with 33 additions and 4 deletions

View File

@ -0,0 +1,27 @@
function nix_upgrade --description "Upgrade nix packages"
# Step 1: Update Nixpkgs channel
nix-channel --update
# Step 2: Determine changes, if any
set --local nix_pkgs_filepath "$HOME/.config/nix/packages.nix"
set --local nix_pkgs_available (nix-env -qacf "$nix_pkgs_filepath" | grep -v ' = ' | string collect)
set --local nix_pkgs_installed (nix-env -qcf "$nix_pkgs_filepath" | grep -v ' = ' | string collect)
if test -z "$nix_pkgs_available" && test -z "$nix_pkgs_installed"
echo "All packages up-to-date."
return 0
end
set --local nix_pkgs_upd (echo $nix_pkgs_available | grep -v ' - \? ' | awk '{print $1}')
set --local nix_pkgs_add (echo $nix_pkgs_available | grep ' - \? ' | awk '{print $1}')
set --local nix_pkgs_rem (echo $nix_pkgs_installed | grep ' - \? ' | awk '{print $1}')
test -z "$nix_pkgs_add" || echo "Added packages: $nix_pkgs_add"
test -z "$nix_pkgs_upd" || echo "Outdated packages: $nix_pkgs_upd"
test -z "$nix_pkgs_rem" || echo "Removed packages: $nix_pkgs_rem"
# Step 3: Confirm changes
if confirm
nix-env -irf "$nix_pkgs_filepath"
end
end

View File

@ -1,7 +1,7 @@
function npm_upgrade --description "Upgrade npm packages"
set --local npm_pkgs_outdated (npm outdated -g | awk 'NR > 1 {print $1}')
if test (count $npm_pkgs_outdated) = 0
if test (count $npm_pkgs_outdated) -eq 0
echo "All packages up-to-date."
else
echo "Outdated packages: $npm_pkgs_outdated"

View File

@ -1,7 +1,7 @@
function pip_upgrade --description "Upgrade python packages"
set --local py_pkgs_outdated (python3 -m pip list --outdated | awk 'NR > 2 {print $1}')
if test (count $py_pkgs_outdated) = 0
if test (count $py_pkgs_outdated) -eq 0
echo "All packages up-to-date."
else
echo "Outdated packages: $py_pkgs_outdated"

View File

@ -6,7 +6,7 @@ ROOTDIR=$(cd "$(dirname "$0")/.." && pwd)
NIX_ENV="$HOME/.nix-profile/bin/nix-env"
if [ -x "$NIX_ENV" ]; then
"$NIX_ENV" --install --remove-all --file "$ROOTDIR/install/packages.nix"
"$NIX_ENV" --install --remove-all --file "$ROOTDIR/nix/packages.nix"
else
echo "Cannot install Nix packages! $NIX_ENV is not executable."
fi

View File

@ -19,6 +19,7 @@ mkdir -p "$HOME/.config"
backup_existing "$HOME/.bashrc"
backup_existing "$HOME/.config/fish"
backup_existing "$HOME/.config/kitty"
backup_existing "$HOME/.config/nix"
backup_existing "$HOME/.config/nvim"
backup_existing "$HOME/.config/git"
@ -26,6 +27,7 @@ backup_existing "$HOME/.config/git"
ln -fsv "$ROOTDIR/bash/.bashrc" "$HOME/.bashrc" # Bash does not support XDG config
ln -fsv "$ROOTDIR/fish" "$HOME/.config"
ln -fsv "$ROOTDIR/kitty" "$HOME/.config"
ln -fsv "$ROOTDIR/nix" "$HOME/.config"
ln -fsv "$ROOTDIR/nvim" "$HOME/.config"
ln -fsv "$ROOTDIR/git" "$HOME/.config"

View File

@ -1,6 +1,6 @@
# Moving toward a more declarative user environment...
# This "Nix expression" describes the set of packages I want in my user environment.
# Whenever it changes, run `nix-env -irf /path/to/packages.nix` to reinstall the environment.
# Whenever it changes, run `nix-env -irf ~/.config/nix/packages.nix` to reinstall the environment.
with import <nixpkgs> {}; [
bat