refactor(home/linux/desktop): home/linux/desktop => home/linux/gui

This commit is contained in:
Ryan Yin
2024-03-19 00:14:04 +08:00
parent 7d5a04fd38
commit d94f482c23
466 changed files with 1 additions and 2 deletions

View File

@@ -0,0 +1,61 @@
{
pkgs,
pkgs-unstable,
pkgs-stable,
nur-ryan4yin,
...
}: {
home.packages = with pkgs; [
# creative
blender # 3d modeling
# gimp # image editing, I prefer using figma in browser instead of this one
inkscape # vector graphics
krita # digital painting
musescore # music notation
# reaper # audio production
# sonic-pi # music programming
# this app consumes a lot of storage, so do not install it currently
# kicad # 3d printing, eletrical engineering
# fpga
pkgs-unstable.python311Packages.apycula # gowin fpga
pkgs-unstable.yosys # fpga synthesis
pkgs-unstable.nextpnr # fpga place and route
pkgs-unstable.openfpgaloader # fpga programming
nur-ryan4yin.packages.${pkgs.system}.gowin-eda-edu-ide # app: `gowin-env` => `gw_ide` / `gw_pack` / ...
];
programs = {
# live streaming
obs-studio = {
enable = true;
plugins = with pkgs-stable.obs-studio-plugins; [
# screen capture
wlrobs
# obs-ndi
obs-vaapi
obs-nvfbc
obs-teleport
# obs-hyperion
droidcam-obs
obs-vkcapture
obs-gstreamer
obs-3d-effect
input-overlay
obs-multi-rtmp
obs-source-clone
obs-shaderfilter
obs-source-record
obs-livesplit-one
looking-glass-obs
obs-vintage-filter
obs-command-source
obs-move-transition
obs-backgroundremoval
advanced-scene-switcher
obs-pipewire-audio-capture
];
};
};
}

View File

@@ -0,0 +1,3 @@
{mylib, ...}: {
imports = mylib.scanPaths ./.;
}

View File

@@ -0,0 +1,5 @@
{pkgs, ...}: {
home.packages = with pkgs; [
android-tools
];
}

View File

@@ -0,0 +1,45 @@
{
pkgs,
lib,
...
}: {
# Adjust the color temperature(& brightness) of your screen according to
# your surroundings. This may help your eyes hurt less if you are
# working in front of the screen at night.
#
# works fine with both x11 & wayland(hyprland)
#
# https://gitlab.com/chinstrap/gammastep
services.gammastep = {
enable = true;
# add a gammastep icon in the system tray
# has problem with wayland, so disable it
tray = false;
temperature = {
day = 5700;
night = 4000;
};
# https://gitlab.com/chinstrap/gammastep/-/blob/master/gammastep.conf.sample?ref_type=heads
settings = {
general = {
fade = "1"; # gradually apply the new screen temperature/brightness over a couple of seconds.
# it is a fake brightness adjustment obtained by manipulating the gamma ramps,
# which means that it does not reduce the backlight of the screen.
# Preferably only use it if your normal backlight adjustment is too coarse-grained.
brightness-day = "1.0";
brightness-night = "0.8";
location-provider = "manual";
# by default, Redshift will use the current elevation of the sun
# to determine whether it is daytime, night or in transition (dawn/dusk).
# dawn-time = "6:00-8:45";
# dusk-time = "18:35-20:15";
};
manual = {
# China, Shenzhen
lat = "22.5"; # latitude
lon = "114.1"; # longitude
};
};
};
}

View File

@@ -0,0 +1,26 @@
# Vertical Candidate List
Vertical Candidate List=False
# Use Per Screen DPI
PerScreenDPI=True
# Use mouse wheel to go to prev or next page
WheelForPaging=True
# Font
Font="Sans 10"
# Menu Font
MenuFont="Sans 10"
# Tray Font
TrayFont="Sans Bold 10"
# Tray Label Outline Color
TrayOutlineColor=#000000
# Tray Label Text Color
TrayTextColor=#ffffff
# Prefer Text Icon
PreferTextIcon=False
# Show Layout Name In Icon
ShowLayoutNameInIcon=True
# Use input method language to display text
UseInputMethodLangaugeToDisplayText=True
# Theme macchiato, frappe, latte, mocha
Theme=catppuccin-mocha
# Force font DPI on Wayland
ForceWaylandDPI=0

View File

@@ -0,0 +1,30 @@
{
pkgs,
nur-ryan4yin,
...
}: {
home.file.".local/share/fcitx5/themes".source = "${nur-ryan4yin.packages.${pkgs.system}.catppuccin-fcitx5}/src";
xdg.configFile = {
"fcitx5/profile" = {
source = ./profile;
# every time fcitx5 switch input method, it will modify ~/.config/fcitx5/profile,
# so we need to force replace it in every rebuild to avoid file conflict.
force = true;
};
"fcitx5/conf/classicui.conf".source = ./classicui.conf;
};
i18n.inputMethod = {
enabled = "fcitx5";
fcitx5.addons = with pkgs; [
# for flypy chinese input method
fcitx5-rime
# needed enable rime using configtool after installed
fcitx5-configtool
fcitx5-chinese-addons
# fcitx5-mozc # japanese input method
fcitx5-gtk # gtk im module
];
};
}

View File

@@ -0,0 +1,17 @@
[Groups/0]
# Group Name
Name=Other
# Layout
Default Layout=us
# Default Input Method
DefaultIM=rime
[Groups/0/Items/0]
# Name
Name=rime
# Layout
Layout=
[GroupOrder]
0=Other

View File

@@ -0,0 +1,12 @@
{
pkgs,
nix-gaming,
...
}: {
home.packages = with pkgs; [
# nix-gaming.packages.${pkgs.system}.osu-lazer-bin
gamescope # SteamOS session compositing window manager
prismlauncher # A free, open source launcher for Minecraft
winetricks # A script to install DLLs needed to work around problems in Wine
];
}

View File

@@ -0,0 +1,57 @@
{
pkgs,
config,
...
}: {
# If your themes for mouse cursor, icons or windows dont load correctly,
# try setting them with home.pointerCursor and gtk.theme,
# which enable a bunch of compatibility options that should make the themes load in all situations.
home.pointerCursor = {
gtk.enable = true;
x11.enable = true;
package = pkgs.bibata-cursors;
name = "Bibata-Modern-Ice";
size = 24;
};
# set dpi for 4k monitor
xresources.properties = {
# dpi for Xorg's font
"Xft.dpi" = 150;
# or set a generic dpi
"*.dpi" = 150;
};
# gtk's theme settings, generate files:
# 1. ~/.gtkrc-2.0
# 2. ~/.config/gtk-3.0/settings.ini
# 3. ~/.config/gtk-4.0/settings.ini
gtk = {
enable = true;
font = {
name = "Noto Sans";
package = pkgs.noto-fonts;
size = 11;
};
gtk2.configLocation = "${config.xdg.configHome}/gtk-2.0/gtkrc";
iconTheme = {
name = "Papirus-Dark";
package = pkgs.papirus-icon-theme;
};
theme = {
# https://github.com/catppuccin/gtk
name = "Catppuccin-Macchiato-Compact-Pink-Dark";
package = pkgs.catppuccin-gtk.override {
# https://github.com/NixOS/nixpkgs/blob/nixos-23.05/pkgs/data/themes/catppuccin-gtk/default.nix
accents = ["pink"];
size = "compact";
variant = "macchiato";
};
};
};
}

View File

@@ -0,0 +1,65 @@
{
config,
lib,
pkgs,
...
}:
##############################################################################################
#
# Provide a option `home.immutable-file`, it works like `home.file` but make the generated file immutable.
#
# Copy from https://github.com/iosmanthus/nixos-config/blob/349917b/modules/immutable-file.nix
#
# this module use the `chattr +i` to make the file immutable, `i` indicates `immutable`,
# it's a i-node flags only works on Linux.
#
# TODO not used yet, need to test it.
#
##############################################################################################
with lib; let
cfg = config.home.immutable-file;
immutableFileOpts = _: {
options = {
src = mkOption {
type = types.path;
};
dst = mkOption {
type = types.path;
};
};
};
mkImmutableFile = pkgs.writeScript "make_immutable_file" ''
# $1: dst
# $2: src
if [ ! -d "$(dirname $1)" ]; then
mkdir -p $1
fi
if [ -f $1 ]; then
sudo chattr -i $1
fi
sudo cp $2 $1
sudo chattr +i $1
'';
in {
options.home.immutable-file = mkOption {
type = with types; attrsOf (submodule immutableFileOpts);
default = {};
};
config = mkIf (cfg != {}) {
home.activation =
mapAttrs'
(name: {
src,
dst,
}:
nameValuePair
"make-immutable-${name}"
(lib.hm.dag.entryAfter ["writeBoundary"] ''
${mkImmutableFile} ${dst} ${src}
''))
cfg;
};
}

View File

@@ -0,0 +1,44 @@
{
pkgs,
pkgs-unstable,
nur-ryan4yin,
...
}:
# media - control and enjoy audio/video
{
home.packages = with pkgs; [
# audio control
pavucontrol
playerctl
pulsemixer
imv # simple image viewer
nvtop
# video/audio tools
cava # for visualizing audio
libva-utils
vdpauinfo
vulkan-tools
glxinfo
];
# https://github.com/catppuccin/cava
xdg.configFile."cava/config".text =
''
# custom cava config
''
+ builtins.readFile "${nur-ryan4yin.packages.${pkgs.system}.catppuccin-cava}/mocha.cava";
programs = {
mpv = {
enable = true;
defaultProfiles = ["gpu-hq"];
scripts = [pkgs.mpvScripts.mpris];
};
};
services = {
playerctld.enable = true;
};
}

View File

@@ -0,0 +1,34 @@
{
pkgs,
pkgs-unstable,
...
}: {
home.packages = with pkgs; [
# GUI apps
# e-book viewer(.epub/.mobi/...)
# do not support .pdf
foliate
# instant messaging
telegram-desktop
discord
pkgs-unstable.qq # https://github.com/NixOS/nixpkgs/tree/master/pkgs/applications/networking/instant-messengers/qq
# remote desktop(rdp connect)
remmina
freerdp # required by remmina
# misc
flameshot
ventoy # multi-boot usb creator
];
# GitHub CLI tool
programs.gh = {
enable = true;
};
# allow fontconfig to discover fonts and configurations installed through home.packages
# Install fonts at system-level, not user-level
fonts.fontconfig.enable = false;
}

View File

@@ -0,0 +1,7 @@
{pkgs, ...}: {
home.packages = with pkgs; [
# https://joplinapp.org/help/
joplin # joplin-cli
joplin-desktop
];
}

View File

@@ -0,0 +1,31 @@
{
pkgs,
config,
lib,
wallpapers,
...
}: {
systemd.user.services.wallpaper = {
Unit = {
Description = "Wallpaper Switcher daemon";
After = ["graphical-session-pre.target" "xdg-desktop-autostart.target"];
Wants = ["graphical-session-pre.target"];
};
Install.WantedBy = ["graphical-session.target"];
Service = {
ExecStart = lib.getExe (pkgs.writeShellApplication {
name = "wallpaper";
runtimeInputs = with pkgs; [procps feh swaybg python3];
text = ''
export WALLPAPERS_DIR="${wallpapers}"
export WALLPAPERS_STATE_FILEPATH="${config.xdg.stateHome}/wallpaper-switcher/switcher_state"
export WALLPAPER_WAIT_MIN=60
export WALLPAPER_WAIT_MAX=180
exec ${./wallpaper-switcher.py}
'';
});
RestartSec = 3;
Restart = "on-failure";
};
};
}

View File

@@ -0,0 +1,169 @@
#!/usr/bin/env python3
"""
This script will randomly select a wallpaper from the wallpapers directory.
It will skip the last wallpaper used, so that you don't get the same wallpaper.
It will also set the wallpaper using `feh` for X11, or `swaybg` for Wayland.
Maintainer: ryan4yin [xiaoyin_c@qq.com]
"""
import os
import time
import random
import json
from pathlib import Path
from typing import Union
import subprocess
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
class WallpaperSwitcher:
def __init__(
self,
wait_min,
wait_max,
wallpapers_dir: Path,
state_filepath: Path,
image_extensions: Union[tuple, list],
) -> None:
self.wallpapers_dir = wallpapers_dir
self.image_extensions = image_extensions
self.state_filepath = state_filepath
self.wait_min = wait_min
self.wait_max = wait_max
# initialize the state file
self.state_filepath.parent.mkdir(parents=True, exist_ok=True)
self.current_state = self.state_filepath.open("a+", encoding="utf-8")
self.current_wallpaper_list = list()
def run(self):
"""
Iterate on all wallpapers in the wallpapers directory, cycling through them in a random order.
"""
self.initialize_state()
while True:
for i, w in enumerate(self.current_wallpaper_list):
if i < self.current_wallpaper_index:
continue
logger.info(
f"Setting wallpaper {i+1}/{len(self.current_wallpaper_list)}: {w}"
)
self.set_wallpaper(w)
# update the state
self.current_wallpaper_index = i
self.save_state()
wait_time = random.randint(self.wait_min, self.wait_max)
logger.info(f"Waiting {wait_time} seconds...")
time.sleep(wait_time)
# reset the state
self.reset_state()
def save_state(self):
wallpaper_list = [w.as_posix() for w in self.current_wallpaper_list]
state = {
"current_wallpaper_list": wallpaper_list,
"current_wallpaper_index": self.current_wallpaper_index,
}
self.current_state.truncate(0)
self.current_state.write(json.dumps(state, indent=4))
self.current_state.flush()
def initialize_state(self):
self.current_state.seek(0)
data = self.current_state.read()
if not data:
logger.info("No state found, resetting...")
self.reset_state()
else:
logger.info("State found, reloading...")
state = json.loads(data)
wallpapers = [Path(w) for w in state["current_wallpaper_list"]]
self.current_wallpaper_list = wallpapers
self.current_wallpaper_index = state["current_wallpaper_index"]
def reset_state(self):
logger.info(f"Rescanning & shuffle wallpapers in {self.wallpapers_dir} ...")
wallpapers = list(
filter(
lambda x: x.suffix in self.image_extensions,
self.wallpapers_dir.iterdir(),
)
)
random.shuffle(wallpapers)
self.current_wallpaper_list = wallpapers
self.current_wallpaper_index = 0
def set_wallpaper(self, path: Path):
# check if we are running under x11 or wayland
if (
"WAYLAND_DISPLAY" in os.environ
or os.environ.get("XDG_SESSION_TYPE") == "wayland"
):
self.set_wallpaper_wayland(path)
else:
self.set_wallpaper_x11(path)
def set_wallpaper_x11(self, path: Path):
subprocess.run(["feh", "--bg-fill", path])
def set_wallpaper_wayland(self, path: Path):
# find all swaybg processes
swaybg_pids = subprocess.run(
["pgrep", "-f", "swaybg"], stdout=subprocess.PIPE
).stdout.decode("utf-8")
# run swaybg in the background, and make it running even after the parent process exits
subprocess.Popen(
["swaybg", "--output", "*", "--mode", "fill", "--image", path],
start_new_session=True,
)
time.sleep(1)
# kill all old swaybg processes
for pid in swaybg_pids.splitlines():
try:
os.kill(int(pid), 9)
except ProcessLookupError:
pass
def main():
wallpapers_dir = os.getenv("WALLPAPERS_DIR")
state_filepath = os.getenv("WALLPAPERS_STATE_FILEPATH")
if not wallpapers_dir:
raise Exception("WALLPAPERS_DIR not set")
if not state_filepath:
raise Exception("WALLPAPERS_STATE_FILEPATH not set")
image_postfix = (
".jpg",
".jpeg",
".png",
# ".gif",
# ".webp"
)
wait_min = int(os.getenv("WALLPAPER_WAIT_MIN", 60))
wait_max = int(os.getenv("WALLPAPER_WAIT_MAX", 300))
wallpaper_switcher = WallpaperSwitcher(
wait_min,
wait_max,
Path(wallpapers_dir).expanduser(),
Path(state_filepath).expanduser(),
image_postfix,
)
wallpaper_switcher.run()
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,92 @@
# XDG stands for "Cross-Desktop Group", with X used to mean "cross".
# It's a bunch of specifications from freedesktop.org intended to standardize desktops and
# other GUI applications on various systems (primarily Unix-like) to be interoperable:
# https://www.freedesktop.org/wiki/Specifications/
{
config,
pkgs,
...
}: {
home.packages = with pkgs; [
xdg-utils # provides cli tools such as `xdg-mime` `xdg-open`
xdg-user-dirs
];
xdg.configFile."mimeapps.list".force = true;
xdg = {
enable = true;
cacheHome = "${config.home.homeDirectory}/.cache";
configHome = "${config.home.homeDirectory}/.config";
dataHome = "${config.home.homeDirectory}/.local/share";
stateHome = "${config.home.homeDirectory}/.local/state";
# manage $XDG_CONFIG_HOME/mimeapps.list
# xdg search all desktop entries from $XDG_DATA_DIRS, check it by command:
# echo $XDG_DATA_DIRS
# the system-level desktop entries can be list by command:
# ls -l /run/current-system/sw/share/applications/
# the user-level desktop entries can be list by command(user ryan):
# ls /etc/profiles/per-user/ryan/share/applications/
mimeApps = {
enable = true;
# let `xdg-open` to open the url with the correct application.
defaultApplications = let
browser = ["firefox.desktop"];
editor = ["nvim.desktop" "Helix.desktop" "code.desktop" "code-insiders.desktop"];
in {
"application/json" = browser;
"application/pdf" = browser; # TODO: pdf viewer
"text/html" = browser;
"text/xml" = browser;
"text/plain" = editor;
"application/xml" = browser;
"application/xhtml+xml" = browser;
"application/xhtml_xml" = browser;
"application/rdf+xml" = browser;
"application/rss+xml" = browser;
"application/x-extension-htm" = browser;
"application/x-extension-html" = browser;
"application/x-extension-shtml" = browser;
"application/x-extension-xht" = browser;
"application/x-extension-xhtml" = browser;
"application/x-wine-extension-ini" = editor;
# define default applications for some url schemes.
"x-scheme-handler/about" = browser; # open `about:` url with `browser`
"x-scheme-handler/ftp" = browser; # open `ftp:` url with `browser`
"x-scheme-handler/http" = browser;
"x-scheme-handler/https" = browser;
# https://github.com/microsoft/vscode/issues/146408
"x-scheme-handler/vscode" = ["code-url-handler.desktop"]; # open `vscode://` url with `code-url-handler.desktop`
"x-scheme-handler/vscode-insiders" = ["code-insiders-url-handler.desktop"]; # open `vscode-insiders://` url with `code-insiders-url-handler.desktop`
# all other unknown schemes will be opened by this default application.
# "x-scheme-handler/unknown" = editor;
"x-scheme-handler/discord" = ["discord.desktop"];
"x-scheme-handler/tg" = ["org.telegram.desktop.desktop "];
"audio/*" = ["mpv.desktop"];
"video/*" = ["mpv.dekstop"];
"image/*" = ["imv-dir.desktop"];
"image/gif" = ["imv-dir.desktop"];
"image/jpeg" = ["imv-dir.desktop"];
"image/png" = ["imv-dir.desktop"];
"image/webp" = ["imv-dir.desktop"];
};
associations.removed = {
# ......
};
};
userDirs = {
enable = true;
createDirectories = true;
extraConfig = {
XDG_SCREENSHOTS_DIR = "${config.xdg.userDirs.pictures}/Screenshots";
};
};
};
}