diff --git a/pkgs/default.nix b/pkgs/default.nix index ce16870..935206d 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -1 +1,15 @@ -final: prev: { } +final: prev: +with final; { + import-gtk-settings = writeShellScriptBin "import-gtk-settings" (import ./import-gtk-settings.nix final); + mailto-mutt = writeShellScriptBin "mailto-mutt" (import ./mailto-mutt.nix final); + mopidy-jellyfin = import ./mopidy-jellyfin.nix final; + mu = writeShellScriptBin "mu" (import ./mu.nix final); + psos = writeShellScriptBin "psos" (import ./psos.nix final); + s = writeShellScriptBin "s" (import ./s.nix final); + sway-launcher = writeScriptBin "sway-launcher" (import ./sway-launcher.nix final); + sway-service = writeShellScriptBin "sway-service" (import ./sway-service.nix final); + swaylock-bg = writeScriptBin "swaylock-bg" (import ./swaylock-bg.nix final); + toggle-kbd-layout = writeShellScriptBin "toggle-kbd-layout" (import ./toggle-kbd-layout.nix final); + uhk-agent = import ./uhk-agent.nix final; + wcwd = writeShellScriptBin "wcwd" (import ./wcwd.nix final); +} diff --git a/pkgs/import-gtk-settings.nix b/pkgs/import-gtk-settings.nix new file mode 100644 index 0000000..f4b12b9 --- /dev/null +++ b/pkgs/import-gtk-settings.nix @@ -0,0 +1,11 @@ +self: with self; '' + # usage: import-gsettings : : ... + + expression="" + for pair in "$@"; do + IFS=:; set -- $pair + expressions="$expressions -e 's/^$2=(.*)$/gsettings set org.gnome.desktop.interface $1 \1/e'" + done + IFS= + eval exec sed -E $expressions "$XDG_CONFIG_HOME"/gtk-3.0/settings.ini >/dev/null +'' diff --git a/pkgs/mailto-mutt.nix b/pkgs/mailto-mutt.nix new file mode 100644 index 0000000..a17d240 --- /dev/null +++ b/pkgs/mailto-mutt.nix @@ -0,0 +1,5 @@ +self: with self; '' + echo "$@" >> $XDG_CACHE_HOME/log/mailto.log + + exec ${alacritty}/bin/alacritty -e neomutt -- "$@" +'' diff --git a/pkgs/mopidy-jellyfin.nix b/pkgs/mopidy-jellyfin.nix new file mode 100644 index 0000000..8c99ac2 --- /dev/null +++ b/pkgs/mopidy-jellyfin.nix @@ -0,0 +1,29 @@ +self: with self; +let + websocket-client = python38.pkgs.buildPythonPackage rec { + pname = "websocket-client"; + version = "1.0.0"; + doCheck = false; + src = python38.pkgs.fetchPypi { + inherit pname version; + sha256 = "sha256-UFGzii9MJ/vXygd+uyPsaWWmJt7VqVY382vhs1tsT4E="; + }; + }; +in +python38.pkgs.buildPythonPackage rec { + pname = "Mopidy-Jellyfin"; + version = "1.0.2"; + doCheck = false; + propagatedBuildInputs = with python38.pkgs; [ + unidecode + websocket-client + requests + setuptools + pykka + mopidy + ]; + src = python38.pkgs.fetchPypi { + inherit pname version; + sha256 = "sha256-5XimIIQSpvNyQbSOFtSTkA0jhA0V68BbyQEQNnov+0g="; + }; +} diff --git a/pkgs/mu.nix b/pkgs/mu.nix new file mode 100644 index 0000000..90afaa4 --- /dev/null +++ b/pkgs/mu.nix @@ -0,0 +1,3 @@ +self: with self; '' + exec ${alacritty}/bin/alacritty --class mu_vimpc --option dimensions.columns=120 --option dimensions.lines=80 -e vimpc -- "$@" +'' diff --git a/pkgs/psos.nix b/pkgs/psos.nix new file mode 100644 index 0000000..a60bad6 --- /dev/null +++ b/pkgs/psos.nix @@ -0,0 +1,29 @@ +self: with self; '' + case $1 in + rebuild) + shift; + exec sudo nixos-rebuild switch --flake "/etc/nixos#installed-host" $@ + ;; + update) + shift; + cd /etc/nixos + git pull + exec nix flake update + ;; + option) + shift; + exec nixos-option -I nixpkgs=/etc/nixos/lib/compat $@ + ;; + *) + if [[ "$@" != "" ]]; then + echo "Unknown command: psos $@" + echo "" + fi + echo "Usage: psos [COMMAND]" + echo " rebuild Rebuild the configuration and switch to it" + echo " update Pull git and update flake.lock" + echo " option [path] See the current value for an option in the flake config. Example: psos option nix.nixPath" + exit 1 + ;; + esac +'' diff --git a/pkgs/s.nix b/pkgs/s.nix new file mode 100644 index 0000000..668d555 --- /dev/null +++ b/pkgs/s.nix @@ -0,0 +1,39 @@ +self: with self; '' + case $1 in + d) + shift; + URL="https://duckduckgo.com?q=$@" + ;; + no) + shift; + URL="https://search.nixos.org/options?query=$@" + ;; + np) + shift; + URL="https://search.nixos.org/packages?query=$@" + ;; + rs) + shift; + URL="https://doc.rust-lang.org/std/index.html?search=$@" + ;; + rsc) + shift; + URL="https://docs.rs/releases/search?query=$@" + ;; + mdn) + shift; + URL="https://developer.mozilla.org/en-US/search?q=$@" + ;; + w) + shift; + URL="https://en.wikipedia.org/w/index.php?search=$@" + ;; + *) + URL="https://search.b12f.io?q=$@" + ;; + esac + + + ${firefox-wayland}/bin/firefox --new-tab "$URL" + ${sway}/bin/swaymsg '[app_id="firefox"]' focus +'' diff --git a/pkgs/sway-launcher.nix b/pkgs/sway-launcher.nix new file mode 100644 index 0000000..afa09d0 --- /dev/null +++ b/pkgs/sway-launcher.nix @@ -0,0 +1,64 @@ +self: with self; '' + #!/usr/bin/env zsh + # terminal application launcher for sway, using fzf + # original command: + # Based on: https://github.com/swaywm/sway/issues/1367 + # bindsym $altkey+space exec termite --name=launcher -e \ + # "bash -c 'compgen -c | sort -u | fzf --no-extended --print-query | \ + # tail -n1 | xargs -r swaymsg -t command exec'" + + HIST_FILE="''${XDG_CACHE_HOME:-$HOME/.cache}/sway-launcher-history.txt" + + # Get shell command list + # This may include the occasional non-executable file + command_list=$({ whence -wm '*' | sed 's/:[^:]*$//' }) + + # read existing command history + if [ -f "$HIST_FILE" ]; then + command_history=$(cat "$HIST_FILE") + else + command_history="" + fi + + # search command list + command_str=$(printf "%s\n" "''${command_history}" "''${command_list}" | \ + sed -E 's/^[0-9]+ (.+)$/\1/' | \ + fzf --exact --no-extended --print-query --no-sort | \ + tail -n1) || exit 1 + + if [ "$command_str" = "" ]; then + exit 1 + fi + # echo "Command: $command_str" + + # using \E flag from perl regex + test "''${command_str#*\\E}" != "$command_str" && echo "command can't contain '\E'" + test "''${command_str#*\\E}" != "$command_str" && exit 1 + + # get full line from history (with count number) + hist_line=$(echo "$command_history" | grep -Pe "^[0-9]+ \Q$command_str\E$") + # echo "Hist Line: $hist_line" + + if [ "$hist_line" = "" ]; then + hist_count=1 + else + # Increment usage count + hist_count=$(echo "$hist_line" | sed -E 's/^([0-9]+) .+$/\1/') + hist_count=$((hist_count + 1)) + # delete line, to add updated later + # echo "Hist Before: $command_history" + command_history=$(echo "$command_history" | \ + grep --invert-match -Pe "^[0-9]+ \Q$command_str\E$") + # echo "Hist After: $command_history" + fi + + # update history + update_line="''${hist_count} ''${command_str}" + printf "%s\n" "''${update_line}" "''${command_history}" | \ + sort --numeric-sort --reverse > "$HIST_FILE" + # echo "$update_line" + + # execute command + echo "$command_str" + ${sway}/bin/swaymsg -t command exec "$command_str" +'' diff --git a/pkgs/sway-service.nix b/pkgs/sway-service.nix new file mode 100644 index 0000000..f0b97ee --- /dev/null +++ b/pkgs/sway-service.nix @@ -0,0 +1,6 @@ +self: with self; '' + # first import environment variables from the login manager + systemctl --user import-environment + # then start the service + exec systemctl --wait --user start sway.service +'' diff --git a/pkgs/swaylock-bg.nix b/pkgs/swaylock-bg.nix new file mode 100644 index 0000000..b55c32a --- /dev/null +++ b/pkgs/swaylock-bg.nix @@ -0,0 +1,20 @@ +self: with self; '' + # Dependencies: + # swaylock + + # Make sure we aren't running twice + RUNNING=$(ps -A | grep swaylock | wc -l) + if [ $RUNNING -ne 0 ]; then + exit 0 + fi + + IMAGE=$XDG_CONFIG_HOME/wallpaper.jpg + LOCKARGS="" + + for OUTPUT in `${sway}/bin/swaymsg -t get_outputs | jq -r '.[].name'` + do + LOCKARGS="''${LOCKARGS} --image ''${OUTPUT}:''${IMAGE}" + IMAGES="''${IMAGES} ''${IMAGE}" + done + exec ${swaylock}/bin/swaylock $LOCKARGS +'' diff --git a/pkgs/toggle-kbd-layout.nix b/pkgs/toggle-kbd-layout.nix new file mode 100644 index 0000000..0d837b0 --- /dev/null +++ b/pkgs/toggle-kbd-layout.nix @@ -0,0 +1,14 @@ +self: with self; '' + set -e + + current_layout=$(${sway}/bin/swaymsg -t get_inputs | ${jq}/bin/jq -r '.[] | select(.type == "keyboard") | .xkb_active_layout_index' | head -1) + total_layouts=$(${sway}/bin/swaymsg -t get_inputs | ${jq}/bin/jq -r '.[] | select(.type == "keyboard") | .xkb_layout_names | length' | head -1) + + next_layout=$(expr $current_layout + 1); + + if [ $next_layout -ge $total_layouts ]; then + next_layout=0; + fi + + ${sway}/bin/swaymsg input '*' xkb_switch_layout "$next_layout" +'' diff --git a/pkgs/uhk-agent.nix b/pkgs/uhk-agent.nix new file mode 100644 index 0000000..3143b05 --- /dev/null +++ b/pkgs/uhk-agent.nix @@ -0,0 +1,44 @@ +self: with self; +let + uhk-agent-bin = stdenv.mkDerivation rec { + pname = "uhk-agent-bin"; + version = "1.5.14"; + src = builtins.fetchurl { + url = "https://github.com/UltimateHackingKeyboard/agent/releases/download/v1.5.14/UHK.Agent-1.5.14-linux-x86_64.AppImage"; + sha256 = "sha256:1yzh4ixy0cqg02xf84vcqj3h67mkxyzs6jf1h935ay582n70nyqg"; + }; + phases = [ "installPhase" "patchPhase" ]; + installPhase = '' + mkdir -p $out/bin + cp $src $out/bin/uhk-agent + chmod +x $out/bin/uhk-agent + ''; + }; + + script = '' + #!${bash}/bin/bash + + ${appimage-run}/bin/appimage-run ${uhk-agent-bin}/bin/uhk-agent + ''; +in +stdenv.mkDerivation rec { + pname = "uhk-agent"; + version = "1.5.14"; + buildInputs = [ + bash + uhk-agent-bin + appimage-run + ]; + + phases = [ "buildPhase" "installPhase" "patchPhase" ]; + + buildPhase = '' + echo "${script}" >> uhk-agent + ''; + + installPhase = '' + mkdir -p $out/bin + cp uhk-agent $out/bin/uhk-agent + chmod +x $out/bin/uhk-agent + ''; +} diff --git a/pkgs/wcwd.nix b/pkgs/wcwd.nix new file mode 100644 index 0000000..e5ebcca --- /dev/null +++ b/pkgs/wcwd.nix @@ -0,0 +1,5 @@ +self: with self; '' + pid=$(${sway}/bin/swaymsg -t get_tree | jq '.. | select(.type?) | select(.type=="con") | select(.focused==true).pid') + ppid=$(pgrep --newest --parent ''${pid}) + readlink /proc/''${ppid}/cwd || echo $HOME +''