From 47550dfff7677f06c8efeb60a63ce80ea0ab249f Mon Sep 17 00:00:00 2001 From: ulic-youthlic Date: Wed, 15 Jan 2025 13:37:41 +0800 Subject: [PATCH] add json support for helix change notification app for niri from mako to swaync add deno as json/jsonc formatter in helix add wluma to control backlight add taplo as toml formatter refactor waybar, and use waybar default config change gpg pinentry to shell script which can determine which session type is used fix error when SSH_CLIENT is unbind in pinentry script fix pinentry selector in pkgs --- .../configurations/Tytonidae/default.nix | 2 + .../configurations/Tytonidae/niri/config.kdl | 2 +- .../Tytonidae/waybar/config/config.jsonc | 215 ++++++++++++++++++ .../Tytonidae/waybar/default.nix | 4 + .../Tytonidae/wluma/config.toml | 25 ++ .../Tytonidae/wluma/default.nix | 4 + home/modules/default.nix | 2 + home/modules/gpg/default.nix | 3 +- home/modules/helix/default.nix | 71 ++++++ home/modules/niri.nix | 5 +- home/modules/waybar.nix | 33 +++ home/modules/wluma.nix | 57 +++++ nixos/configurations/Tytonidae/default.nix | 6 +- .../Tytonidae/users/default.nix | 12 +- pkgs/default.nix | 1 + pkgs/pinentry-selector.nix | 25 ++ 16 files changed, 459 insertions(+), 8 deletions(-) create mode 100644 home/david/configurations/Tytonidae/waybar/config/config.jsonc create mode 100644 home/david/configurations/Tytonidae/waybar/default.nix create mode 100644 home/david/configurations/Tytonidae/wluma/config.toml create mode 100644 home/david/configurations/Tytonidae/wluma/default.nix create mode 100644 home/modules/waybar.nix create mode 100644 home/modules/wluma.nix create mode 100644 pkgs/pinentry-selector.nix diff --git a/home/david/configurations/Tytonidae/default.nix b/home/david/configurations/Tytonidae/default.nix index a598dff..0cfddab 100644 --- a/home/david/configurations/Tytonidae/default.nix +++ b/home/david/configurations/Tytonidae/default.nix @@ -9,6 +9,8 @@ { imports = [ ./niri + ./wluma + ./waybar ]; youthlic.programs = { diff --git a/home/david/configurations/Tytonidae/niri/config.kdl b/home/david/configurations/Tytonidae/niri/config.kdl index 6e753e0..cca096f 100644 --- a/home/david/configurations/Tytonidae/niri/config.kdl +++ b/home/david/configurations/Tytonidae/niri/config.kdl @@ -126,7 +126,7 @@ environment { DISPLAY ":1" } spawn-at-startup "waybar" -spawn-at-startup "mako" +spawn-at-startup "swaync" spawn-at-startup "swaybg" "-i" "/home/david/wallpaper/01.png" spawn-at-startup "fcitx5" "-d" "--replace" spawn-at-startup "xwayland-satellite" ":1" diff --git a/home/david/configurations/Tytonidae/waybar/config/config.jsonc b/home/david/configurations/Tytonidae/waybar/config/config.jsonc new file mode 100644 index 0000000..e87e71e --- /dev/null +++ b/home/david/configurations/Tytonidae/waybar/config/config.jsonc @@ -0,0 +1,215 @@ +// -*- mode: jsonc -*- +{ + // "layer": "top", // Waybar at top layer + // "position": "bottom", // Waybar position (top|bottom|left|right) + "height": 30, // Waybar height (to be removed for auto height) + // "width": 1280, // Waybar width + "spacing": 4, // Gaps between modules (4px) + // Choose the order of the modules + "modules-left": [ + "sway/workspaces", + "sway/mode", + "sway/scratchpad", + "custom/media" + ], + "modules-center": [ + "sway/window" + ], + "modules-right": [ + "mpd", + "idle_inhibitor", + "pulseaudio", + "network", + "power-profiles-daemon", + "cpu", + "memory", + "temperature", + "backlight", + "keyboard-state", + "sway/language", + "battery", + "battery#bat2", + "clock", + "tray", + "custom/power" + ], + // Modules configuration + // "sway/workspaces": { + // "disable-scroll": true, + // "all-outputs": true, + // "warp-on-scroll": false, + // "format": "{name}: {icon}", + // "format-icons": { + // "1": "", + // "2": "", + // "3": "", + // "4": "", + // "5": "", + // "urgent": "", + // "focused": "", + // "default": "" + // } + // }, + "keyboard-state": { + "numlock": true, + "capslock": true, + "format": "{name} {icon}", + "format-icons": { + "locked": "", + "unlocked": "" + } + }, + "sway/mode": { + "format": "{}" + }, + "sway/scratchpad": { + "format": "{icon} {count}", + "show-empty": false, + "format-icons": ["", ""], + "tooltip": true, + "tooltip-format": "{app}: {title}" + }, + "mpd": { + "format": "{stateIcon} {consumeIcon}{randomIcon}{repeatIcon}{singleIcon}{artist} - {album} - {title} ({elapsedTime:%M:%S}/{totalTime:%M:%S}) ⸨{songPosition}|{queueLength}⸩ {volume}% ", + "format-disconnected": "Disconnected ", + "format-stopped": "{consumeIcon}{randomIcon}{repeatIcon}{singleIcon}Stopped ", + "unknown-tag": "N/A", + "interval": 5, + "consume-icons": { + "on": " " + }, + "random-icons": { + "off": " ", + "on": " " + }, + "repeat-icons": { + "on": " " + }, + "single-icons": { + "on": "1 " + }, + "state-icons": { + "paused": "", + "playing": "" + }, + "tooltip-format": "MPD (connected)", + "tooltip-format-disconnected": "MPD (disconnected)" + }, + "idle_inhibitor": { + "format": "{icon}", + "format-icons": { + "activated": "", + "deactivated": "" + } + }, + "tray": { + // "icon-size": 21, + "spacing": 10 + }, + "clock": { + // "timezone": "America/New_York", + "tooltip-format": "{:%Y %B}\n{calendar}", + "format-alt": "{:%Y-%m-%d}" + }, + "cpu": { + "format": "{usage}% ", + "tooltip": false + }, + "memory": { + "format": "{}% " + }, + "temperature": { + // "thermal-zone": 2, + // "hwmon-path": "/sys/class/hwmon/hwmon2/temp1_input", + "critical-threshold": 80, + // "format-critical": "{temperatureC}°C {icon}", + "format": "{temperatureC}°C {icon}", + "format-icons": ["", "", ""] + }, + "backlight": { + // "device": "acpi_video1", + "format": "{percent}% {icon}", + "format-icons": ["", "", "", "", "", "", "", "", ""] + }, + "battery": { + "states": { + // "good": 95, + "warning": 30, + "critical": 15 + }, + "format": "{capacity}% {icon}", + "format-full": "{capacity}% {icon}", + "format-charging": "{capacity}% ", + "format-plugged": "{capacity}% ", + "format-alt": "{time} {icon}", + // "format-good": "", // An empty format will hide the module + // "format-full": "", + "format-icons": ["", "", "", "", ""] + }, + "battery#bat2": { + "bat": "BAT2" + }, + "power-profiles-daemon": { + "format": "{icon}", + "tooltip-format": "Power profile: {profile}\nDriver: {driver}", + "tooltip": true, + "format-icons": { + "default": "", + "performance": "", + "balanced": "", + "power-saver": "" + } + }, + "network": { + // "interface": "wlp2*", // (Optional) To force the use of this interface + "format-wifi": "{essid} ({signalStrength}%) ", + "format-ethernet": "{ipaddr}/{cidr} ", + "tooltip-format": "{ifname} via {gwaddr} ", + "format-linked": "{ifname} (No IP) ", + "format-disconnected": "Disconnected ⚠", + "format-alt": "{ifname}: {ipaddr}/{cidr}" + }, + "pulseaudio": { + // "scroll-step": 1, // %, can be a float + "format": "{volume}% {icon} {format_source}", + "format-bluetooth": "{volume}% {icon} {format_source}", + "format-bluetooth-muted": " {icon} {format_source}", + "format-muted": " {format_source}", + "format-source": "{volume}% ", + "format-source-muted": "", + "format-icons": { + "headphone": "", + "hands-free": "", + "headset": "", + "phone": "", + "portable": "", + "car": "", + "default": ["", "", ""] + }, + "on-click": "pavucontrol" + }, + "custom/media": { + "format": "{icon} {text}", + "return-type": "json", + "max-length": 40, + "format-icons": { + "spotify": "", + "default": "🎜" + }, + "escape": true, + "exec": "$HOME/.config/waybar/mediaplayer.py 2> /dev/null" // Script in resources folder + // "exec": "$HOME/.config/waybar/mediaplayer.py --player spotify 2> /dev/null" // Filter player based on name + }, + "custom/power": { + "format": "⏻ ", + "tooltip": false, + "menu": "on-click", + "menu-file": "$HOME/.config/waybar/power_menu.xml", // Menu file in resources folder + "menu-actions": { + "shutdown": "shutdown", + "reboot": "reboot", + "suspend": "systemctl suspend", + "hibernate": "systemctl hibernate" + } + } +} diff --git a/home/david/configurations/Tytonidae/waybar/default.nix b/home/david/configurations/Tytonidae/waybar/default.nix new file mode 100644 index 0000000..b80cabe --- /dev/null +++ b/home/david/configurations/Tytonidae/waybar/default.nix @@ -0,0 +1,4 @@ +{ ... }: +{ + youthlic.programs.waybar.configDir = ./config; +} diff --git a/home/david/configurations/Tytonidae/wluma/config.toml b/home/david/configurations/Tytonidae/wluma/config.toml new file mode 100644 index 0000000..8ae2f7d --- /dev/null +++ b/home/david/configurations/Tytonidae/wluma/config.toml @@ -0,0 +1,25 @@ +# [als.iio] +# path = "/sys/bus/iio/devices" +# thresholds = { 0 = "night", 20 = "dark", 80 = "dim", 250 = "normal", 500 = "bright", 800 = "outdoors" } + +[als.webcam] +video = 0 +thresholds = { 0 = "night", 15 = "dark", 30 = "dim", 45 = "normal", 60 = "bright", 75 = "outdoors" } + +# [als.time] +# thresholds = { 0 = "night", 7 = "dark", 9 = "dim", 11 = "normal", 13 = "bright", 16 = "normal", 18 = "dark", 20 = "night" } + +# [als.none] + +[[output.backlight]] +name = "eDP-1" +path = "/sys/class/backlight/intel_backlight" +capturer = "wayland" + +# [[output.ddcutil]] +# name = "Dell Inc. DELL P2415Q" +# capturer = "none" + +[[keyboard]] +name = "keyboard-asus" +path = "/sys/bus/platform/devices/asus-nb-wmi/leds/asus::kbd_backlight" diff --git a/home/david/configurations/Tytonidae/wluma/default.nix b/home/david/configurations/Tytonidae/wluma/default.nix new file mode 100644 index 0000000..50a5098 --- /dev/null +++ b/home/david/configurations/Tytonidae/wluma/default.nix @@ -0,0 +1,4 @@ +{ ... }: +{ + youthlic.programs.wluma.config = ./config.toml; +} diff --git a/home/modules/default.nix b/home/modules/default.nix index 885667a..e4d0da1 100644 --- a/home/modules/default.nix +++ b/home/modules/default.nix @@ -17,6 +17,8 @@ ./fuzzel.nix ./firefox.nix ./niri.nix + ./wluma.nix + ./waybar.nix ]; options = { diff --git a/home/modules/gpg/default.nix b/home/modules/gpg/default.nix index 1862db3..34642d5 100644 --- a/home/modules/gpg/default.nix +++ b/home/modules/gpg/default.nix @@ -2,6 +2,7 @@ pkgs, config, lib, + outputs, ... }: { @@ -26,7 +27,7 @@ { enable = true; enableSshSupport = true; - pinentryPackage = pkgs.pinentry-curses; + pinentryPackage = outputs.packages."${pkgs.system}".pinentry-selector; } (lib.mkIf config.youthlic.programs.fish.enable { enableFishIntegration = true; diff --git a/home/modules/helix/default.nix b/home/modules/helix/default.nix index 813aaf4..d6e5203 100644 --- a/home/modules/helix/default.nix +++ b/home/modules/helix/default.nix @@ -23,6 +23,7 @@ nixd deno nixfmt-rfc-style + nodePackages_latest.vscode-json-languageserver ]; example = ( with pkgs; @@ -50,6 +51,76 @@ config = builtins.fromTOML config-file; in config; + languages = { + language-server = { + vscode-json-languageserver = { + command = "vscode-json-languageserver"; + args = [ "--stdio" ]; + config = { + provideFormatter = true; + json = { + validate = { + enable = true; + }; + }; + }; + }; + }; + language = [ + { + name = "toml"; + formatter = { + command = "taplo"; + args = [ + "fmt" + "-" + ]; + }; + } + { + name = "markdown"; + formatter = { + command = "deno"; + args = [ + "fmt" + "-" + "--ext" + "md" + ]; + }; + } + { + name = "json"; + language-servers = [ + "vscode-json-languageserver" + ]; + formatter = { + command = "deno"; + args = [ + "fmt" + "-" + "--ext" + "json" + ]; + }; + } + { + name = "jsonc"; + language-servers = [ + "vscode-json-languageserver" + ]; + formatter = { + command = "deno"; + args = [ + "fmt" + "-" + "--ext" + "jsonc" + ]; + }; + } + ]; + }; }; home.packages = cfg.extraPackages; }; diff --git a/home/modules/niri.nix b/home/modules/niri.nix index 20a4cf3..29b9ec4 100644 --- a/home/modules/niri.nix +++ b/home/modules/niri.nix @@ -22,13 +22,14 @@ in }; config = lib.mkIf cfg.enable { home.packages = with pkgs; [ - mako + swaynotificationcenter swaybg xwayland-satellite - waybar ]; youthlic.programs = { fuzzel.enable = true; + wluma.enable = true; + waybar.enable = true; }; programs.niri = { config = builtins.readFile cfg.config; diff --git a/home/modules/waybar.nix b/home/modules/waybar.nix new file mode 100644 index 0000000..4512296 --- /dev/null +++ b/home/modules/waybar.nix @@ -0,0 +1,33 @@ +{ + pkgs, + config, + lib, + ... +}: +let + cfg = config.youthlic.programs.waybar; +in +{ + options = { + youthlic.programs.waybar = { + enable = lib.mkEnableOption "waybar"; + configDir = lib.mkOption { + type = lib.types.path; + example = ./config; + description = '' + path to waybar config dir + ''; + }; + }; + }; + config = lib.mkIf cfg.enable { + home.packages = with pkgs; [ + waybar + ]; + xdg.configFile."waybar" = { + enable = true; + source = cfg.configDir; + recursive = true; + }; + }; +} diff --git a/home/modules/wluma.nix b/home/modules/wluma.nix new file mode 100644 index 0000000..6c30ea8 --- /dev/null +++ b/home/modules/wluma.nix @@ -0,0 +1,57 @@ +{ + config, + pkgs, + lib, + ... +}: +let + cfg = config.youthlic.programs.wluma; +in +{ + options = { + youthlic.programs.wluma = { + enable = lib.mkEnableOption "wluma"; + config = lib.mkOption { + type = lib.types.path; + example = ./config.toml; + description = '' + path to config file of wluma + ''; + }; + package = lib.mkOption { + type = lib.types.package; + example = pkgs.wluam; + default = pkgs.wluma; + description = '' + pakcage of wluma + ''; + }; + }; + }; + config = lib.mkIf cfg.enable { + home.packages = [ + cfg.package + ]; + xdg.configFile."wluma/config.toml" = { + enable = true; + source = cfg.config; + }; + systemd.user.services.wluma = { + Unit = { + Description = "Adjusting screen brightness based on screen contents and amount of ambient light"; + PartOf = [ "graphical-session.target" ]; + After = [ "graphical-session.target" ]; + }; + Service = { + ExecStart = [ "${lib.getExe cfg.package}" ]; + Restart = "always"; + EnvironmentFile = [ "-%E/wluma/service.conf" ]; + PrivateNetwork = true; + PrivateMounts = false; + }; + Install = { + WantedBy = [ "graphical-session.target" ]; + }; + }; + }; +} diff --git a/nixos/configurations/Tytonidae/default.nix b/nixos/configurations/Tytonidae/default.nix index 6cfce14..cbe46e9 100644 --- a/nixos/configurations/Tytonidae/default.nix +++ b/nixos/configurations/Tytonidae/default.nix @@ -29,14 +29,14 @@ openssh.enable = true; steam.enable = true; }; - gui.enabled = "niri"; + gui.enabled = "cosmic"; }; specialisation = { - cosmic = { + niri = { inheritParentConfig = true; configuration = { - youthlic.gui.enabled = lib.mkForce "cosmic"; + youthlic.gui.enabled = lib.mkForce "niri"; }; }; }; diff --git a/nixos/configurations/Tytonidae/users/default.nix b/nixos/configurations/Tytonidae/users/default.nix index f954fb7..ca6a451 100644 --- a/nixos/configurations/Tytonidae/users/default.nix +++ b/nixos/configurations/Tytonidae/users/default.nix @@ -1,4 +1,4 @@ -{ pkgs, ... }: +{ lib, pkgs, ... }: { users.users.david = { isNormalUser = true; @@ -7,8 +7,18 @@ "networkmanager" "libvirtd" "wheel" + "video" ]; }; + services.udev = { + enable = true; + extraRules = '' + ACTION=="add", SUBSYSTEM=="backlight", RUN+="${lib.getExe' pkgs.coreutils "chgrp"} video /sys/class/backlight/%k/brightness" + ACTION=="add", SUBSYSTEM=="backlight", RUN+="${lib.getExe' pkgs.coreutils "chmod"} g+w /sys/class/backlight/%k/brightness" + ACTION=="add", SUBSYSTEM=="leds", RUN+="${lib.getExe' pkgs.coreutils "chgrp"} video /sys/class/leds/%k/brightness" + ACTION=="add", SUBSYSTEM=="leds", RUN+="${lib.getExe' pkgs.coreutils "chmod"} g+w /sys/class/leds/%k/brightness" + ''; + }; programs.fish.enable = true; users.users.david.shell = pkgs.fish; users.users.david.openssh.authorizedKeys.keyFiles = [ diff --git a/pkgs/default.nix b/pkgs/default.nix index db05879..fbc2153 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -4,6 +4,7 @@ ... }: { + pinentry-selector = pkgs.callPackage ./pinentry-selector.nix { }; immersive-translate = (pkgs.callPackage "${inputs.firefox-addons}/default.nix" { }).firefox-addons.immersive-translate; } diff --git a/pkgs/pinentry-selector.nix b/pkgs/pinentry-selector.nix new file mode 100644 index 0000000..24558fb --- /dev/null +++ b/pkgs/pinentry-selector.nix @@ -0,0 +1,25 @@ +{ pkgs }: +pkgs.writeShellApplication { + name = "pinentry"; + runtimeInputs = with pkgs; [ + pinentry-all + ]; + text = '' + if [ -v XDG_SESSION_TYPE ]; then + case $XDG_SESSION_TYPE in + tty) + pinentry-tty;; + *) + pinentry-qt;; + esac + elif [ -v SSH_CLIENT ] && [ -n "$SSH_CLIENT" ]; then + pinentry-tty + elif [ -v WAYLAND_DISPLAY ] && [ -n "$WAYLAND_DISPLAY" ]; then + pinentry-qt + elif [ -v DISPLAY ] && [ -n "$DISPLAY" ]; then + pinentry-qt + else + pinentry-tty + fi + ''; +}