chore: replace alias for updating packages with script

This commit is contained in:
Nico 2025-05-03 16:16:00 +10:00
parent d258e96b96
commit 3db7c1ad5b
2 changed files with 48 additions and 32 deletions

32
.envrc
View file

@ -1,32 +0,0 @@
# ~/.direnvrc
# Clear existing aliases when entering a directory
export tmpdir="$(mktemp -d -t dots-alias-direnv.XXXXXX)"
rm -rf "/tmp/dots-alias-direnv.*"
export_alias() {
# Create a new alias
local name=$1
shift
local alias_dir="$tmpdir/.envrc-aliases"
local alias_file="$alias_dir/$name"
local oldpath="$PATH"
# If this is the first time we're calling export_alias, add to PATH once
if ! [[ ":$PATH:" == *":$alias_dir:"* ]]; then
mkdir -p "$alias_dir"
PATH_add "$alias_dir"
fi
# Write the alias file
cat <<EOT >$alias_file
#!/usr/bin/env bash
PATH="$oldpath"
$@
EOT
chmod +x "$alias_file"
}
export_alias flakeup 'nix flake update && git commit flake.lock -m "nix: update flake sources to $(nix flake metadata --json | jq '.locks.nodes.nixpkgs.locked.rev' --raw-output | cut -c1-7)" && FLAKE=$PWD nh os switch'

48
conf.sh Executable file
View file

@ -0,0 +1,48 @@
#! /bin/sh
# basic scripts in for managing dotfiles and minor system tasks
update_packages() {
echo "updating packages"
# brew
if [ -f /opt/homebrew/bin/brew ]; then
echo "homebrew detected, updating..."
/opt/homebrew/bin/brew update
fi
# pkg (termux)
if which pkg > /dev/null; then
echo "pkg detected, updating..."
pkg update
pkg upgrade
fi
# nix flake
if which nix > /dev/null; then
echo "nix detected, updating..."
nix flake update
git commit flake.lock -m "nix: update flake sources to $(nix flake metadata --json | jq '.locks.nodes.nixpkgs.locked.rev' --raw-output | cut -c1-7)"
# rebuild and switch for nix and darwin systems
if which nixos-rebuild > /dev/null; then
echo "detected nixos system, rebuilding..."
sudo nixos-rebuild switch --flake .
elif which darwin-rebuild > /dev/null; then
echo "detected darwin system, rebuilding..."
darwin-rebuild switch --flake .
else
echo "didn't detect a nixos or darwin system, continuing..."
fi
fi
}
HELPTEXT="$0
usage:
update update packages on your system"
if [ "$1" = "update" ]; then
update_packages
else
echo "$HELPTEXT"
fi