2019-09-05 11:18:43 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
2025-03-07 14:16:46 -06:00
|
|
|
inherit (lib) literalExpression mkOption types;
|
2019-09-05 11:18:43 +02:00
|
|
|
|
|
|
|
cfg = config.xdg.userDirs;
|
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
in {
|
2025-03-07 14:16:46 -06:00
|
|
|
meta.maintainers = with lib.maintainers; [ euxane ];
|
2019-09-05 11:18:43 +02:00
|
|
|
|
2020-01-13 10:48:07 +01:00
|
|
|
imports = [
|
2025-03-07 14:16:46 -06:00
|
|
|
(lib.mkRenamedOptionModule [ "xdg" "userDirs" "publishShare" ] [
|
2020-02-02 00:39:17 +01:00
|
|
|
"xdg"
|
|
|
|
"userDirs"
|
|
|
|
"publicShare"
|
|
|
|
])
|
2020-01-13 10:48:07 +01:00
|
|
|
];
|
|
|
|
|
2019-09-05 11:18:43 +02:00
|
|
|
options.xdg.userDirs = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2023-07-02 00:45:18 +01:00
|
|
|
description = ''
|
2023-07-01 00:30:13 +01:00
|
|
|
Whether to manage {file}`$XDG_CONFIG_HOME/user-dirs.dirs`.
|
|
|
|
|
2019-09-05 11:18:43 +02:00
|
|
|
The generated file is read-only.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
# Well-known directory list from
|
|
|
|
# https://gitlab.freedesktop.org/xdg/xdg-user-dirs/blob/master/man/user-dirs.dirs.xml
|
|
|
|
|
|
|
|
desktop = mkOption {
|
2022-11-12 09:35:01 -05:00
|
|
|
type = with types; nullOr (coercedTo path toString str);
|
2022-09-15 22:17:19 +02:00
|
|
|
default = "${config.home.homeDirectory}/Desktop";
|
|
|
|
defaultText =
|
|
|
|
literalExpression ''"''${config.home.homeDirectory}/Desktop"'';
|
2023-07-02 00:45:18 +01:00
|
|
|
description = "The Desktop directory.";
|
2019-09-05 11:18:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
documents = mkOption {
|
2022-11-12 09:35:01 -05:00
|
|
|
type = with types; nullOr (coercedTo path toString str);
|
2022-09-15 22:17:19 +02:00
|
|
|
default = "${config.home.homeDirectory}/Documents";
|
|
|
|
defaultText =
|
|
|
|
literalExpression ''"''${config.home.homeDirectory}/Documents"'';
|
2023-07-02 00:45:18 +01:00
|
|
|
description = "The Documents directory.";
|
2019-09-05 11:18:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
download = mkOption {
|
2022-11-12 09:35:01 -05:00
|
|
|
type = with types; nullOr (coercedTo path toString str);
|
2022-09-15 22:17:19 +02:00
|
|
|
default = "${config.home.homeDirectory}/Downloads";
|
|
|
|
defaultText =
|
|
|
|
literalExpression ''"''${config.home.homeDirectory}/Downloads"'';
|
2023-07-02 00:45:18 +01:00
|
|
|
description = "The Downloads directory.";
|
2019-09-05 11:18:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
music = mkOption {
|
2022-11-12 09:35:01 -05:00
|
|
|
type = with types; nullOr (coercedTo path toString str);
|
2022-09-15 22:17:19 +02:00
|
|
|
default = "${config.home.homeDirectory}/Music";
|
|
|
|
defaultText =
|
|
|
|
literalExpression ''"''${config.home.homeDirectory}/Music"'';
|
2023-07-02 00:45:18 +01:00
|
|
|
description = "The Music directory.";
|
2019-09-05 11:18:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
pictures = mkOption {
|
2022-11-12 09:35:01 -05:00
|
|
|
type = with types; nullOr (coercedTo path toString str);
|
2022-09-15 22:17:19 +02:00
|
|
|
default = "${config.home.homeDirectory}/Pictures";
|
|
|
|
defaultText =
|
|
|
|
literalExpression ''"''${config.home.homeDirectory}/Pictures"'';
|
2023-07-02 00:45:18 +01:00
|
|
|
description = "The Pictures directory.";
|
2019-09-05 11:18:43 +02:00
|
|
|
};
|
|
|
|
|
2020-01-13 10:48:07 +01:00
|
|
|
publicShare = mkOption {
|
2022-11-12 09:35:01 -05:00
|
|
|
type = with types; nullOr (coercedTo path toString str);
|
2022-09-15 22:17:19 +02:00
|
|
|
default = "${config.home.homeDirectory}/Public";
|
|
|
|
defaultText =
|
|
|
|
literalExpression ''"''${config.home.homeDirectory}/Public"'';
|
2023-07-02 00:45:18 +01:00
|
|
|
description = "The Public share directory.";
|
2019-09-05 11:18:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
templates = mkOption {
|
2022-11-12 09:35:01 -05:00
|
|
|
type = with types; nullOr (coercedTo path toString str);
|
2022-09-15 22:17:19 +02:00
|
|
|
default = "${config.home.homeDirectory}/Templates";
|
|
|
|
defaultText =
|
|
|
|
literalExpression ''"''${config.home.homeDirectory}/Templates"'';
|
2023-07-02 00:45:18 +01:00
|
|
|
description = "The Templates directory.";
|
2019-09-05 11:18:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
videos = mkOption {
|
2022-11-12 09:35:01 -05:00
|
|
|
type = with types; nullOr (coercedTo path toString str);
|
2022-09-15 22:17:19 +02:00
|
|
|
default = "${config.home.homeDirectory}/Videos";
|
|
|
|
defaultText =
|
|
|
|
literalExpression ''"''${config.home.homeDirectory}/Videos"'';
|
2023-07-02 00:45:18 +01:00
|
|
|
description = "The Videos directory.";
|
2019-09-05 11:18:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
2022-04-05 06:32:03 +03:00
|
|
|
type = with types; attrsOf (coercedTo path toString str);
|
2019-09-05 11:18:43 +02:00
|
|
|
default = { };
|
2022-04-05 06:32:03 +03:00
|
|
|
defaultText = literalExpression "{ }";
|
|
|
|
example = literalExpression ''
|
|
|
|
{
|
2022-09-15 22:17:19 +02:00
|
|
|
XDG_MISC_DIR = "''${config.home.homeDirectory}/Misc";
|
2022-04-05 06:32:03 +03:00
|
|
|
}
|
|
|
|
'';
|
2023-07-02 00:45:18 +01:00
|
|
|
description = "Other user directories.";
|
2019-09-05 11:18:43 +02:00
|
|
|
};
|
2021-02-22 23:17:23 -03:00
|
|
|
|
2023-07-02 00:45:18 +01:00
|
|
|
createDirectories =
|
2025-03-07 14:16:46 -06:00
|
|
|
lib.mkEnableOption "automatic creation of the XDG user directories";
|
2019-09-05 11:18:43 +02:00
|
|
|
};
|
|
|
|
|
2021-02-22 23:17:23 -03:00
|
|
|
config = let
|
2025-03-07 14:16:46 -06:00
|
|
|
directories = (lib.filterAttrs (n: v: !isNull v) {
|
2021-02-22 23:17:23 -03:00
|
|
|
XDG_DESKTOP_DIR = cfg.desktop;
|
|
|
|
XDG_DOCUMENTS_DIR = cfg.documents;
|
|
|
|
XDG_DOWNLOAD_DIR = cfg.download;
|
|
|
|
XDG_MUSIC_DIR = cfg.music;
|
|
|
|
XDG_PICTURES_DIR = cfg.pictures;
|
|
|
|
XDG_PUBLICSHARE_DIR = cfg.publicShare;
|
|
|
|
XDG_TEMPLATES_DIR = cfg.templates;
|
|
|
|
XDG_VIDEOS_DIR = cfg.videos;
|
2022-11-12 09:35:01 -05:00
|
|
|
}) // cfg.extraConfig;
|
2025-03-07 14:16:46 -06:00
|
|
|
in lib.mkIf cfg.enable {
|
|
|
|
assertions = [
|
|
|
|
(lib.hm.assertions.assertPlatform "xdg.userDirs" pkgs lib.platforms.linux)
|
|
|
|
];
|
2021-07-07 23:24:27 +02:00
|
|
|
|
2020-08-12 22:51:20 +02:00
|
|
|
xdg.configFile."user-dirs.dirs".text = let
|
|
|
|
# For some reason, these need to be wrapped with quotes to be valid.
|
2025-03-07 14:16:46 -06:00
|
|
|
wrapped = lib.mapAttrs (_: value: ''"${value}"'') directories;
|
|
|
|
in lib.generators.toKeyValue { } wrapped;
|
2020-04-12 20:39:52 +02:00
|
|
|
|
|
|
|
xdg.configFile."user-dirs.conf".text = "enabled=False";
|
2021-02-22 23:17:23 -03:00
|
|
|
|
2022-04-05 06:32:03 +03:00
|
|
|
home.sessionVariables = directories;
|
|
|
|
|
2025-03-07 14:16:46 -06:00
|
|
|
home.activation.createXdgUserDirectories = lib.mkIf cfg.createDirectories
|
|
|
|
(let
|
|
|
|
directoriesList = lib.attrValues directories;
|
|
|
|
mkdir =
|
|
|
|
(dir: ''[[ -L "${dir}" ]] || run mkdir -p $VERBOSE_ARG "${dir}"'');
|
|
|
|
in lib.hm.dag.entryAfter [ "linkGeneration" ]
|
|
|
|
(lib.strings.concatMapStringsSep "\n" mkdir directoriesList));
|
2019-09-05 11:18:43 +02:00
|
|
|
};
|
|
|
|
}
|