diff --git a/config/Ollama.nix b/config/Ollama.nix index 31146367..b39e1790 100644 --- a/config/Ollama.nix +++ b/config/Ollama.nix @@ -10,45 +10,45 @@ in { config = lib.mkIf cfg.enable { # Specify default model. - environment.variables.OLLAMA_MODEL = cfg.primaryModel; - - systemd.services = { - # Enable Ollama server. - ollama = { - description = "Ollama LLM server"; - serviceConfig = { - Type = "simple"; - }; - wantedBy = [ - "multi-user.target" - ]; - script = '' - HOME=/root ${lib.getExe pkgsUnstable.ollama} serve - ''; - }; - - # Download Ollama models. - ollama-pull = { - description = "Ollama LLM model"; - after = [ - "NetworkManager-wait-online.service" - "ollama.service" - ]; - wantedBy = [ - "multi-user.target" - ]; - wants = [ - "NetworkManager-wait-online.service" - "ollama.service" - ]; - serviceConfig = { - Type = "simple"; - }; - script = util.trimTabs '' - sleep 5 - ${lib.getExe pkgsUnstable.ollama} pull ${lib.concatStringsSep " " cfg.models} - ''; - }; - }; + # environment.variables.OLLAMA_MODEL = cfg.primaryModel; + # + # systemd.services = { + # # Enable Ollama server. + # ollama = { + # description = "Ollama LLM server"; + # serviceConfig = { + # Type = "simple"; + # }; + # wantedBy = [ + # "multi-user.target" + # ]; + # script = '' + # HOME=/root ${lib.getExe pkgsUnstable.ollama} serve + # ''; + # }; + # + # # Download Ollama models. + # ollama-pull = { + # description = "Ollama LLM model"; + # after = [ + # "NetworkManager-wait-online.service" + # "ollama.service" + # ]; + # wantedBy = [ + # "multi-user.target" + # ]; + # wants = [ + # "NetworkManager-wait-online.service" + # "ollama.service" + # ]; + # serviceConfig = { + # Type = "simple"; + # }; + # script = util.trimTabs '' + # sleep 5 + # ${lib.getExe pkgsUnstable.ollama} pull ${lib.concatStringsSep " " cfg.models} + # ''; + # }; + # }; }; } diff --git a/home/file/mako/default.nix b/home/file/mako/default.nix index 8d383a46..e5b803bc 100644 --- a/home/file/mako/default.nix +++ b/home/file/mako/default.nix @@ -3,7 +3,8 @@ config, pkgs, ... -}: let +} @args: let + swayscript = pkgs.callPackage args; alpha = config.module.style.opacity.hex; color = config.module.style.color; max = 3; @@ -20,7 +21,7 @@ in { margin = 32; max-history = max; max-visible = max; - on-notify = "exec swayscript notify"; + on-notify = "exec ${swayscript}/bin/swayscript notify"; text-color = "#${config.module.style.color.bg.dark}"; width = 480; }; diff --git a/home/file/sway/module/System.nix b/home/file/sway/module/System.nix index bd51c893..af2ca1c1 100644 --- a/home/file/sway/module/System.nix +++ b/home/file/sway/module/System.nix @@ -4,6 +4,7 @@ in { text = '' bindsym ${mod} input * xkb_switch_layout 0 + bindsym --to-code ${mod}+a exec 'swayscript network' bindsym --to-code ${mod}+c exec 'systemctl reboot -i' bindsym --to-code ${mod}+g exec 'swayscript gaming' bindsym --to-code ${mod}+l exec 'powerlimit toggle' diff --git a/home/file/sway/module/Waybar.nix b/home/file/sway/module/Waybar.nix index d846516a..630ba9a0 100644 --- a/home/file/sway/module/Waybar.nix +++ b/home/file/sway/module/Waybar.nix @@ -2,7 +2,5 @@ text = '' bindsym --to-code $mod+shift+r exec 'pkill waybar || exec waybar' exec waybar - exec nm-applet - exec blueman-applet ''; } diff --git a/home/file/waybar/config/default.nix b/home/file/waybar/config/default.nix index 8a7c6d9e..a11fd4b1 100644 --- a/home/file/waybar/config/default.nix +++ b/home/file/waybar/config/default.nix @@ -32,6 +32,7 @@ in { "group/batteryinfo" "group/hardware" "custom/display" + "custom/network" "tray" ]; "sway/workspaces" = { @@ -186,6 +187,15 @@ in { return-type = "json"; signal = 4; }; + "custom/network" = { + exec = "swayscript networkwidget"; + # interval = refreshInterval; + on-click = "blueman-manager"; + on-click-middle = "swayscript network"; + on-click-right = "nm-connection-editor"; + return-type = "json"; + signal = 7; + }; "custom/taghw1" = { exec = "echo ​"; }; diff --git a/home/file/waybar/style/Plugin.nix b/home/file/waybar/style/Plugin.nix index 956bbbdc..8389fb47 100644 --- a/home/file/waybar/style/Plugin.nix +++ b/home/file/waybar/style/Plugin.nix @@ -23,6 +23,7 @@ in { /* Padding for global widgets. */ #clock, #custom-display, + #custom-network, #language, #mpris, #pulseaudio, @@ -44,6 +45,7 @@ in { #batteryinfo:hover, #clock:hover, #custom-display:hover, + #custom-network:hover, #hardware:hover, #language:hover, #mpris:hover, @@ -58,6 +60,7 @@ in { #battery, #cpu.usage, #custom-display, + #custom-network, #memory, #pulseaudio, #temperature, @@ -69,6 +72,8 @@ in { #battery.critical, #cpu.usage.critical, #custom-display.modified, + #custom-network.issue, + #custom-network.vpn, #memory.critical, #pulseaudio.muted, #pulseaudio.source-muted, diff --git a/package/swayscript/script/NetworkWidget.nix b/package/swayscript/script/NetworkWidget.nix new file mode 100644 index 00000000..4d6fcec8 --- /dev/null +++ b/package/swayscript/script/NetworkWidget.nix @@ -0,0 +1,62 @@ +{ ... }: { + text = '' + # Waybar output. + function networkwidget() { + local IFS=$'\n' + local internet=$(nmcli networking connectivity check) + local _ethernets=($(nmcli connection show --active | rg ethernet | cut -f1 -d\ )) + local _vpns=($(nmcli connection show --active | rg vpn | cut -f1 -d\ )) + local _wifis=($(nmcli connection show --active | rg wifi | cut -f1 -d\ )) + local _bts=($(bluetoothctl devices Connected | cut -d\ -f3)) + local icon="󰖩" + local class="" + + if [[ "''${_bts}" != "" ]]; then + icon="󱛃" + fi + + if [[ "''${_vpns}" != "" ]]; then + class="vpn" + icon="󱚿" + fi + + if [[ "''${internet}" != "full" ]]; then + class="issue" + icon="󱚵" + fi + + for net in ''${_vpns[@]}; do + [[ "''${networks}" = "" ]] || networks+="\\\n" + networks+=" ''${net}" + done + + for net in ''${_ethernets[@]}; do + [[ "''${networks}" = "" ]] || networks+="\\\n" + networks+=" ''${net}" + done + + for net in ''${_wifis[@]}; do + [[ "''${networks}" = "" ]] || networks+="\\\n" + networks+="󰖩 ''${net}" + done + + for bt in ''${_bts[@]}; do + [[ "''${networks}" = "" ]] || networks+="\\\n" + networks+="󰂯 ''${bt}" + done + + printf "{\"text\": \"''${icon}\", \"tooltip\": \"''${networks[@]}\", \"class\": \"''${class}\"}\n" + } + + # Toggle network. + function network() { + notify_short + local state=$(nmcli networking) + if [[ "''${state}" = "enabled" ]]; then + nmcli networking off + else + nmcli networking on + fi + } + ''; +} diff --git a/system/Network.nix b/system/Network.nix index 929f0aa4..bdf1ae34 100644 --- a/system/Network.nix +++ b/system/Network.nix @@ -1,7 +1,16 @@ -{ ... }: { +{ + pkgs, + util, + ... +}: { networking = { networkmanager = { enable = true; + dispatcherScripts = [{ + source = pkgs.writeText "nm-wb-dispatcher" (util.trimTabs '' + ${pkgs.procps}/bin/pkill -RTMIN+7 waybar + ''); + }]; # unmanaged = [ # "type:bridge" # "type:ethernet" diff --git a/system/Udev.nix b/system/Udev.nix new file mode 100644 index 00000000..274c3954 --- /dev/null +++ b/system/Udev.nix @@ -0,0 +1,14 @@ +{ + pkgs, + util, + ... +}: let + waybar_reload = pkgs.writeShellScriptBin "bt-wb-dispatcher" (util.trimTabs '' + ${pkgs.procps}/bin/pkill -RTMIN+7 waybar + ''); +in { + services.udev.extraRules = util.trimTabs '' + ACTION=="add", SUBSYSTEM=="bluetooth", RUN+="${waybar_reload}/bin/bt-wb-dispatcher" + ACTION=="remove", SUBSYSTEM=="bluetooth", RUN+="${waybar_reload}/bin/bt-wb-dispatcher" + ''; +}