mirror of
https://github.com/ryan4yin/nix-config.git
synced 2026-01-11 14:20:23 +01:00
refactor: auto start apps on login via xdg-autostart (#242)
Signed-off-by: Ryan Yin <xiaoyin_c@qq.com>
This commit is contained in:
@@ -1,106 +0,0 @@
|
||||
# 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 = [
|
||||
"google-chrome.desktop"
|
||||
"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`
|
||||
"x-scheme-handler/zoommtg" = [ "Zoom.desktop" ];
|
||||
|
||||
# all other unknown schemes will be opened by this default application.
|
||||
# "x-scheme-handler/unknown" = editor;
|
||||
|
||||
"x-scheme-handler/tg" = [ "org.telegram.desktop.desktop " ];
|
||||
|
||||
"audio/*" = [ "mpv.desktop" ];
|
||||
"video/*" = [ "mpv.desktop" ];
|
||||
"image/*" = [ "imv-dir.desktop" ];
|
||||
"image/gif" = [ "imv-dir.desktop" ];
|
||||
"image/jpeg" = [ "imv-dir.desktop" ];
|
||||
"image/png" = [ "imv-dir.desktop" ];
|
||||
"image/webp" = [ "imv-dir.desktop" ];
|
||||
|
||||
"inode/directory" = [ "yazi.desktop" ];
|
||||
};
|
||||
|
||||
associations.removed = {
|
||||
# ......
|
||||
};
|
||||
};
|
||||
|
||||
userDirs = {
|
||||
enable = true;
|
||||
createDirectories = true;
|
||||
extraConfig = {
|
||||
XDG_SCREENSHOTS_DIR = "${config.xdg.userDirs.pictures}/Screenshots";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
23
home/linux/gui/base/xdg/autostart.nix
Normal file
23
home/linux/gui/base/xdg/autostart.nix
Normal file
@@ -0,0 +1,23 @@
|
||||
{ pkgs, lib, ... }:
|
||||
{
|
||||
# XDG autostart entries - ensures apps start after portal services are ready
|
||||
xdg.autostart.enable = true;
|
||||
# This fixes nixpak sandboxed apps (like firefox) accessing mapped folders correctly
|
||||
xdg.autostart.entries = [
|
||||
"${pkgs.foot}/share/applications/foot.desktop"
|
||||
"${pkgs.alacritty}/share/applications/Alacritty.desktop"
|
||||
"${pkgs.ghostty}/share/applications/com.mitchellh.ghostty.desktop"
|
||||
|
||||
"${pkgs.clash-verge-rev}/share/applications/clash-verge.desktop"
|
||||
|
||||
# nixpaks
|
||||
"${pkgs.nixpaks.firefox}/share/applications/org.mozilla.firefox.desktop"
|
||||
"${pkgs.nixpaks.telegram-desktop}/share/applications/org.telegram.desktop.desktop"
|
||||
]
|
||||
++ (
|
||||
if pkgs.stdenv.isx86_64 then
|
||||
[ "${pkgs.google-chrome}/share/applications/google-chrome.desktop" ]
|
||||
else
|
||||
[ "${pkgs.chromium}/share/applications/chromium-browser.desktop" ]
|
||||
);
|
||||
}
|
||||
35
home/linux/gui/base/xdg/default.nix
Normal file
35
home/linux/gui/base/xdg/default.nix
Normal file
@@ -0,0 +1,35 @@
|
||||
# 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/
|
||||
{
|
||||
mylib,
|
||||
config,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
{
|
||||
imports = mylib.scanPaths ./.;
|
||||
|
||||
home.packages = with pkgs; [
|
||||
xdg-utils # provides cli tools such as `xdg-mime` `xdg-open`
|
||||
xdg-user-dirs
|
||||
];
|
||||
|
||||
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";
|
||||
|
||||
userDirs = {
|
||||
enable = true;
|
||||
createDirectories = true;
|
||||
extraConfig = {
|
||||
XDG_SCREENSHOTS_DIR = "${config.xdg.userDirs.pictures}/Screenshots";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
76
home/linux/gui/base/xdg/mime.nix
Normal file
76
home/linux/gui/base/xdg/mime.nix
Normal file
@@ -0,0 +1,76 @@
|
||||
{
|
||||
xdg.configFile."mimeapps.list".force = true;
|
||||
|
||||
# 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/
|
||||
xdg.mimeApps = {
|
||||
enable = true;
|
||||
# let `xdg-open` to open the url with the correct application.
|
||||
defaultApplications =
|
||||
let
|
||||
browser = [
|
||||
"google-chrome.desktop"
|
||||
"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`
|
||||
"x-scheme-handler/zoommtg" = [ "Zoom.desktop" ];
|
||||
|
||||
# all other unknown schemes will be opened by this default application.
|
||||
# "x-scheme-handler/unknown" = editor;
|
||||
|
||||
"x-scheme-handler/tg" = [ "org.telegram.desktop.desktop " ];
|
||||
|
||||
"audio/*" = [ "mpv.desktop" ];
|
||||
"video/*" = [ "mpv.desktop" ];
|
||||
"image/*" = [ "imv-dir.desktop" ];
|
||||
"image/gif" = [ "imv-dir.desktop" ];
|
||||
"image/jpeg" = [ "imv-dir.desktop" ];
|
||||
"image/png" = [ "imv-dir.desktop" ];
|
||||
"image/webp" = [ "imv-dir.desktop" ];
|
||||
|
||||
"inode/directory" = [ "yazi.desktop" ];
|
||||
};
|
||||
|
||||
associations.removed = {
|
||||
# ......
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -6,7 +6,6 @@
|
||||
// This is the main configuration file that includes all other config files
|
||||
include "./keybindings.kdl"
|
||||
include "./windowrules.kdl"
|
||||
include "./spawn-at-startup.kdl"
|
||||
include "./niri-hardware.kdl"
|
||||
include "./noctalia-shell.kdl"
|
||||
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
// Add lines like this to spawn processes at startup.
|
||||
// Note that running niri as a session supports xdg-desktop-autostart,
|
||||
// which may be more convenient to use.
|
||||
// See the binds section below for more spawn examples.
|
||||
|
||||
// Terminal applications
|
||||
spawn-at-startup "foot"
|
||||
spawn-at-startup "alacritty"
|
||||
spawn-at-startup "ghostty"
|
||||
|
||||
// Network proxy
|
||||
spawn-at-startup "clash-verge"
|
||||
|
||||
// Web browsers
|
||||
spawn-at-startup "firefox"
|
||||
spawn-at-startup "google-chrome-stable"
|
||||
spawn-at-startup "chromium-browser"
|
||||
|
||||
// Communication applications
|
||||
spawn-at-startup "Telegram"
|
||||
Reference in New Issue
Block a user