diff --git a/flake.nix b/flake.nix index f082a14..3d821c9 100755 --- a/flake.nix +++ b/flake.nix @@ -51,68 +51,53 @@ home-manager.nixosModules.home-manager sops-nix.nixosModules.sops ]; + + # Helper function to create home-manager configuration + mkHomeManagerConfig = + { username, stateVersion }: + { + home-manager = { + useGlobalPkgs = true; + useUserPackages = true; + extraSpecialArgs = { inherit inputs; }; + users.${username} = mkHomeConfig { + inherit username stateVersion; + }; + }; + }; + + # Helper function to create a NixOS system configuration + mkSystem = + { hostPath, user, extraModules ? [ ] }: + nixpkgs.lib.nixosSystem { + specialArgs = { inherit inputs; }; + modules = commonModules ++ [ + hostPath + { inherit user; } + (mkHomeManagerConfig { + username = user; + stateVersion = "25.05"; + }) + ] ++ extraModules; + }; in { nixosConfigurations = { - laptop = nixpkgs.lib.nixosSystem { - specialArgs = { inherit inputs; }; - modules = commonModules ++ [ - ./hosts/laptop - { user = "none"; } - { - home-manager = { - useGlobalPkgs = true; - useUserPackages = true; - extraSpecialArgs = { inherit inputs; }; - users.none = mkHomeConfig { - username = "none"; - stateVersion = "25.05"; - }; - }; - } - ]; + laptop = mkSystem { + hostPath = ./hosts/laptop; + user = "none"; }; - VNPC-21 = nixpkgs.lib.nixosSystem { - specialArgs = { inherit inputs; }; - modules = commonModules ++ [ - ./hosts/vnpc-21 - { user = "odin"; } - nixos-hardware.nixosModules.lenovo-thinkpad-p53 - { - home-manager = { - useGlobalPkgs = true; - useUserPackages = true; - extraSpecialArgs = { - inherit inputs; - }; - users.odin = mkHomeConfig { - username = "odin"; - stateVersion = "25.05"; - }; - }; - } - ]; + VNPC-21 = mkSystem { + hostPath = ./hosts/vnpc-21; + user = "odin"; + extraModules = [ nixos-hardware.nixosModules.lenovo-thinkpad-p53 ]; }; - station = nixpkgs.lib.nixosSystem { - specialArgs = { inherit inputs; }; - modules = commonModules ++ [ - ./hosts/station - { user = "none"; } - { - home-manager = { - useGlobalPkgs = true; - useUserPackages = true; - extraSpecialArgs = { inherit inputs; }; - users.none = mkHomeConfig { - username = "none"; - stateVersion = "25.05"; - }; - }; - } - ]; + station = mkSystem { + hostPath = ./hosts/station; + user = "none"; }; }; diff --git a/modules/home-manager/cli/zsh/scripts/quote.sh b/modules/home-manager/cli/zsh/scripts/quote.sh index 2ae8e84..f540150 100755 --- a/modules/home-manager/cli/zsh/scripts/quote.sh +++ b/modules/home-manager/cli/zsh/scripts/quote.sh @@ -1,18 +1,18 @@ #!/bin/bash DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -len=$(cat $DIR/quotes | wc -l) +len=$(wc -l < "$DIR/quotes") len=$((len-5)) rand=$((RANDOM%len)) # while random line picked # is less than number of lines in quotes file # check if number is divisible by 4 -while [ $rand -lt $len ] +while [ "$rand" -lt "$len" ] do - if (( $rand % 4 == 0 )) + if (( rand % 4 == 0 )) then finish=$((rand+3)) - head -"$finish" $DIR/quotes | tail -3 + head -"$finish" "$DIR/quotes" | tail -3 break fi ((rand++)) diff --git a/modules/home-manager/desktop/bspwm/dotfiles/polybar-launch.sh b/modules/home-manager/desktop/bspwm/dotfiles/polybar-launch.sh index 79f3a41..9c73446 100755 --- a/modules/home-manager/desktop/bspwm/dotfiles/polybar-launch.sh +++ b/modules/home-manager/desktop/bspwm/dotfiles/polybar-launch.sh @@ -4,13 +4,13 @@ killall -q polybar # Wait until the processes have been shut down -while pgrep -u $UID -x polybar >/dev/null; do sleep 1; done +while pgrep -u "$UID" -x polybar >/dev/null; do sleep 1; done # Launch Polybar on all monitors -if type "xrandr"; then - for m in $(xrandr --query | grep " connected" | cut -d" " -f1); do - MONITOR=$m polybar --reload example & - done +if type xrandr >/dev/null 2>&1; then + while IFS= read -r monitor; do + MONITOR="$monitor" polybar --reload example & + done < <(xrandr --query | grep " connected" | cut -d" " -f1) else polybar --reload example & fi diff --git a/modules/home-manager/desktop/hyprland/config/waybar/modules/bru.sh b/modules/home-manager/desktop/hyprland/config/waybar/modules/bru.sh deleted file mode 100755 index 4f77c44..0000000 --- a/modules/home-manager/desktop/hyprland/config/waybar/modules/bru.sh +++ /dev/null @@ -1,4 +0,0 @@ - #!/usr/bin/ - zscroll -b "⮕ " "$(mpc current)" - text=$4 - print "{\"text\":\""text"\", \"percentage\":"use",\"tooltip\":\""tooltip"\", \"class\":\""class"\"}" diff --git a/modules/home-manager/desktop/hyprland/config/waybar/modules/session.sh b/modules/home-manager/desktop/hyprland/config/waybar/modules/session.sh index 8ada046..4bfe3cb 100755 --- a/modules/home-manager/desktop/hyprland/config/waybar/modules/session.sh +++ b/modules/home-manager/desktop/hyprland/config/waybar/modules/session.sh @@ -1,4 +1,4 @@ #!/bin/sh uptime=$(uptime | awk -F, '{sub(".*up ",x,$1);print $1}') -echo $uptime +echo "$uptime" diff --git a/modules/home-manager/desktop/hyprland/config/waybar/modules/weather.sh b/modules/home-manager/desktop/hyprland/config/waybar/modules/weather.sh index baec89c..b9d2cbc 100755 --- a/modules/home-manager/desktop/hyprland/config/waybar/modules/weather.sh +++ b/modules/home-manager/desktop/hyprland/config/waybar/modules/weather.sh @@ -3,12 +3,12 @@ cachedir=~/.cache/rbn cachefile=${0##*/}-$1 -if [ ! -d $cachedir ]; then - mkdir -p $cachedir +if [ ! -d "$cachedir" ]; then + mkdir -p "$cachedir" fi -if [ ! -f $cachedir/$cachefile ]; then - touch $cachedir/$cachefile +if [ ! -f "$cachedir/$cachefile" ]; then + touch "$cachedir/$cachefile" fi # Save current IFS @@ -17,24 +17,24 @@ SAVEIFS=$IFS IFS=$'\n' cacheage=$(($(date +%s) - $(stat -c '%Y' "$cachedir/$cachefile"))) -if [ $cacheage -gt 1740 ] || [ ! -s $cachedir/$cachefile ]; then - data=($(curl -s https://en.wttr.in/$1\?0qnT 2>&1)) - echo ${data[0]} | cut -f1 -d, > $cachedir/$cachefile - echo ${data[1]} | sed -E 's/^.{15}//' >> $cachedir/$cachefile - echo ${data[2]} | sed -E 's/^.{15}//' >> $cachedir/$cachefile +if [ "$cacheage" -gt 1740 ] || [ ! -s "$cachedir/$cachefile" ]; then + mapfile -t data < <(curl -s "https://en.wttr.in/$1?0qnT" 2>&1) + echo "${data[0]}" | cut -f1 -d, > "$cachedir/$cachefile" + echo "${data[1]}" | sed -E 's/^.{15}//' >> "$cachedir/$cachefile" + echo "${data[2]}" | sed -E 's/^.{15}//' >> "$cachedir/$cachefile" fi -weather=($(cat $cachedir/$cachefile)) +mapfile -t weather < "$cachedir/$cachefile" # Restore IFSClear IFS=$SAVEIFS -temperature=$(echo ${weather[2]} | sed -E 's/([[:digit:]])+\.\./\1 to /g') +temperature=$(echo "${weather[2]}" | sed -E 's/([[:digit:]])+\.\./\1 to /g') #echo ${weather[1]##*,} # https://fontawesome.com/icons?s=solid&c=weather -case $(echo ${weather[1]##*,} | tr '[:upper:]' '[:lower:]') in +case $(echo "${weather[1]##*,}" | tr '[:upper:]' '[:lower:]') in "clear" | "sunny") condition="" ;; @@ -76,4 +76,4 @@ esac #echo $temp $condition -echo -e "{\"text\":\""$temperature $condition"\", \"alt\":\""${weather[0]}"\", \"tooltip\":\""${weather[0]}: $temperature ${weather[1]}"\"}" +echo -e "{\"text\":\"$temperature $condition\", \"alt\":\"${weather[0]}\", \"tooltip\":\"${weather[0]}: $temperature ${weather[1]}\"}" diff --git a/modules/home-manager/desktop/hyprland/config/waybar/modules/zscroll2.sh b/modules/home-manager/desktop/hyprland/config/waybar/modules/zscroll2.sh deleted file mode 100755 index 9141450..0000000 --- a/modules/home-manager/desktop/hyprland/config/waybar/modules/zscroll2.sh +++ /dev/null @@ -1,5 +0,0 @@ -zscroll -b "♪ x" -d 0.3 \ - -M "mpc status" \ - -m "playing" "-b ' '" \ - -m "paused" "-b ' ' -s 0" \ - -u t "mpc current" diff --git a/modules/home-manager/desktop/hyprland/config/waybar/scripts/waybar-wttr.py b/modules/home-manager/desktop/hyprland/config/waybar/scripts/waybar-wttr.py index c7ac5c2..eeeb653 100755 --- a/modules/home-manager/desktop/hyprland/config/waybar/scripts/waybar-wttr.py +++ b/modules/home-manager/desktop/hyprland/config/waybar/scripts/waybar-wttr.py @@ -66,7 +66,7 @@ def format_time(time): def format_temp(temp): - return (hour['FeelsLikeC']+"°").ljust(3) + return (temp+"°").ljust(3) def format_chances(hour): diff --git a/modules/home-manager/desktop/hyprland/default.nix b/modules/home-manager/desktop/hyprland/default.nix index 98604e4..8aee9db 100755 --- a/modules/home-manager/desktop/hyprland/default.nix +++ b/modules/home-manager/desktop/hyprland/default.nix @@ -17,7 +17,9 @@ # Startup applications exec-once = [ "pypr" - "hyprpanel & ~/.config/hypr/random-wallpaper.sh & swaync" + "hyprpanel" + "~/.config/hypr/random-wallpaper.sh" + "swaync" "hyprctl setcursor Bibate-Modern-Ice 18" "dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP" "nm-applet --indicator" diff --git a/modules/home-manager/desktop/hyprland/scripts/random-wallpaper.sh b/modules/home-manager/desktop/hyprland/scripts/random-wallpaper.sh index c69c69a..f04165d 100755 --- a/modules/home-manager/desktop/hyprland/scripts/random-wallpaper.sh +++ b/modules/home-manager/desktop/hyprland/scripts/random-wallpaper.sh @@ -9,8 +9,8 @@ if [ ! -d "$WALLPAPER_DIR" ] || [ -z "$(ls -A "$WALLPAPER_DIR" 2>/dev/null)" ]; exit 1 fi -# Find all image files (follow symlinks with -L) -WALLPAPERS=($(find -L "$WALLPAPER_DIR" -type f \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" -o -iname "*.webp" -o -iname "*.gif" \) 2>/dev/null)) +# Find all image files (follow symlinks with -L) - use mapfile for efficiency +mapfile -t WALLPAPERS < <(find -L "$WALLPAPER_DIR" -type f \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" -o -iname "*.webp" -o -iname "*.gif" \) 2>/dev/null) # Check if any wallpapers were found if [ ${#WALLPAPERS[@]} -eq 0 ]; then diff --git a/scripts/flake-rebuild.sh b/scripts/flake-rebuild.sh index 8e14ae0..ad9ee2d 100755 --- a/scripts/flake-rebuild.sh +++ b/scripts/flake-rebuild.sh @@ -1,9 +1,10 @@ #!/usr/bin/env bash -if [ ! -z $1 ]; then - export HOST=$1 +if [ -n "$1" ]; then + HOST="$1" else - export HOST=$(hostname) + HOST=$(hostname) fi +export HOST -sudo nixos-rebuild --impure --flake .#$HOST switch +sudo nixos-rebuild --impure --flake ".#$HOST" switch