feat: add wallpaperEngine services

This commit is contained in:
DACHXY 2025-01-06 21:43:50 +08:00
parent 28789b9db8
commit 9a47a9e692
14 changed files with 352 additions and 79 deletions

11
home/config/tmux.yaml Normal file
View file

@ -0,0 +1,11 @@
name: init
root: ~/
startup_window: editor
windows:
- editor:
layout: main-vertical
panes:
- editor:
- nvim

View file

@ -61,7 +61,7 @@
"nvim . (.*)": " $1",
"\\(\\d+\\) Discord (.*)": " $1",
"(.*) - YouTube — Mozilla Firefox": " $1",
"(.*)\\pdf — Mozilla Firefox": " $1",
"(.*)\\.pdf — Mozilla Firefox": " $1",
"(.*) — Mozilla Firefox": " $1",
"(.*) - VLC media player": " $1",
"(.*) - YouTube Music — Mozilla Firefox": "󰎆 $1",

View file

@ -6,6 +6,7 @@
}:
let
swayncScript = pkgs.pkgs.writeShellScriptBin "swaync-start" ''
#!/usr/bin/env bash
XDG_CONFIG_HOME="$HOME/.dummy" # Prevent swaync use default gtk theme
swaync -c "$HOME/.config/swaync/config.json" -s "$HOME/.config/swaync/style.css"
'';

View file

@ -52,6 +52,7 @@ in
ruff-lsp
pyright
hadolint
yaml-language-server
];
programs.neovim = {

View file

@ -33,6 +33,9 @@ in
../../modules/gaming.nix
../../modules/wireguard.nix
../../modules/dn-ca.nix
(import ../../modules/wallpaper-engine.nix {
offload = nvidia-offload-enabled;
})
];
# Overrides

View file

@ -0,0 +1,194 @@
{
config,
pkgs,
lib,
...
}:
let
cfg = config.services.wallpaperEngine;
scaleTypes = [
"default"
"fit"
"fill"
"stretch"
];
clampModes = [
"clamp"
"border"
"repeat"
];
generateCommandLine =
monitors:
lib.concatStringsSep " " (
lib.mapAttrsToList (
monitorName: monitorConfig:
let
scaleArg = if monitorConfig.scale != null then "--scaling ${monitorConfig.scale}" else "";
bgId =
if monitorConfig.bg != null then
monitorConfig.bg
else
throw "Error: Background (bg) is required for monitor ${monitorName}.";
bgArg = if cfg.contentDir != null then "${lib.removeSuffix "/" cfg.contentDir}/${bgId}" else bgId;
in
(scaleArg + " --screen-root " + monitorName + " " + bgArg)
) cfg.monitors
);
startup =
let
args = lib.concatStringsSep " \\\n " (
lib.filter (x: x != "") (
with lib;
[
(optionalString (cfg.extraPrefix != null) cfg.extraPrefix)
"${pkgs.linux-wallpaperengine}/bin/linux-wallpaperengine"
(optionalString (cfg.assetsDir != null) "--assets-dir ${cfg.assetsDir}")
(optionalString (cfg.fps != null) "--fps ${toString cfg.fps}")
(optionalString (cfg.audio.enable == false) "--silent")
(optionalString (cfg.audio.autoMute == false) "--noautomute")
(generateCommandLine cfg.monitors)
(optionalString (cfg.extraPostfix != null) cfg.extraPostfix)
]
)
);
in
pkgs.writeShellScriptBin "launch-wallpaper-engine" ''
${args}
'';
in
with lib;
{
options = {
services.wallpaperEngine = {
enable = mkOption {
default = false;
type = with types; bool;
description = ''Start Wallpaper Engine for linux'';
};
extraPrefix = mkOption {
default = "";
type = with types; str;
description = ''Add extra command to exec'';
};
extraPostfix = mkOption {
default = "";
type = with types; str;
description = ''Add extra arguments'';
};
fps = mkOption {
default = null;
type = with types; nullOr int;
description = ''Limits the FPS to the given number, useful to keep battery consumption low'';
};
audio = {
enable = mkOption {
default = false;
type = with types; bool;
description = ''Mutes all the sound the wallpaper might produce'';
};
autoMute = mkOption {
default = true;
type = with types; bool;
description = ''Automute when an app is playing sound'';
};
volume = mkOption {
default = null;
type = with types; nullOr int;
description = ''Sets the volume for all the sounds in the background'';
};
};
assetsDir = mkOption {
default = null;
type = with types; nullOr str;
description = "Steam WallpaperEngine assets directory";
};
contentDir = mkOption {
default = null;
type = with types; nullOr str;
description = "Steam WallpaperEngine workshop content directory";
};
screenshot = mkOption {
default = false;
type = with types; bool;
description = "Takes a screenshot of the background";
};
clamping = mkOption {
default = "clamp";
type = with types; enum clampModes;
description = ''Clamping mode for all wallpapers. Can be clamp, border, repeat. Enables GL_CLAMP_TO_EDGE, GL_CLAMP_TO_BORDER, GL_REPEAT accordingly. Default is clamp.'';
};
monitors = mkOption {
default = { };
description = ''Monitor to display'';
example = {
"HDMI-A-2" = {
scale = "fill";
bg = "3029865244";
};
"DP-3" = {
bg = "3029865244";
};
};
type =
with types;
attrsOf (
submodule (
{ ... }:
{
options = {
scale = mkOption {
default = "default";
description = ''Scaling mode for wallpaper. Can be stretch, fit, fill, default. Must be used before wallpaper provided.'';
type = enum scaleTypes;
};
bg = mkOption {
description = ''Background to use.'';
type = str;
};
};
}
)
);
};
};
};
config = mkIf cfg.enable {
environment.systemPackages = (
(with pkgs; [
linux-wallpaperengine
])
++ [ startup ]
);
systemd.user.services.wallpaper-engine = {
enable = true;
description = "Start Wallpaper Engine after Hyprland";
after = [
"wayland-session@Hyprland.target"
];
wantedBy = [ "default.target" ];
serviceConfig = {
ExecStart = "${startup}/bin/launch-wallpaper-engine";
Restart = "always";
RestartSec = 10;
};
};
};
}

View file

@ -24,5 +24,6 @@
./gc.nix
./polkit.nix
./lsp.nix
./tmux.nix
];
}

View file

@ -11,6 +11,6 @@
nix.gc = {
automatic = true;
dates = "weekly";
options = "--delete-older-than 14d";
options = "--delete-older-than 7d";
};
}

View file

@ -21,14 +21,7 @@ in
# Nvidia offload mode
let
offload = pkgs.writeShellScriptBin "offload" ''
#!/bin/bash
export __NV_PRIME_RENDER_OFFLOAD=1
export __NV_PRIME_RENDER_OFFLOAD_PROVIDER=NVIDIA-G0
export __GLX_VENDOR_LIBRARY_NAME=nvidia
export __VK_LAYER_NV_optimus=NVIDIA_only
exec "$@"
'';
offload = import ./offload.nix { inherit pkgs; };
in
lib.checkListOfEnum "Nvidia Prime Mode" validModes [ nvidia-mode ] {
environment.systemPackages = [ offload ];

View file

@ -0,0 +1,8 @@
{ pkgs, ... }:
pkgs.writeShellScriptBin "offload" ''
export __NV_PRIME_RENDER_OFFLOAD=1
export __NV_PRIME_RENDER_OFFLOAD_PROVIDER=NVIDIA-G0
export __GLX_VENDOR_LIBRARY_NAME=nvidia
export __VK_LAYER_NV_optimus=NVIDIA_only
exec "$@"
''

View file

@ -95,5 +95,6 @@
])
++ [
inputs.ghostty.packages.${system}.default
inputs.yazi.packages.${system}.default
];
}

View file

@ -1,10 +1,5 @@
{ pkgs, config, ... }:
{ pkgs, ... }:
let
getIconScript = pkgs.writeShellScriptBin "get-icon" (
builtins.readFile ../../home/config/scripts/getIcons.sh
);
in
{
programs = {
gnupg = {
@ -14,69 +9,6 @@ in
};
};
tmux = {
enable = true;
escapeTime = 0;
plugins = with pkgs; [
tmuxPlugins.vim-tmux-navigator
tmuxPlugins.resurrect
tmuxPlugins.continuum
tmuxPlugins.catppuccin
];
extraConfig = ''
set -gq allow-passthrough on
set -g status "on"
set -g status-style fg=default,bg=default
set -g status-position top
set -g status-justify "left"
set -g status-left "#[fg=#84977f,bg=default,bold] session: #S"
set -g status-right " #[fg=#828bb8,bg=default,bold]${config.networking.hostName} "
setw -g window-status-format "#[fg=#171616,bg=default] #[fg=#495361,bg=default]#(${getIconScript}/get-icon #I)#W"
setw -g window-status-current-format "#[fg=#7e93a9,bg=default] #[fg=#7e93a9,bg=default,bold]#(${getIconScript}/get-icon #I) #W"
set -g default-terminal "xterm-256color"
set -ga terminal-overrides ",*256col*:Tc"
set -ga terminal-overrides '*:Ss=\E[%p1%d q:Se=\E[ q'
set-environment -g COLORTERM "truecolor"
set -g prefix C-b
bind-key C-b send-prefix
unbind %
bind | split-window -h
unbind '"'
bind - split-window -v
unbind r
bind r source-file ~/.tmux.conf
bind -r j resize-pane -D 5
bind -r k resize-pane -U 5
bind -r l resize-pane -R 5
bind -r h resize-pane -L 5
bind -r m resize-pane -Z
set -g mouse on
set-window-option -g mode-keys vi
bind-key -T copy-mode-vi 'v' send -X begin-selection
bind-key -T copy-mode-vi 'y' send -X copy-selection
unbind -T copy-mode-vi MouseDragEnd1Pane
set -g @resurrect-capture-pane-contents 'on'
set -g @continuum-restore 'on'
set -g @catppuccin-flavour 'macchiato'
'';
};
dconf.enable = true;
zsh.enable = true;
mtr.enable = true;

101
system/modules/tmux.nix Normal file
View file

@ -0,0 +1,101 @@
{ pkgs, config, ... }:
let
getIconScript = pkgs.writeShellScriptBin "get-icon" (
builtins.readFile ../../home/config/scripts/getIcons.sh
);
prefixKey = "C-Space";
tmuxConfigPath = "/etc/tmux.conf";
in
{
environment.variables = {
TMUXINATOR_CONFIG = "/etc/tmuxinator";
};
environment.etc = {
"tmuxinator/tmux.yaml" = {
source = ../../home/config/tmux.yaml;
mode = "0444";
};
};
environment.systemPackages = with pkgs; [ tmuxinator ];
programs = {
tmux = {
enable = true;
escapeTime = 0;
plugins = with pkgs; [
tmuxPlugins.vim-tmux-navigator
tmuxPlugins.resurrect
tmuxPlugins.continuum
tmuxPlugins.catppuccin
tmuxPlugins.yank
];
extraConfig = ''
set -gq allow-passthrough on
set -g status "on"
set -g status-style fg=default,bg=default
set -g status-position top
set -g status-justify "left"
set -g status-left "#[fg=#84977f,bg=default,bold] session: #S"
set -g status-right " #[fg=#828bb8,bg=default,bold]${config.networking.hostName} "
setw -g window-status-format "#[fg=#171616,bg=default] #[fg=#495361,bg=default]#(${getIconScript}/get-icon #I)#W"
setw -g window-status-current-format "#[fg=#7e93a9,bg=default] #[fg=#7e93a9,bg=default,bold]#(${getIconScript}/get-icon #I) #W"
set -g default-terminal "xterm-256color"
set -ga terminal-overrides ",*256col*:Tc"
set -ga terminal-overrides '*:Ss=\E[%p1%d q:Se=\E[ q'
set-environment -g COLORTERM "truecolor"
unbind C-b
set -g prefix ${prefixKey}
bind-key ${prefixKey} send-prefix
# Set Window start at 1
set -g base-index 1
set -g pane-base-index 1
set-window-option -g pane-base-index 1
set-option -g renumber-windows on
# Switch Windows (Shift + Alt + h/l)
bind -n M-H previous-window
bind -n M-L next-window
unbind %
bind | split-window -h -c "#{pane_current_path}"
unbind '"'
bind - split-window -v -c "#{pane_current_path}"
unbind r
bind r source-file ${tmuxConfigPath}
bind -r j resize-pane -D 5
bind -r k resize-pane -U 5
bind -r l resize-pane -R 5
bind -r h resize-pane -L 5
bind -r m resize-pane -Z
set -g mouse on
set-window-option -g mode-keys vi
bind-key -T copy-mode-vi 'v' send -X begin-selection
bind-key -T copy-mode-vi 'y' send -X copy-selection
unbind -T copy-mode-vi MouseDragEnd1Pane
set -g @resurrect-capture-pane-contents 'on'
set -g @continuum-restore 'on'
set -g @catppuccin-flavour 'macchiato'
'';
};
};
}

View file

@ -0,0 +1,27 @@
# Work pretty good on ONE monitor
{
offload ? false,
...
}:
{ pkgs, lib, ... }:
let
wallpaper = "3029865244";
assetsDir = "/mnt/windows/Users/danny/scoop/apps/steam/current/steamapps/common/wallpaper_engine/assets";
contentDir = "/mnt/windows/Users/danny/scoop/apps/steam/current/steamapps/workshop/content/431960";
offloadScript = import ./offload.nix { inherit pkgs; };
in
{
imports = [ ../extra/wallpaper-engine.nix ];
services.wallpaperEngine = {
enable = true;
assetsDir = assetsDir;
contentDir = contentDir;
extraPrefix = lib.mkIf offload "${offloadScript}/bin/offload";
fps = 30;
monitors = {
"DP-3" = {
bg = wallpaper;
};
};
};
}