From 78dc8978e68dcd6e13892bf019bf772d675f48ca Mon Sep 17 00:00:00 2001 From: isabel Date: Fri, 03 Jul 2026 16:52:14 +0000 Subject: [PATCH] lib: remove xdg template --- modules/flake/lib/default.nix | 1 - modules/flake/lib/template/default.nix | 3 --- modules/flake/lib/template/xdg.nix | 114 ------------------------------------------------------------------------------------------------------------------ modules/home/environment/xdg.nix | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- modules/nixos/environment/default.nix | 1 - modules/nixos/environment/xdg.nix | 14 -------------- 6 file(s) changed, 78 insertion(s)(+), 141 deletion(s)(-) diff --git a/modules/flake/lib/default.nix b/modules/flake/lib/default.nix --- a/modules/flake/lib/default.nix +++ b/modules/flake/lib/default.nix @@ -10,7 +10,6 @@ helpers = import ./helpers.nix { inherit lib; }; mkHost = import ./mkhost.nix { inherit inputs lib; }; secrets = import ./secrets.nix { inherit inputs; }; services = import ./services.nix { inherit lib; }; - template = import ./template; # templates, selections of code that are repeated validators = import ./validators.nix { inherit lib; }; # keep-sorted end diff --git a/modules/flake/lib/template/default.nix b/modules/flake/lib/template/default.nix deleted file mode 100644 --- a/modules/flake/lib/template/default.nix +++ /dev/null @@ -1,3 +0,0 @@ -{ - xdg = import ./xdg.nix; -} diff --git a/modules/flake/lib/template/xdg.nix b/modules/flake/lib/template/xdg.nix deleted file mode 100644 --- a/modules/flake/lib/template/xdg.nix +++ /dev/null @@ -1,114 +0,0 @@ -# You can generate something like this using xdg-ninja -let - XDG_CONFIG_HOME = "$HOME/.config"; - XDG_CACHE_HOME = "$HOME/.cache"; - XDG_DATA_HOME = "$HOME/.local/share"; - XDG_STATE_HOME = "$HOME/.local/state"; - XDG_BIN_HOME = "$HOME/.local/bin"; - XDG_RUNTIME_DIR = "/run/user/$UID"; -in -{ - simple = { - dataHome = XDG_DATA_HOME; - configHome = XDG_CONFIG_HOME; - cacheHome = XDG_CACHE_HOME; - }; - - # global env - global = { - inherit - XDG_CONFIG_HOME - XDG_CACHE_HOME - XDG_DATA_HOME - XDG_STATE_HOME - XDG_BIN_HOME - XDG_RUNTIME_DIR - ; - PATH = [ "$XDG_BIN_HOME" ]; - }; - - user = - xdg: - let - data = xdg.dataHome; - config = xdg.configHome; - cache = xdg.cacheHome; - in - { - # desktop - KDEHOME = "${config}/kde"; - XCOMPOSECACHE = "${cache}/X11/xcompose"; - ERRFILE = "${cache}/X11/xsession-errors"; - WINEPREFIX = "${data}/wine"; - - # programs - GNUPGHOME = "${data}/gnupg"; - LESSHISTFILE = "${data}/less/history"; - CUDA_CACHE_PATH = "${cache}/nv"; - STEPPATH = "${data}/step"; - WAKATIME_HOME = "${config}/wakatime"; - INPUTRC = "${config}/readline/inputrc"; - PLATFORMIO_CORE_DIR = "${data}/platformio"; - DOTNET_CLI_HOME = "${data}/dotnet"; - MPLAYER_HOME = "${config}/mplayer"; - SQLITE_HISTORY = "${cache}/sqlite_history"; - - # programming - ANDROID_HOME = "${data}/android"; - ANDROID_USER_HOME = "${data}/android"; - GRADLE_USER_HOME = "${data}/gradle"; - IPYTHONDIR = "${config}/ipython"; - JUPYTER_CONFIG_DIR = "${config}/jupyter"; - GOPATH = "${data}/go"; - GOMODCACHE = "${cache}/go/pkg/mod"; - M2_HOME = "${data}/m2"; - CARGO_HOME = "${data}/cargo"; - RUSTUP_HOME = "${data}/rustup"; - STACK_ROOT = "${data}/stack"; - STACK_XDG = 1; - NODE_REPL_HISTORY = "${data}/node_repl_history"; - NPM_CONFIG_CACHE = "${cache}/npm"; - NPM_CONFIG_TMP = "${XDG_RUNTIME_DIR}/npm"; - NPM_CONFIG_USERCONFIG = "${config}/npm/config"; - }; - - npmrc.text = '' - prefix=''${data}/npm - cache=''${cache}/npm - init-module=''${config}/npm/config/npm-init.js - ''; - - pythonrc.text = '' - import os - import atexit - import readline - from pathlib import Path - - if readline.get_current_history_length() == 0: - - state_home = os.environ.get("state") - if state_home is None: - state_home = Path.home() / ".local" / "state" - else: - state_home = Path(state_home) - - history_path = state_home / "python_history" - if history_path.is_dir(): - raise OSError(f"'{history_path}' cannot be a directory") - - history = str(history_path) - - try: - readline.read_history_file(history) - except OSError: # Non existent - pass - - def write_history(): - try: - readline.write_history_file(history) - except OSError: - pass - - atexit.register(write_history) - ''; -} diff --git a/modules/home/environment/xdg.nix b/modules/home/environment/xdg.nix --- a/modules/home/environment/xdg.nix +++ b/modules/home/environment/xdg.nix @@ -1,16 +1,12 @@ { lib, pkgs, - self, config, ... }: let inherit (lib.modules) mkForce; inherit (pkgs.stdenv.hostPlatform) isLinux; - - template = self.lib.template.xdg; - vars = template.user config.xdg; appsToAssoc = { browser = { @@ -78,6 +74,8 @@ "x-scheme-handler/discord" = [ "discord.desktop" ]; }; associations = associations' // specifics; + + cfg = config.xdg; in { home.preferXdgDirectories = true; @@ -120,12 +118,84 @@ portal.enable = lib.mkForce false; }; - home.sessionVariables = vars // { - GNUPGHOME = mkForce vars.GNUPGHOME; + # You can generate something like this using xdg-ninja + home.sessionVariables = { + # desktop + KDEHOME = "${cfg.configHome}/kde"; + XCOMPOSECACHE = "${cfg.cacheHome}/X11/xcompose"; + ERRFILE = "${cfg.cacheHome}/X11/xsession-errors"; + WINEPREFIX = "${cfg.dataHome}/wine"; + + # programs + GNUPGHOME = mkForce "${cfg.dataHome}/gnupg"; + LESSHISTFILE = "${cfg.dataHome}/less/history"; + CUDA_CACHE_PATH = "${cfg.cacheHome}/nv"; + STEPPATH = "${cfg.dataHome}/step"; + WAKATIME_HOME = "${cfg.configHome}/wakatime"; + INPUTRC = "${cfg.configHome}/readline/inputrc"; + PLATFORMIO_CORE_DIR = "${cfg.dataHome}/platformio"; + DOTNET_CLI_HOME = "${cfg.dataHome}/dotnet"; + MPLAYER_HOME = "${cfg.configHome}/mplayer"; + SQLITE_HISTORY = "${cfg.cacheHome}/sqlite_history"; + + # programming + ANDROID_HOME = "${cfg.dataHome}/android"; + ANDROID_USER_HOME = "${cfg.dataHome}/android"; + GRADLE_USER_HOME = "${cfg.dataHome}/gradle"; + IPYTHONDIR = "${cfg.configHome}/ipython"; + JUPYTER_CONFIG_DIR = "${cfg.configHome}/jupyter"; + GOPATH = "${cfg.dataHome}/go"; + GOMODCACHE = "${cfg.cacheHome}/go/pkg/mod"; + M2_HOME = "${cfg.dataHome}/m2"; + CARGO_HOME = "${cfg.dataHome}/cargo"; + RUSTUP_HOME = "${cfg.dataHome}/rustup"; + STACK_ROOT = "${cfg.dataHome}/stack"; + STACK_XDG = 1; + NODE_REPL_HISTORY = "${cfg.dataHome}/node_repl_history"; + NPM_CONFIG_CACHE = "${cfg.cacheHome}/npm"; + NPM_CONFIG_TMP = "/run/user/$UID/npm"; + NPM_CONFIG_USERCONFIG = "${cfg.configHome}/npm/config"; }; xdg.configFile = { - "npm/npmrc" = template.npmrc; - "python/pythonrc" = template.pythonrc; + "npm/npmrc".text = '' + prefix=''${cfg.dataHome}/npm + cache=''${cfg.cacheHome}/npm + init-module=''${cfg.configHome}/npm/config/npm-init.js + ''; + + "python/pythonrc".text = '' + import os + import atexit + import readline + from pathlib import Path + + if readline.get_current_history_length() == 0: + + state_home = os.environ.get("state") + if state_home is None: + state_home = Path.home() / ".local" / "state" + else: + state_home = Path(state_home) + + history_path = state_home / "python_history" + if history_path.is_dir(): + raise OSError(f"'{history_path}' cannot be a directory") + + history = str(history_path) + + try: + readline.read_history_file(history) + except OSError: # Non existent + pass + + def write_history(): + try: + readline.write_history_file(history) + except OSError: + pass + + atexit.register(write_history) + ''; }; } diff --git a/modules/nixos/environment/default.nix b/modules/nixos/environment/default.nix --- a/modules/nixos/environment/default.nix +++ b/modules/nixos/environment/default.nix @@ -7,7 +7,6 @@ ./fonts.nix # fonts ./locale.nix # locale settings ./paths.nix # paths ./wayland.nix # wayland settings - ./xdg.nix # move everything to nice placee ./zswap.nix # zswap optimisation and enabling # keep-sorted end ]; diff --git a/modules/nixos/environment/xdg.nix b/modules/nixos/environment/xdg.nix deleted file mode 100644 --- a/modules/nixos/environment/xdg.nix +++ /dev/null @@ -1,14 +0,0 @@ -{ self, ... }: -let - template = self.lib.template.xdg; -in -{ - environment = { - variables = template.global; - etc = { - inherit (template) pythonrc npmrc; - }; - - sessionVariables = template.user template.simple; - }; -} -- tangled.sh