nix/modules/stuff/xdg.nix

89 lines
2.7 KiB
Nix
Raw Normal View History

2024-08-01 21:22:47 +02:00
{ lib, pkgs, config, ...}: let
inherit (lib) mkIf mkEnableOption mkOption;
cfg = config.chuj.xdg;
in {
options.chuj.xdg = {
enable = mkEnableOption "xdg";
};
config = let
hmCfg = config.home-manager.users.${user};
HOME = hmCfg.home.homeDirectory;
in mkIf cfg.enable {
xdg.portal = {
enable = true;
xdgOpenUsePortal = true;
extraPortals = [ pkgs.xdg-desktop-portal-gtk ];
config.common.default = [ "*" ];
};
home-manager.users.${user} = {
xdg = {
dataHome = "${HOME}/.local/share";
configHome = "${HOME}/.config";
stateHome = "${HOME}/.local/state";
cacheHome = "${HOME}/.cache";
userDirs = {
enable = true;
desktop = "${HOME}/desktop";
documents = "${HOME}/documents";
download = "${HOME}/downloads";
music = "${HOME}/music";
pictures = "${HOME}/pictures";
publicShare = "${HOME}/public";
templates = "${HOME}/templates";
videos = "${HOME}/videos";
};
};
home.sessionVariables = {
XDG_DATA_HOME = hmCfg.xdg.dataHome;
XDG_CONFIG_HOME = hmCfg.xdg.configHome;
XDG_STATE_HOME = hmCfg.xdg.stateHome;
XDG_CACHE_HOME = hmCfg.xdg.cacheHome;
ANDROID_USER_HOME = "${XDG_DATA_HOME}/android";
ANDROID_HOME = "${XDG_DATA_HOME}/android/sdk";
GRADLE_USER_HOME = "${XDG_DATA_HOME}/gradle";
PYTHONSTARTUP = "${XDG_CONFIG_HOME}/python/pythonrc";
HISTFILE = "${XDG_CACHE_HOME}/bash/history";
CARGO_HOME = "${XDG_DATA_HOME}/cargo";
_JAVA_OPTIONS = "-Djava.utils.prefs.userRoot=${XDG_CONFIG_HOME}/java";
GNUPGHOME = "${XDG_DATA_HOME}/gnupg";
WINEPREFIX = "${XDG_DATA_HOME}/wine";
RUSTUP_HOME = "${XDG_DATA_HOME}/rustup";
NUGET_PACKAGES = "${XDG_CACHE_HOME}/NuGetPackages";
FCEUX_HOME = "${XDG_CONFIG_HOME}/fceux";
DOTNET_CLI_HOME = "${XDG_CONFIG_HOME}/dotnet";
GTK2_RC_FILES = lib.mkForce "${XDG_CONFIG_HOME}/gtk-2.0/gtkrc";
};
home.packages = with pkgs; [
xdg-user-dirs
xdg-utils
];
xdg.configFile = {
"python/pythonrc".text = ''
import os
import atexit
import readline
history = os.path.join(os.environ['XDG_CACHE_HOME'], 'python_history')
try:
readline.read_history_file(history)
except OSError:
pass
def write_history():
try:
readline.write_history_file(history)
except OSError:
pass
atexit.register(write_history)
'';
};
};
};
}