diff --git a/flake.nix b/flake.nix index 41135a7..53e4ce5 100644 --- a/flake.nix +++ b/flake.nix @@ -83,10 +83,10 @@ inherit system; }; in - with pkgs; { - formatter = nixpkgs-fmt; - devShells.default = mkShell { - buildInputs = [ + { + formatter = pkgs.nixpkgs-fmt; + devShells.default = pkgs.mkShell { + buildInputs = with pkgs; [ git git-crypt statix diff --git a/home/wm/addon/wallpaper.nix b/home/wm/addon/wallpaper.nix index f59862e..02f7ca0 100644 --- a/home/wm/addon/wallpaper.nix +++ b/home/wm/addon/wallpaper.nix @@ -1,8 +1,7 @@ -{ config, pkgs, ... }: +{ pkgs, ... }: let - pictures = "${config.xdg.userDirs.pictures}"; - change-wallpaper = "${pkgs.scripts}/bin/chpaper ${pictures}/Wallpapers"; - wallpaper-downloader = "${pkgs.scripts}/bin/wallhaven ${pictures}/Wallpapers"; + change-wallpaper = "${pkgs.setpaper}/bin/setpaper"; + wallpaper-downloader = "${pkgs.getpaper}/bin/getpaper"; in { systemd.user = { diff --git a/home/wm/hyprland/default.nix b/home/wm/hyprland/default.nix index d92ae8e..4a4dc6a 100644 --- a/home/wm/hyprland/default.nix +++ b/home/wm/hyprland/default.nix @@ -167,9 +167,9 @@ in "SUPER,i, exec, ${firefox}" "SUPER_SHIFT,i, exec, ${firefox} --private-window" - "SUPER_SHIFT,escape, exec, ${pkgs.scripts}/bin/power-menu" - "SUPER,f11, exec, ${pkgs.scripts}/bin/tmux-sessions" - "SUPER_SHIFT,y, exec, ${pkgs.scripts}/bin/youtube" + "SUPER_SHIFT,escape, exec, ${pkgs.misc-scripts}/bin/power-menu" + "SUPER,f11, exec, ${pkgs.misc-scripts}/bin/tmux-sessions" + "SUPER_SHIFT,y, exec, ${pkgs.youtube}/bin/youtube" "SUPER_SHIFT,b, exec, ${pkgs.rofi-bluetooth}/bin/rofi-bluetooth" "SUPER,escape, exec, ${loginctl} lock-session" diff --git a/packages/default.nix b/packages/default.nix index 669c963..89e6fa4 100644 --- a/packages/default.nix +++ b/packages/default.nix @@ -1,6 +1,9 @@ final: prev: { dracula-gtk = prev.callPackage ./dracula-gtk { }; - scripts = prev.callPackage ./scripts { }; + misc-scripts = prev.callPackage ./scripts/misc { }; + getpaper = prev.callPackage ./scripts/getpaper { }; + setpaper = prev.callPackage ./scripts/setpaper { }; + youtube = prev.callPackage ./scripts/youtube { }; rofi-bluetooth = prev.callPackage ./rofi-bluetooth { }; smc-manjari = prev.callPackage ./smc-manjari { }; smc-nupuram = prev.callPackage ./smc-nupuram { }; diff --git a/packages/scripts/chpaper.sh b/packages/scripts/chpaper.sh deleted file mode 100755 index 6ad1257..0000000 --- a/packages/scripts/chpaper.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh - -set -eu - -DIR="${1:-}" -if [ -z "$DIR" ]; then - echo "Usage: $0 " - exit 1 -fi - -random_paper() { - if [ -d "$DIR" ] ; then - find -L "${DIR}"/ -type f -regextype egrep -regex ".*\.(jpe?g|png)$" | shuf -n1 --random-source=/dev/urandom - elif [ -f "$DIR" ] ; then - echo "$DIR" - fi -} - -swww img \ - --transition-type any \ - --transition-step 2 \ - --transition-duration 2 \ - "$(random_paper)" - diff --git a/packages/scripts/getpaper/default.nix b/packages/scripts/getpaper/default.nix new file mode 100644 index 0000000..e9153d4 --- /dev/null +++ b/packages/scripts/getpaper/default.nix @@ -0,0 +1,30 @@ +{ lib +, stdenvNoCC +, makeWrapper +, curl +, envsubst +, jq +, libsecret +, +}: +stdenvNoCC.mkDerivation { + pname = "getpaper"; + version = "0.1"; + src = ./.; + + nativeBuildInputs = [ makeWrapper ]; + + installPhase = '' + runHook preInstall + + mkdir -p $out/bin + cp getpaper.sh $out/bin/getpaper + chmod +x $out/bin/getpaper + + runHook postInstall + ''; + + postInstall = '' + wrapProgram $out/bin/getpaper --prefix PATH : ${lib.makeBinPath [envsubst jq curl libsecret]} + ''; +} diff --git a/packages/scripts/wallhaven.sh b/packages/scripts/getpaper/getpaper.sh similarity index 87% rename from packages/scripts/wallhaven.sh rename to packages/scripts/getpaper/getpaper.sh index b9b8a7c..b5451dc 100755 --- a/packages/scripts/wallhaven.sh +++ b/packages/scripts/getpaper/getpaper.sh @@ -11,17 +11,23 @@ fi CURL_BASE_CMD="curl --silent ${API_KEY_HEADER}" -DIR="${1:-/tmp}" -mkdir -p "${DIR}" - CONFIG_DIR="${XDG_CONFIG_HOME:-${HOME}/.config}" CONFIG_FILE="${CONFIG_DIR}/wallpaper_config.json" if [ ! -e "${CONFIG_FILE}" ]; then - echo '{"tags":null,"categories":"100","purity":"100", "sorting":"random", "size":null, "ratios":null, "colors":null, "ai_filter":1, "range": "1M"}' | jq > "${CONFIG_FILE}" + echo '{"tags":null,"categories":"100","purity":"100", "sorting":"random", "size":null, "ratios":null, "colors":null, "ai_filter":1, "range": "1M", "dir":"~/Pictures/Wallpapers"}' | jq > "${CONFIG_FILE}" fi CONFIG="$(cat "${CONFIG_FILE}")" +DIR="$(echo "${CONFIG}" | jq -r '.dir // empty')" +if [ -z "${DIR}" ]; then + DIR="${XDG_PICTURES_DIR:-${HOME}/Pictures}/Wallpapers" + echo "Warning: wallpaper directory not set. using fallback directory ${DIR}" >&2 +fi + +DIR="$(echo "${DIR}" | envsubst)" +mkdir -p "${DIR}" + AI_FILTER="$(echo "${CONFIG}" | jq -r '.ai_filter // empty')" if [ -n "${AI_FILTER}" ]; then AI_FILTER="ai_art_filter=${AI_FILTER}&" @@ -38,7 +44,7 @@ if [ -n "${CATEGORIES}" ]; then fi PURITY="$(echo "${CONFIG}" | jq -r '.purity // empty')" -if [ -n "${PURITY}" ]; then +if [ -n "${PURITY}" ] && [ -n "${API_KEY_HEADER}" ]; then PURITY="purity=${PURITY}&" fi diff --git a/packages/scripts/default.nix b/packages/scripts/misc/default.nix similarity index 53% rename from packages/scripts/default.nix rename to packages/scripts/misc/default.nix index 0a4c581..a752110 100644 --- a/packages/scripts/default.nix +++ b/packages/scripts/misc/default.nix @@ -1,22 +1,16 @@ { lib , stdenvNoCC , makeWrapper -, curl , hyprland -, jq , kitty , libnotify -, libsecret , rofi-wayland -, swww , tmux -, ueberzugpp -, ytfzf , }: stdenvNoCC.mkDerivation { - pname = "scripts"; - version = "1.0"; + pname = "misc-scripts"; + version = "0.1"; src = ./.; nativeBuildInputs = [ makeWrapper ]; @@ -32,23 +26,11 @@ stdenvNoCC.mkDerivation { cp tmux-sessions.sh $out/bin/tmux-sessions chmod +x $out/bin/tmux-sessions - cp chpaper.sh $out/bin/chpaper - chmod +x $out/bin/chpaper - - cp wallhaven.sh $out/bin/wallhaven - chmod +x $out/bin/wallhaven - - cp youtube.sh $out/bin/youtube - chmod +x $out/bin/youtube - runHook postInstall ''; postInstall = '' wrapProgram $out/bin/power-menu --prefix PATH : ${lib.makeBinPath [libnotify rofi-wayland hyprland]} wrapProgram $out/bin/tmux-sessions --prefix PATH : ${lib.makeBinPath [tmux kitty rofi-wayland]} - wrapProgram $out/bin/chpaper --prefix PATH : ${lib.makeBinPath [swww]} - wrapProgram $out/bin/wallhaven --prefix PATH : ${lib.makeBinPath [jq curl libsecret]} - wrapProgram $out/bin/youtube --prefix PATH : ${lib.makeBinPath [kitty ytfzf rofi-wayland ueberzugpp]} ''; } diff --git a/packages/scripts/power-menu.sh b/packages/scripts/misc/power-menu.sh similarity index 100% rename from packages/scripts/power-menu.sh rename to packages/scripts/misc/power-menu.sh diff --git a/packages/scripts/tmux-sessions.sh b/packages/scripts/misc/tmux-sessions.sh similarity index 100% rename from packages/scripts/tmux-sessions.sh rename to packages/scripts/misc/tmux-sessions.sh diff --git a/packages/scripts/setpaper/default.nix b/packages/scripts/setpaper/default.nix new file mode 100644 index 0000000..732fd6c --- /dev/null +++ b/packages/scripts/setpaper/default.nix @@ -0,0 +1,29 @@ +{ lib +, stdenvNoCC +, makeWrapper +, envsubst +, jq +, swww +, +}: +stdenvNoCC.mkDerivation { + pname = "setpaper"; + version = "0.1"; + src = ./.; + + nativeBuildInputs = [ makeWrapper ]; + + installPhase = '' + runHook preInstall + + mkdir -p $out/bin + cp setpaper.sh $out/bin/setpaper + chmod +x $out/bin/setpaper + + runHook postInstall + ''; + + postInstall = '' + wrapProgram $out/bin/setpaper --prefix PATH : ${lib.makeBinPath [envsubst jq swww]} + ''; +} diff --git a/packages/scripts/setpaper/setpaper.sh b/packages/scripts/setpaper/setpaper.sh new file mode 100755 index 0000000..632ec9d --- /dev/null +++ b/packages/scripts/setpaper/setpaper.sh @@ -0,0 +1,36 @@ +#!/bin/sh + +set -eu + +CONFIG_DIR="${XDG_CONFIG_HOME:-${HOME}/.config}" +CONFIG_FILE="${CONFIG_DIR}/wallpaper_config.json" +if [ ! -e "${CONFIG_FILE}" ]; then + echo "Wallpaper config file: ${CONFIG_FILE} missing." >&2 + exit 1 +fi + +CONFIG="$(cat "${CONFIG_FILE}")" + +DIR="$(echo "${CONFIG}" | jq -r '.dir // empty')" +if [ -z "${DIR}" ]; then + DIR="${XDG_PICTURES_DIR:-${HOME}/Pictures}/Wallpapers" + echo "Warning: wallpaper directory not set. using fallback directory ${DIR}" >&2 +fi +DIR="$(echo "${DIR}" | envsubst)" +mkdir -p "${DIR}" + +random_paper() { + if [ -d "$DIR" ] ; then + find -L "${DIR}"/ -type f -regextype egrep -regex ".*\.(jpe?g|png)$" | shuf -n1 --random-source=/dev/urandom + else + echo "${DIR} is not a directory" >&2 + exit 1 + fi +} + +swww img \ + --transition-type any \ + --transition-step 2 \ + --transition-duration 2 \ + "$(random_paper)" + diff --git a/packages/scripts/youtube/default.nix b/packages/scripts/youtube/default.nix new file mode 100644 index 0000000..0db9d3c --- /dev/null +++ b/packages/scripts/youtube/default.nix @@ -0,0 +1,31 @@ +{ lib +, stdenvNoCC +, makeWrapper +, kitty +, rofi-wayland +, ueberzugpp +, ytfzf +, +}: +stdenvNoCC.mkDerivation { + pname = "youtube"; + version = "0.1"; + src = ./.; + + nativeBuildInputs = [ makeWrapper ]; + + installPhase = '' + runHook preInstall + + mkdir -p $out/bin + + cp youtube.sh $out/bin/youtube + chmod +x $out/bin/youtube + + runHook postInstall + ''; + + postInstall = '' + wrapProgram $out/bin/youtube --prefix PATH : ${lib.makeBinPath [kitty ytfzf rofi-wayland ueberzugpp]} + ''; +} diff --git a/packages/scripts/youtube.sh b/packages/scripts/youtube/youtube.sh similarity index 100% rename from packages/scripts/youtube.sh rename to packages/scripts/youtube/youtube.sh