# nixos-config - My current NixOS configuration # # Copyright (C) 2025 Benedikt Peetz # SPDX-License-Identifier: GPL-3.0-or-later # # This file is part of my nixos-config. # # You should have received a copy of the License along with this program. # If not, see . { pkgs, lib, config, ... }: let lf-wrapper = pkgs.writeShellApplication { name = "lf-wrapper"; runtimeInputs = [pkgs.lf pkgs.alacritty]; inheritPath = true; text = builtins.readFile ./scripts/lf-wrapper.sh; }; url-handler = pkgs.writeShellApplication { name = "url-handler"; runtimeInputs = [pkgs.rofi pkgs.libnotify pkgs.zathura pkgs.tskm]; # We need to run the browser in tskm or nvim and alacritty. inheritPath = true; text = builtins.readFile ./scripts/url-handler.sh; }; tfcConfigFile = (pkgs.formats.ini {}).generate "xdg-desktop-portal-termfilechooser.ini" { filechooser = { default_dir = "/tmp"; cmd = "${lib.getExe lf-wrapper}"; }; }; cfg = config.soispha.xdg; in { options.soispha.xdg = { enable = lib.mkEnableOption "xdg"; }; config = lib.mkIf cfg.enable { home-manager.users.soispha.xdg = let inherit (config.home-manager.users.soispha.home) homeDirectory; in { enable = true; configFile."xdg-desktop-portal-termfilechooser/config".source = tfcConfigFile; configHome = "${homeDirectory}/.config"; dataHome = "${homeDirectory}/.local/share"; stateHome = "${homeDirectory}/.local/state"; cacheHome = "${homeDirectory}/.cache"; userDirs = { enable = true; # TODO: We shouldn't build on these variables to exist, but currently my config # might expect them. So let's just keep it. See here for a full explanation: # https://github.com/nix-community/home-manager/pull/7937#issuecomment-3372232126 # <2026-04-14> setSessionVariables = true; createDirectories = true; documents = "${homeDirectory}/documents/general"; download = "/tmp/download"; music = "${homeDirectory}/media/music"; pictures = "${homeDirectory}/media/pictures"; videos = "${homeDirectory}/media/videos"; templates = null; publicShare = null; desktop = null; }; desktopEntries = { url-handler = { name = "url-handler"; genericName = "Web Browser"; exec = "${lib.getExe url-handler} %u"; terminal = false; categories = [ "Application" "Network" "WebBrowser" ]; mimeType = [ "text/html" "text/xml" "x-scheme-handler/http" "x-scheme-handler/https" "x-scheme-handler/about" "x-scheme-handler/unknown" ]; }; }; }; xdg = { mime = { enable = true; defaultApplications = { "application/pdf" = ["url-handler.desktop"]; "application/x-pdf" = ["url-handler.desktop"]; "text/html" = ["url-handler.desktop"]; "text/xml" = ["url-handler.desktop"]; "x-scheme-handler/http" = ["url-handler.desktop"]; "x-scheme-handler/https" = ["url-handler.desktop"]; "x-scheme-handler/about" = ["url-handler.desktop"]; "x-scheme-handler/unknown" = ["url-handler.desktop"]; }; }; portal = { enable = true; wlr = { enable = true; }; config = { common = { default = ["wlr"]; "org.freedesktop.impl.portal.FileChooser" = ["termfilechooser"]; }; # TODO: Also activate, when on another wlr-based compositor <2023-11-25> river = { default = ["wlr"]; "org.freedesktop.impl.portal.FileChooser" = ["termfilechooser"]; }; }; extraPortals = [ pkgs.xdg-desktop-portal-wlr pkgs.xdg-desktop-portal-termfilechooser ]; }; }; services.dbus.enable = true; systemd.user.services.xdg-desktop-portal-termfilechooser = { serviceConfig.ExecStart = [ "" "${pkgs.xdg-desktop-portal-termfilechooser}/libexec/xdg-desktop-portal-termfilechooser --loglevel=TRACE" ]; }; }; }