1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-23 03:29:45 +01: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 # https://gitlab.freedesktop.org/xdg/xdg-user-dirs/blob/master/man/user-dirs.dirs.xml
desktop = mkOption { desktop = mkOption {
type = with types; coercedTo path toString str; type = with types; nullOr (coercedTo path toString str);
default = "${config.home.homeDirectory}/Desktop"; default = "${config.home.homeDirectory}/Desktop";
defaultText = defaultText =
literalExpression ''"''${config.home.homeDirectory}/Desktop"''; literalExpression ''"''${config.home.homeDirectory}/Desktop"'';
@ -41,7 +41,7 @@ in {
}; };
documents = mkOption { documents = mkOption {
type = with types; coercedTo path toString str; type = with types; nullOr (coercedTo path toString str);
default = "${config.home.homeDirectory}/Documents"; default = "${config.home.homeDirectory}/Documents";
defaultText = defaultText =
literalExpression ''"''${config.home.homeDirectory}/Documents"''; literalExpression ''"''${config.home.homeDirectory}/Documents"'';
@ -49,7 +49,7 @@ in {
}; };
download = mkOption { download = mkOption {
type = with types; coercedTo path toString str; type = with types; nullOr (coercedTo path toString str);
default = "${config.home.homeDirectory}/Downloads"; default = "${config.home.homeDirectory}/Downloads";
defaultText = defaultText =
literalExpression ''"''${config.home.homeDirectory}/Downloads"''; literalExpression ''"''${config.home.homeDirectory}/Downloads"'';
@ -57,7 +57,7 @@ in {
}; };
music = mkOption { music = mkOption {
type = with types; coercedTo path toString str; type = with types; nullOr (coercedTo path toString str);
default = "${config.home.homeDirectory}/Music"; default = "${config.home.homeDirectory}/Music";
defaultText = defaultText =
literalExpression ''"''${config.home.homeDirectory}/Music"''; literalExpression ''"''${config.home.homeDirectory}/Music"'';
@ -65,7 +65,7 @@ in {
}; };
pictures = mkOption { pictures = mkOption {
type = with types; coercedTo path toString str; type = with types; nullOr (coercedTo path toString str);
default = "${config.home.homeDirectory}/Pictures"; default = "${config.home.homeDirectory}/Pictures";
defaultText = defaultText =
literalExpression ''"''${config.home.homeDirectory}/Pictures"''; literalExpression ''"''${config.home.homeDirectory}/Pictures"'';
@ -73,7 +73,7 @@ in {
}; };
publicShare = mkOption { publicShare = mkOption {
type = with types; coercedTo path toString str; type = with types; nullOr (coercedTo path toString str);
default = "${config.home.homeDirectory}/Public"; default = "${config.home.homeDirectory}/Public";
defaultText = defaultText =
literalExpression ''"''${config.home.homeDirectory}/Public"''; literalExpression ''"''${config.home.homeDirectory}/Public"'';
@ -81,7 +81,7 @@ in {
}; };
templates = mkOption { templates = mkOption {
type = with types; coercedTo path toString str; type = with types; nullOr (coercedTo path toString str);
default = "${config.home.homeDirectory}/Templates"; default = "${config.home.homeDirectory}/Templates";
defaultText = defaultText =
literalExpression ''"''${config.home.homeDirectory}/Templates"''; literalExpression ''"''${config.home.homeDirectory}/Templates"'';
@ -89,7 +89,7 @@ in {
}; };
videos = mkOption { videos = mkOption {
type = with types; coercedTo path toString str; type = with types; nullOr (coercedTo path toString str);
default = "${config.home.homeDirectory}/Videos"; default = "${config.home.homeDirectory}/Videos";
defaultText = defaultText =
literalExpression ''"''${config.home.homeDirectory}/Videos"''; literalExpression ''"''${config.home.homeDirectory}/Videos"'';
@ -113,7 +113,7 @@ in {
}; };
config = let config = let
directories = { directories = (filterAttrs (n: v: !isNull v) {
XDG_DESKTOP_DIR = cfg.desktop; XDG_DESKTOP_DIR = cfg.desktop;
XDG_DOCUMENTS_DIR = cfg.documents; XDG_DOCUMENTS_DIR = cfg.documents;
XDG_DOWNLOAD_DIR = cfg.download; XDG_DOWNLOAD_DIR = cfg.download;
@ -122,7 +122,7 @@ in {
XDG_PUBLICSHARE_DIR = cfg.publicShare; XDG_PUBLICSHARE_DIR = cfg.publicShare;
XDG_TEMPLATES_DIR = cfg.templates; XDG_TEMPLATES_DIR = cfg.templates;
XDG_VIDEOS_DIR = cfg.videos; XDG_VIDEOS_DIR = cfg.videos;
} // cfg.extraConfig; }) // cfg.extraConfig;
in mkIf cfg.enable { in mkIf cfg.enable {
assertions = assertions =
[ (hm.assertions.assertPlatform "xdg.userDirs" pkgs platforms.linux) ]; [ (hm.assertions.assertPlatform "xdg.userDirs" pkgs platforms.linux) ];

View file

@ -4,4 +4,5 @@
xdg-desktop-entries = ./desktop-entries.nix; xdg-desktop-entries = ./desktop-entries.nix;
xdg-file-gen = ./file-gen.nix; xdg-file-gen = ./file-gen.nix;
xdg-default-locations = ./default-locations.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"
''
}
'';
};
}