From 2def0940226ff35594b56b2c08e24af6080cce61 Mon Sep 17 00:00:00 2001 From: krizej Date: Tue, 6 Aug 2024 13:41:05 +0200 Subject: [PATCH] mpd 1 --- hosts/desktop/default.nix | 2 ++ hosts/laptop/default.nix | 1 + modules/default.nix | 2 ++ modules/stuff/i3.nix | 62 +++++++++++++++++++++++++-------------- modules/stuff/mpd.nix | 42 ++++++++++++++++++++++++++ modules/stuff/xdg.nix | 4 ++- 6 files changed, 90 insertions(+), 23 deletions(-) create mode 100644 modules/stuff/mpd.nix diff --git a/hosts/desktop/default.nix b/hosts/desktop/default.nix index 6dd5be0..0921a26 100644 --- a/hosts/desktop/default.nix +++ b/hosts/desktop/default.nix @@ -52,6 +52,7 @@ }; home-manager.enable = true; + xdg.enable = true; stuff = { xserver.enable = true; @@ -67,6 +68,7 @@ documentation.enable = true; theme.enable = true; printing.enable = true; + mpd.enable = true; autorandr = { enable = true; diff --git a/hosts/laptop/default.nix b/hosts/laptop/default.nix index 221d7a3..5dbc7e5 100644 --- a/hosts/laptop/default.nix +++ b/hosts/laptop/default.nix @@ -51,6 +51,7 @@ documentation.enable = true; theme.enable = true; printing.enable = true; + xdg.enable = true; xserver = { enable = true; diff --git a/modules/default.nix b/modules/default.nix index ed98c87..14d0f1a 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -22,5 +22,7 @@ ./stuff/gaming.nix ./stuff/other-desktop-programs.nix ./stuff/other-dev-programs.nix + ./stuff/mpd.nix + ./stuff/xdg.nix ]; } \ No newline at end of file diff --git a/modules/stuff/i3.nix b/modules/stuff/i3.nix index fa2b430..c4a3653 100644 --- a/modules/stuff/i3.nix +++ b/modules/stuff/i3.nix @@ -68,14 +68,6 @@ in { size = 10.0; }; - bars = [ - { - inherit fonts; - trayOutput = "primary"; - statusCommand = "${pkgs.i3status}/bin/i3status"; - } - ]; - defaultWorkspace = "workspace number 1"; workspaceOutputAssign = lib.mapAttrsToList @@ -90,7 +82,6 @@ in { startup = [ { command = "autotiling &"; notification = false; } - # { command = "mpd &"; notification = false; } ] ++ optionals config.chuj.stuff.dunst.enable [{ command = "dunst &"; notification = false; }] ++ optionals config.chuj.stuff.flameshot.enable [{ command = "flameshot &"; notification = false; }] @@ -98,6 +89,16 @@ in { { command = "i3-msg \"workspace ${cfg.communicators.workspace}; append_layout ${../../files/i3_communicators_layout.json}\""; notification = false; } { command = "discord &"; notification = false; } { command = "element-desktop &"; notification = false; } + ] + ++ optionals config.chuj.stuff.mpd.enable [ + { command = "${pkgs.writeShellScriptBin "mpdstatus" '' + while true; do + status=$(mpc status | sed -n 2p | cut -d' ' -f1) + title=$(basename "$(mpc current -f '%file%')" .mp3) + echo "$status $title" > /tmp/i3-mpd-status-stuff + sleep 1 + done + ''}/bin/mpdstatus &"; notification = false; } ]; modes = let @@ -119,7 +120,7 @@ in { mod = modifier; execns = "exec --no-startup-id"; cmd_and_center = cmd: "${execns} i3-msg '${cmd}' && i3custom-center-mouse-on-focus"; - in { + in mergeAttrs { # Program keybinds "${mod}+Return" = ''${execns} ${if config.chuj.stuff.alacritty.enable then "alacritty" else "i3-sensible-terminal"}''; "${mod}+Shift+s" = mkIf config.chuj.stuff.flameshot.enable "${execns} flameshot gui"; @@ -132,17 +133,6 @@ in { "Ctrl+F10" = "${execns} pamixer --decrease 5"; "Ctrl+F11" = "${execns} pamixer --increase 5"; - # MPD controls - # "Ctrl+F5" = "exec ~/music/select_music.sh"; - # "Ctrl+F6" = "exec mpc prev"; - # "Ctrl+F7" = "exec mpc toggle"; - # "Ctrl+F8" = "exec mpc next"; - # "Ctrl+Shift+F6" = "exec mpc seek -3"; - # "Ctrl+Shift+F7" = "exec mpc clear"; - # "Ctrl+Shift+F8" = "exec mpc seek +3"; - # "Ctrl+Shift+F10" = ''exec mpc volume -5 && dunstify "mpc $(mpc volume)" -r 420''; - # "Ctrl+Shift+F11" = ''exec mpc volume +5 && dunstify "mpc $(mpc volume)" -r 420''; - # General i3 keybindings "${mod}+f" = cmd_and_center "fullscreen toggle"; "${mod}+r" = "mode resize"; @@ -189,7 +179,26 @@ in { "${mod}+Shift+8" = cmd_and_center "move container to workspace number 8"; "${mod}+Shift+9" = cmd_and_center "move container to workspace number 9"; "${mod}+Shift+0" = cmd_and_center "move container to workspace number 10"; - }; + } (optionalAttrs config.chuj.stuff.mpd.enable { + # MPD controls + "Ctrl+F5" = "exec mpdfdial.sh"; + "Ctrl+F6" = "exec mpc prev"; + "Ctrl+F7" = "exec mpc toggle"; + "Ctrl+F8" = "exec mpc next"; + "Ctrl+Shift+F6" = "exec mpc seek -3"; + "Ctrl+Shift+F7" = "exec mpc clear"; + "Ctrl+Shift+F8" = "exec mpc seek +3"; + "Ctrl+Shift+F10" = ''exec mpc volume -5 && dunstify "mpc $(mpc volume)" -r 420''; + "Ctrl+Shift+F11" = ''exec mpc volume +5 && dunstify "mpc $(mpc volume)" -r 420''; + }); + + bars = [ + { + inherit fonts; + trayOutput = "primary"; + statusCommand = "${pkgs.i3status}/bin/i3status"; + } + ]; }; }; @@ -209,6 +218,15 @@ in { modules = mergeAttrs { # todo MPD module (using read_file most likely, or switch to i3blocks) + "read_file mpd" = { + position = -1; + settings = { + format = "%content"; + path = "/tmp/i3-mpd-status-stuff"; + color_good = "#ffffff"; + }; + }; + "cpu_usage" = { position = 0; settings = { diff --git a/modules/stuff/mpd.nix b/modules/stuff/mpd.nix new file mode 100644 index 0000000..6cba934 --- /dev/null +++ b/modules/stuff/mpd.nix @@ -0,0 +1,42 @@ +{ lib, pkgs, config, ...}: let + inherit (lib) mkIf mkEnableOption mkOption; + cfg = config.chuj.stuff.mpd; + user = config.chuj.system.user; +in { + options.chuj.stuff.mpd = { + enable = mkEnableOption "mpd"; + }; + + config = mkIf cfg.enable { + home-manager.users.${user} = { + services.mpd = { + enable = true; + extraConfig = '' + audio_output { + type "pulse" + name "PulseAudio Output" + } + ''; + }; + home.packages = let + yad = "${pkgs.yad}/bin/yad"; + dunstify = "${pkgs.dunst}/bin/dunstify"; + mpc = "${pkgs.mpc-cli}/bin/mpc"; + cut = "${pkgs.coreutils}/bin/cut"; + in [ + pkgs.mpc-cli + (pkgs.writeShellScriptBin "mpdfdial.sh" '' + path=$(${yad} --file --directory | ${cut} -d "/" -f5-) + + ${dunstify} "playing from \"$path\"" + ${mpc} update + ${mpc} rescan + ${mpc} add "$path" + ${mpc} random on + ${mpc} repeat on + ${mpc} play + '') + ]; + }; + }; +} diff --git a/modules/stuff/xdg.nix b/modules/stuff/xdg.nix index 90e7ae7..905615d 100644 --- a/modules/stuff/xdg.nix +++ b/modules/stuff/xdg.nix @@ -1,6 +1,7 @@ { lib, pkgs, config, ...}: let inherit (lib) mkIf mkEnableOption mkOption; cfg = config.chuj.xdg; + user = config.chuj.system.user; in { options.chuj.xdg = { enable = mkEnableOption "xdg"; @@ -37,11 +38,12 @@ in { }; }; - home.sessionVariables = { + home.sessionVariables = let XDG_DATA_HOME = hmCfg.xdg.dataHome; XDG_CONFIG_HOME = hmCfg.xdg.configHome; XDG_STATE_HOME = hmCfg.xdg.stateHome; XDG_CACHE_HOME = hmCfg.xdg.cacheHome; + in { ANDROID_USER_HOME = "${XDG_DATA_HOME}/android"; ANDROID_HOME = "${XDG_DATA_HOME}/android/sdk"; GRADLE_USER_HOME = "${XDG_DATA_HOME}/gradle";