nix/modules/stuff/xdg.nix

93 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;
2024-08-06 13:41:05 +02:00
user = config.chuj.system.user;
2024-08-01 21:22:47 +02:00
in {
options.chuj.xdg = {
enable = mkEnableOption "xdg";
};
2024-10-16 11:40:24 +02:00
2024-08-01 21:22:47 +02:00
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;
2024-08-02 19:42:56 +02:00
desktop = "${HOME}/Desktop";
documents = "${HOME}/Documents";
download = "${HOME}/Downloads";
music = "${HOME}/Music";
pictures = "${HOME}/Pictures";
publicShare = "${HOME}/Public";
templates = "${HOME}/Templates";
videos = "${HOME}/Videos";
2024-08-01 21:22:47 +02:00
};
};
2024-08-06 13:41:05 +02:00
home.sessionVariables = let
2024-08-01 21:22:47 +02:00
XDG_DATA_HOME = hmCfg.xdg.dataHome;
XDG_CONFIG_HOME = hmCfg.xdg.configHome;
XDG_STATE_HOME = hmCfg.xdg.stateHome;
XDG_CACHE_HOME = hmCfg.xdg.cacheHome;
2024-08-06 13:41:05 +02:00
in {
2024-08-01 21:22:47 +02:00
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 = {
2024-10-16 11:40:24 +02:00
# todo: XDG_CACHE_HOME Not found
2024-08-01 21:22:47 +02:00
"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)
'';
};
};
};
2024-08-02 19:42:56 +02:00
}