1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2024-12-14 11:57:55 +00:00

xdg-user-dirs: allow setting to null to skip setting

Previously, this module was all-or-nothing with its pre-defined user
dirs. This allows e.g. `xdg.userDirs.desktop = null;` to opt-out of
some configuration while still benefiting from the rest.
This commit is contained in:
Andrew Marshall 2022-11-12 09:35:01 -05:00 committed by Robert Helgesson
parent 651db464dc
commit bc90de24d8
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
3 changed files with 37 additions and 10 deletions

View file

@ -33,7 +33,7 @@ in {
# https://gitlab.freedesktop.org/xdg/xdg-user-dirs/blob/master/man/user-dirs.dirs.xml
desktop = mkOption {
type = with types; coercedTo path toString str;
type = with types; nullOr (coercedTo path toString str);
default = "${config.home.homeDirectory}/Desktop";
defaultText =
literalExpression ''"''${config.home.homeDirectory}/Desktop"'';
@ -41,7 +41,7 @@ in {
};
documents = mkOption {
type = with types; coercedTo path toString str;
type = with types; nullOr (coercedTo path toString str);
default = "${config.home.homeDirectory}/Documents";
defaultText =
literalExpression ''"''${config.home.homeDirectory}/Documents"'';
@ -49,7 +49,7 @@ in {
};
download = mkOption {
type = with types; coercedTo path toString str;
type = with types; nullOr (coercedTo path toString str);
default = "${config.home.homeDirectory}/Downloads";
defaultText =
literalExpression ''"''${config.home.homeDirectory}/Downloads"'';
@ -57,7 +57,7 @@ in {
};
music = mkOption {
type = with types; coercedTo path toString str;
type = with types; nullOr (coercedTo path toString str);
default = "${config.home.homeDirectory}/Music";
defaultText =
literalExpression ''"''${config.home.homeDirectory}/Music"'';
@ -65,7 +65,7 @@ in {
};
pictures = mkOption {
type = with types; coercedTo path toString str;
type = with types; nullOr (coercedTo path toString str);
default = "${config.home.homeDirectory}/Pictures";
defaultText =
literalExpression ''"''${config.home.homeDirectory}/Pictures"'';
@ -73,7 +73,7 @@ in {
};
publicShare = mkOption {
type = with types; coercedTo path toString str;
type = with types; nullOr (coercedTo path toString str);
default = "${config.home.homeDirectory}/Public";
defaultText =
literalExpression ''"''${config.home.homeDirectory}/Public"'';
@ -81,7 +81,7 @@ in {
};
templates = mkOption {
type = with types; coercedTo path toString str;
type = with types; nullOr (coercedTo path toString str);
default = "${config.home.homeDirectory}/Templates";
defaultText =
literalExpression ''"''${config.home.homeDirectory}/Templates"'';
@ -89,7 +89,7 @@ in {
};
videos = mkOption {
type = with types; coercedTo path toString str;
type = with types; nullOr (coercedTo path toString str);
default = "${config.home.homeDirectory}/Videos";
defaultText =
literalExpression ''"''${config.home.homeDirectory}/Videos"'';
@ -113,7 +113,7 @@ in {
};
config = let
directories = {
directories = (filterAttrs (n: v: !isNull v) {
XDG_DESKTOP_DIR = cfg.desktop;
XDG_DOCUMENTS_DIR = cfg.documents;
XDG_DOWNLOAD_DIR = cfg.download;
@ -122,7 +122,7 @@ in {
XDG_PUBLICSHARE_DIR = cfg.publicShare;
XDG_TEMPLATES_DIR = cfg.templates;
XDG_VIDEOS_DIR = cfg.videos;
} // cfg.extraConfig;
}) // cfg.extraConfig;
in mkIf cfg.enable {
assertions =
[ (hm.assertions.assertPlatform "xdg.userDirs" pkgs platforms.linux) ];

View file

@ -4,4 +4,5 @@
xdg-desktop-entries = ./desktop-entries.nix;
xdg-file-gen = ./file-gen.nix;
xdg-default-locations = ./default-locations.nix;
xdg-user-dirs-null = ./user-dirs-null.nix;
}

View file

@ -0,0 +1,26 @@
{ config, lib, pkgs, ... }:
{
config = {
xdg.userDirs = {
enable = true;
desktop = null;
};
nmt.script = ''
configFile=home-files/.config/user-dirs.dirs
assertFileExists $configFile
assertFileContent $configFile ${
pkgs.writeText "expected" ''
XDG_DOCUMENTS_DIR="/home/hm-user/Documents"
XDG_DOWNLOAD_DIR="/home/hm-user/Downloads"
XDG_MUSIC_DIR="/home/hm-user/Music"
XDG_PICTURES_DIR="/home/hm-user/Pictures"
XDG_PUBLICSHARE_DIR="/home/hm-user/Public"
XDG_TEMPLATES_DIR="/home/hm-user/Templates"
XDG_VIDEOS_DIR="/home/hm-user/Videos"
''
}
'';
};
}