Improve MIME defaults and Home Manager backups

This commit is contained in:
2026-04-12 14:13:56 -07:00
committed by Kat Huang
parent f6589c3b13
commit 7208ee09ad
3 changed files with 297 additions and 127 deletions

View File

@@ -1,4 +1,11 @@
{ inputs, config, pkgs, lib, makeEnable, ... }: {
inputs,
config,
pkgs,
lib,
makeEnable,
...
}:
makeEnable config "myModules.desktop" true { makeEnable config "myModules.desktop" true {
services.greenclip.enable = true; services.greenclip.enable = true;
imports = [ imports = [
@@ -72,7 +79,8 @@ makeEnable config "myModules.desktop" true {
} }
]; ];
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs;
[
# Appearance # Appearance
adwaita-icon-theme adwaita-icon-theme
hicolor-icon-theme hicolor-icon-theme
@@ -100,12 +108,14 @@ makeEnable config "myModules.desktop" true {
kdePackages.dolphin kdePackages.dolphin
feh feh
file-roller
gthumb gthumb
firefox firefox
cheese cheese
kdePackages.kleopatra kdePackages.kleopatra
libnotify libnotify
libreoffice libreoffice
loupe
lxappearance lxappearance
lxqt.lxqt-powermanagement lxqt.lxqt-powermanagement
networkmanagerapplet networkmanagerapplet
@@ -137,7 +147,11 @@ makeEnable config "myModules.desktop" true {
# Visualization # Visualization
graphviz graphviz
mermaid-cli mermaid-cli
] ++ (if pkgs.stdenv.hostPlatform.system == "x86_64-linux" then with pkgs; [ ]
++ (
if pkgs.stdenv.hostPlatform.system == "x86_64-linux"
then
with pkgs; [
google-chrome google-chrome
pommed_light pommed_light
slack slack
@@ -146,5 +160,7 @@ makeEnable config "myModules.desktop" true {
tor-browser tor-browser
vscode vscode
zulip zulip
] else []); ]
else []
);
} }

View File

@@ -1,5 +1,12 @@
{ config, pkgs, lib, nixos, ... }:
{ {
config,
pkgs,
lib,
nixos,
...
}: let
mimeMap = desktopId: mimeTypes: lib.genAttrs mimeTypes (_: [desktopId]);
in {
# Automatic garbage collection of old home-manager generations # Automatic garbage collection of old home-manager generations
nix.gc = { nix.gc = {
automatic = true; automatic = true;
@@ -20,37 +27,147 @@
static_history = [] static_history = []
''; '';
xdg.mimeApps = lib.mkIf nixos.config.myModules.desktop.enable { xdg.mimeApps = lib.mkIf nixos.config.myModules.desktop.enable (
let
browser = "google-chrome.desktop";
imageViewer = "org.gnome.Loupe.desktop";
fallbackImageViewer = "okularApplication_kimgio.desktop";
pdfViewer = "okularApplication_pdf.desktop";
comicViewer = "okularApplication_comicbook.desktop";
djvuViewer = "okularApplication_djvu.desktop";
ebookViewer = "okularApplication_epub.desktop";
mobiViewer = "okularApplication_mobi.desktop";
xpsViewer = "okularApplication_xps.desktop";
mediaPlayer = "vlc.desktop";
archiveManager = "org.gnome.FileRoller.desktop";
fileManager = "thunar.desktop";
wordProcessor = "writer.desktop";
spreadsheet = "calc.desktop";
presentation = "impress.desktop";
defaultApplications =
(mimeMap imageViewer [
"image/avif"
"image/bmp"
"image/gif"
"image/heic"
"image/jpeg"
"image/jxl"
"image/png"
"image/svg+xml"
"image/svg+xml-compressed"
"image/tiff"
"image/vnd.microsoft.icon"
"image/webp"
])
// (mimeMap fallbackImageViewer [
"image/heif"
])
// (mimeMap pdfViewer [
"application/pdf"
"application/x-bzpdf"
"application/x-gzpdf"
])
// (mimeMap comicViewer [
"application/x-cb7"
"application/x-cbr"
"application/x-cbt"
"application/x-cbz"
])
// (mimeMap djvuViewer [
"image/vnd.djvu"
])
// (mimeMap ebookViewer [
"application/epub+zip"
])
// (mimeMap mobiViewer [
"application/x-mobipocket-ebook"
])
// (mimeMap xpsViewer [
"application/oxps"
"application/vnd.ms-xpsdocument"
])
// (mimeMap mediaPlayer [
"application/ogg"
"audio/flac"
"audio/mp4"
"audio/mpeg"
"audio/ogg"
"audio/opus"
"audio/webm"
"audio/wav"
"audio/x-flac"
"audio/x-wav"
"video/mp4"
"video/ogg"
"video/quicktime"
"video/webm"
"video/x-matroska"
"video/x-msvideo"
])
// (mimeMap archiveManager [
"application/bzip2"
"application/gzip"
"application/vnd.rar"
"application/x-7z-compressed"
"application/x-bzip"
"application/x-compressed-tar"
"application/x-gzip"
"application/x-rar"
"application/x-rar-compressed"
"application/x-tar"
"application/x-xz"
"application/x-zip-compressed"
"application/zip"
"application/zstd"
])
// (mimeMap wordProcessor [
"application/msword"
"application/rtf"
"application/vnd.ms-word"
"application/vnd.oasis.opendocument.text"
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
])
// (mimeMap spreadsheet [
"application/vnd.ms-excel"
"application/vnd.oasis.opendocument.spreadsheet"
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
"text/csv"
"text/tab-separated-values"
])
// (mimeMap presentation [
"application/mspowerpoint"
"application/vnd.ms-powerpoint"
"application/vnd.oasis.opendocument.presentation"
"application/vnd.openxmlformats-officedocument.presentationml.presentation"
"application/vnd.openxmlformats-officedocument.presentationml.slideshow"
])
// (mimeMap fileManager [
"inode/directory"
])
// (mimeMap browser [
"application/rdf+xml"
"application/rss+xml"
"application/xhtml+xml"
"application/xhtml_xml"
"application/xml"
"text/html"
"text/xml"
"x-scheme-handler/about"
"x-scheme-handler/http"
"x-scheme-handler/https"
"x-scheme-handler/unknown"
])
// {
"x-scheme-handler/element" = ["element-desktop.desktop"];
"x-scheme-handler/magnet" = ["transmission-gtk.desktop"];
};
in {
enable = true; enable = true;
associations.added = defaultApplications;
associations.added = { inherit defaultApplications;
"video/x-matroska" = "vlc.desktop"; }
"audio/flac" = "vlc.desktop"; );
"image/jpeg" = "feh.desktop";
"video/x-msvideo" = "vlc.desktop";
"text/vnd.trolltech.linguist" = "vlc.desktop";
"audio/mpeg" = "vlc.desktop";
"application/pdf" = "okularApplication_pdf.desktop";
"image/png" = "okularApplication_kimgio.desktop";
"video/mp4" = [ "vlc.desktop" "org.gnome.Totem.desktop" ];
"x-scheme-handler/magnet" = "userapp-transmission-gtk-24GQLZ.desktop";
"element" = "element-desktop.desktop";
};
defaultApplications = {
"text/html" = "google-chrome.desktop";
"x-scheme-handler/http" = "google-chrome.desktop";
"x-scheme-handler/https" = "google-chrome.desktop";
"x-scheme-handler/about" = "google-chrome.desktop";
"x-scheme-handler/unknown" = "google-chrome.desktop";
"x-scheme-handler/magnet" = "userapp-transmission-gtk-24GQLZ.desktop";
"x-scheme-handler/element" = "element-desktop.desktop";
};
defaultApplicationPackages = [
pkgs.gthumb
];
};
xsession = { xsession = {
enable = true; enable = true;

View File

@@ -1,5 +1,12 @@
{ inputs, specialArgs, config, lib, realUsers, ... }:
{ {
inputs,
specialArgs,
config,
lib,
pkgs,
realUsers,
...
}: {
imports = [ imports = [
inputs.home-manager.nixosModules.home-manager inputs.home-manager.nixosModules.home-manager
]; ];
@@ -19,6 +26,29 @@
}; };
home-manager.useGlobalPkgs = true; home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true; home-manager.useUserPackages = true;
home-manager.backupCommand = pkgs.writeShellScript "home-manager-backup-command" ''
set -eu
target_path="$1"
backup_ext="''${HOME_MANAGER_BACKUP_EXT:-hm-backup}"
backup_path="''${target_path}.''${backup_ext}"
if [[ ! -e "$backup_path" ]]; then
mv -- "$target_path" "$backup_path"
exit 0
fi
timestamp="$(date +%Y%m%d-%H%M%S)"
candidate="''${backup_path}.''${timestamp}"
counter=0
while [[ -e "$candidate" ]]; do
counter=$((counter + 1))
candidate="''${backup_path}.''${timestamp}-''${counter}"
done
mv -- "$target_path" "$candidate"
'';
home-manager.backupFileExtension = "hm-backup"; home-manager.backupFileExtension = "hm-backup";
home-manager.sharedModules = [./home-manager.nix]; home-manager.sharedModules = [./home-manager.nix];
@@ -55,7 +85,8 @@
]; ];
}; };
nixpkgs.overlays = [ nixpkgs.overlays =
[
# (import ./nvidia-container-toolkit-overlay.nix) # (import ./nvidia-container-toolkit-overlay.nix)
(import ./runc-overlay.nix) (import ./runc-overlay.nix)
(import ./emacs-overlay.nix) (import ./emacs-overlay.nix)
@@ -66,7 +97,8 @@
claude-code = inputs.claude-code-nix.packages.${prev.stdenv.hostPlatform.system}.default; claude-code = inputs.claude-code-nix.packages.${prev.stdenv.hostPlatform.system}.default;
git-sync-rs = let git-sync-rs = let
base = inputs.git-sync-rs.packages.${prev.stdenv.hostPlatform.system}.default; base = inputs.git-sync-rs.packages.${prev.stdenv.hostPlatform.system}.default;
in prev.symlinkJoin { in
prev.symlinkJoin {
name = "${base.name}-wrapped"; name = "${base.name}-wrapped";
paths = [base]; paths = [base];
postBuild = '' postBuild = ''
@@ -75,7 +107,12 @@
''; '';
}; };
}) })
] ++ (if config.imalison.nixOverlay.enable then [ inputs.nix.overlays.default ] else []); ]
++ (
if config.imalison.nixOverlay.enable
then [inputs.nix.overlays.default]
else []
);
# Allow all the things # Allow all the things
nixpkgs.config.allowUnfree = true; nixpkgs.config.allowUnfree = true;