1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-23 19:49:45 +01:00
home-manager/modules/misc/xdg-user-dirs.nix
Emily 36a53d9f26 treewide: convert all option docs to Markdown
This process was automated by [my fork of `nix-doc-munge`]. All
conversions were automatically checked to produce the same DocBook
result when converted back, modulo minor typographical/formatting
differences on the acceptable-to-desirable spectrum.

To reproduce this commit, run:

  $ NIX_PATH=nixpkgs=flake:nixpkgs/e7e69199f0372364a6106a1e735f68604f4c5a25 \
    nix shell nixpkgs#coreutils \
    -c find . -name '*.nix' \
    -exec nix run -- github:emilazy/nix-doc-munge/98dadf1f77351c2ba5dcb709a2a171d655f15099 \
    {} +
  $ ./format

[my fork of `nix-doc-munge`]: https://github.com/emilazy/nix-doc-munge/tree/home-manager
2023-07-17 18:40:56 +01:00

144 lines
4.6 KiB
Nix

{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.xdg.userDirs;
in {
meta.maintainers = with maintainers; [ pacien ];
imports = [
(mkRenamedOptionModule [ "xdg" "userDirs" "publishShare" ] [
"xdg"
"userDirs"
"publicShare"
])
];
options.xdg.userDirs = {
enable = mkOption {
type = types.bool;
default = false;
description = lib.mdDoc ''
Whether to manage {file}`$XDG_CONFIG_HOME/user-dirs.dirs`.
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 {
type = with types; nullOr (coercedTo path toString str);
default = "${config.home.homeDirectory}/Desktop";
defaultText =
literalExpression ''"''${config.home.homeDirectory}/Desktop"'';
description = lib.mdDoc "The Desktop directory.";
};
documents = mkOption {
type = with types; nullOr (coercedTo path toString str);
default = "${config.home.homeDirectory}/Documents";
defaultText =
literalExpression ''"''${config.home.homeDirectory}/Documents"'';
description = lib.mdDoc "The Documents directory.";
};
download = mkOption {
type = with types; nullOr (coercedTo path toString str);
default = "${config.home.homeDirectory}/Downloads";
defaultText =
literalExpression ''"''${config.home.homeDirectory}/Downloads"'';
description = lib.mdDoc "The Downloads directory.";
};
music = mkOption {
type = with types; nullOr (coercedTo path toString str);
default = "${config.home.homeDirectory}/Music";
defaultText =
literalExpression ''"''${config.home.homeDirectory}/Music"'';
description = lib.mdDoc "The Music directory.";
};
pictures = mkOption {
type = with types; nullOr (coercedTo path toString str);
default = "${config.home.homeDirectory}/Pictures";
defaultText =
literalExpression ''"''${config.home.homeDirectory}/Pictures"'';
description = lib.mdDoc "The Pictures directory.";
};
publicShare = mkOption {
type = with types; nullOr (coercedTo path toString str);
default = "${config.home.homeDirectory}/Public";
defaultText =
literalExpression ''"''${config.home.homeDirectory}/Public"'';
description = lib.mdDoc "The Public share directory.";
};
templates = mkOption {
type = with types; nullOr (coercedTo path toString str);
default = "${config.home.homeDirectory}/Templates";
defaultText =
literalExpression ''"''${config.home.homeDirectory}/Templates"'';
description = lib.mdDoc "The Templates directory.";
};
videos = mkOption {
type = with types; nullOr (coercedTo path toString str);
default = "${config.home.homeDirectory}/Videos";
defaultText =
literalExpression ''"''${config.home.homeDirectory}/Videos"'';
description = lib.mdDoc "The Videos directory.";
};
extraConfig = mkOption {
type = with types; attrsOf (coercedTo path toString str);
default = { };
defaultText = literalExpression "{ }";
example = literalExpression ''
{
XDG_MISC_DIR = "''${config.home.homeDirectory}/Misc";
}
'';
description = lib.mdDoc "Other user directories.";
};
createDirectories = mkEnableOption
(lib.mdDoc "automatic creation of the XDG user directories");
};
config = let
directories = (filterAttrs (n: v: !isNull v) {
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;
}) // cfg.extraConfig;
in mkIf cfg.enable {
assertions =
[ (hm.assertions.assertPlatform "xdg.userDirs" pkgs platforms.linux) ];
xdg.configFile."user-dirs.dirs".text = let
# For some reason, these need to be wrapped with quotes to be valid.
wrapped = mapAttrs (_: value: ''"${value}"'') directories;
in generators.toKeyValue { } wrapped;
xdg.configFile."user-dirs.conf".text = "enabled=False";
home.sessionVariables = directories;
home.activation.createXdgUserDirectories = mkIf cfg.createDirectories (let
directoriesList = attrValues directories;
mkdir = (dir: ''$DRY_RUN_CMD mkdir -p $VERBOSE_ARG "${dir}"'');
in lib.hm.dag.entryAfter [ "linkGeneration" ]
(strings.concatMapStringsSep "\n" mkdir directoriesList));
};
}