mirror of
https://github.com/nix-community/home-manager.git
synced 2024-12-14 11:57:55 +00:00
xdg: add module
When enabled this module will cause Home Manager to manage the user environment XDG variables. When disabled, then Home Manager will use the XDG variables taken from the user environment.
This commit is contained in:
parent
efb5256d28
commit
54a9058ee0
2 changed files with 139 additions and 0 deletions
|
@ -19,6 +19,7 @@ let
|
|||
./misc/news.nix
|
||||
./misc/nixpkgs.nix
|
||||
./misc/pam.nix
|
||||
./misc/xdg.nix
|
||||
./programs/bash.nix
|
||||
./programs/beets.nix
|
||||
./programs/browserpass.nix
|
||||
|
|
138
modules/misc/xdg.nix
Normal file
138
modules/misc/xdg.nix
Normal file
|
@ -0,0 +1,138 @@
|
|||
{ options, config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
|
||||
cfg = config.xdg;
|
||||
|
||||
fileType = basePath: (types.loaOf (types.submodule (
|
||||
{ name, config, ... }: {
|
||||
options = {
|
||||
target = mkOption {
|
||||
type = types.str;
|
||||
apply = p: "${cfg.configHome}/${p}";
|
||||
description = ''
|
||||
Path to target file relative to <varname>${basePath}</varname>.
|
||||
'';
|
||||
};
|
||||
|
||||
text = mkOption {
|
||||
default = null;
|
||||
type = types.nullOr types.lines;
|
||||
description = "Text of the file.";
|
||||
};
|
||||
|
||||
source = mkOption {
|
||||
type = types.path;
|
||||
description = ''
|
||||
Path of the source file. The file name must not start
|
||||
with a period since Nix will not allow such names in
|
||||
the Nix store.
|
||||
</para><para>
|
||||
This may refer to a directory.
|
||||
'';
|
||||
};
|
||||
|
||||
executable = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Whether the file should be executable.";
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
target = mkDefault name;
|
||||
source = mkIf (config.text != null) (
|
||||
let
|
||||
file = pkgs.writeTextFile {
|
||||
inherit (config) text executable;
|
||||
name = "user-etc-" + baseNameOf name;
|
||||
};
|
||||
in
|
||||
mkDefault file
|
||||
);
|
||||
};
|
||||
}
|
||||
)));
|
||||
|
||||
defaultCacheHome = "${config.home.homeDirectory}/.cache";
|
||||
defaultConfigHome = "${config.home.homeDirectory}/.config";
|
||||
defaultDataHome = "${config.home.homeDirectory}/.local/share";
|
||||
|
||||
getXdgDir = name: fallback:
|
||||
let
|
||||
value = builtins.getEnv name;
|
||||
in
|
||||
if value != "" then value else fallback;
|
||||
|
||||
in
|
||||
|
||||
{
|
||||
options.xdg = {
|
||||
enable = mkEnableOption "management of XDG base directories";
|
||||
|
||||
cacheHome = mkOption {
|
||||
type = types.path;
|
||||
defaultText = "~/.cache";
|
||||
description = ''
|
||||
Absolute path to directory holding application caches.
|
||||
'';
|
||||
};
|
||||
|
||||
configFile = mkOption {
|
||||
type = fileType "xdg.configHome";
|
||||
default = {};
|
||||
description = ''
|
||||
Attribute set of files to link into the user's XDG
|
||||
configuration home.
|
||||
'';
|
||||
};
|
||||
|
||||
configHome = mkOption {
|
||||
type = types.path;
|
||||
defaultText = "~/.config";
|
||||
description = ''
|
||||
Absolute path to directory holding application configurations.
|
||||
'';
|
||||
};
|
||||
|
||||
dataHome = mkOption {
|
||||
type = types.path;
|
||||
defaultText = "~/.local/share";
|
||||
description = ''
|
||||
Absolute path to directory holding application data.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config = mkMerge [
|
||||
(mkIf cfg.enable {
|
||||
xdg.cacheHome = mkDefault defaultCacheHome;
|
||||
xdg.configHome = mkDefault defaultConfigHome;
|
||||
xdg.dataHome = mkDefault defaultDataHome;
|
||||
|
||||
home.sessionVariables = {
|
||||
XDG_CACHE_HOME = cfg.cacheHome;
|
||||
XDG_CONFIG_HOME = cfg.configHome;
|
||||
XDG_DATA_HOME = cfg.dataHome;
|
||||
};
|
||||
})
|
||||
|
||||
(mkIf (!cfg.enable) {
|
||||
xdg.cacheHome = getXdgDir "XDG_CACHE_HOME" defaultCacheHome;
|
||||
xdg.configHome = getXdgDir "XDG_CONFIG_HOME" defaultConfigHome;
|
||||
xdg.dataHome = getXdgDir "XDG_DATA_HOME" defaultDataHome;
|
||||
})
|
||||
|
||||
{
|
||||
home.file =
|
||||
let
|
||||
f = n: v: {
|
||||
inherit (v) source target;
|
||||
mode = if v.executable then "777" else "444";
|
||||
};
|
||||
in mapAttrsToList f cfg.configFile;
|
||||
}
|
||||
];
|
||||
}
|
Loading…
Reference in a new issue