1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-23 11:39:46 +01:00

home-environment: make sessionVariables a freeform module

Specifically, introduce explicit options for `PATH` and `NIX_PATH`.
This commit is contained in:
Robert Helgesson 2021-01-31 20:39:51 +01:00
parent 63d5d28db6
commit fa8692f84c
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
4 changed files with 87 additions and 2 deletions

View file

@ -229,7 +229,30 @@ in
home.sessionVariables = mkOption { home.sessionVariables = mkOption {
default = {}; default = {};
type = types.attrs; type = types.submodule {
freeformType = with types;
lazyAttrsOf (oneOf [ package str int float ]);
options = {
PATH = mkOption {
type = types.envVar;
default = "$PATH";
defaultText = literalExample ''"$PATH"'';
description = ''
Content of the <envar>PATH</envar> variable.
'';
};
NIX_PATH = mkOption {
type = types.envVar;
default = "$NIX_PATH";
defaultText = literalExample ''"$NIX_PATH"'';
description = ''
Content of the <envar>NIX_PATH</envar> variable.
'';
};
};
};
example = { EDITOR = "emacs"; GS_OPTIONS = "-sPAPERSIZE=a4"; }; example = { EDITOR = "emacs"; GS_OPTIONS = "-sPAPERSIZE=a4"; };
description = '' description = ''
Environment variables to always set at login. Environment variables to always set at login.

View file

@ -1,4 +1,5 @@
{ {
home-session-variables = ./session-variables.nix;
home-session-path = ./session-path.nix; home-session-path = ./session-path.nix;
home-session-variables = ./session-variables.nix;
home-session-variables-explicit = ./session-variables-explicit.nix;
} }

View file

@ -0,0 +1,57 @@
# Test of explicitly defined options inside the `home.sessionVariables` freeform
# module.
{ config, lib, pkgs, ... }:
let
inherit (pkgs.stdenv.hostPlatform) isDarwin;
linuxExpected = ''
# Only source this once.
if [ -n "$__HM_SESS_VARS_SOURCED" ]; then return; fi
export __HM_SESS_VARS_SOURCED=1
export LOCALE_ARCHIVE_2_27="${pkgs.glibcLocales}/lib/locale/locale-archive"
export NIX_PATH="testpath=$HOME/testpath:$NIX_PATH"
export PATH="$PATH:$HOME/bin"
export XDG_CACHE_HOME="/home/hm-user/.cache"
export XDG_CONFIG_HOME="/home/hm-user/.config"
export XDG_DATA_HOME="/home/hm-user/.local/share"
'';
darwinExpected = ''
# Only source this once.
if [ -n "$__HM_SESS_VARS_SOURCED" ]; then return; fi
export __HM_SESS_VARS_SOURCED=1
export NIX_PATH="testpath=$HOME/testpath:$NIX_PATH"
export PATH="$PATH:$HOME/bin"
export XDG_CACHE_HOME="/home/hm-user/.cache"
export XDG_CONFIG_HOME="/home/hm-user/.config"
export XDG_DATA_HOME="/home/hm-user/.local/share"
'';
expected = pkgs.writeText "expected"
(if isDarwin then darwinExpected else linuxExpected);
in {
config = {
home.sessionVariables = lib.mkMerge [
{
PATH = "$PATH";
NIX_PATH = "$NIX_PATH";
}
{
PATH = lib.mkAfter "$HOME/bin";
NIX_PATH = lib.mkBefore "testpath=$HOME/testpath";
}
];
nmt.script = ''
assertFileExists home-path/etc/profile.d/hm-session-vars.sh
assertFileContent home-path/etc/profile.d/hm-session-vars.sh \
${expected}
'';
};
}

View file

@ -10,6 +10,8 @@ let
export __HM_SESS_VARS_SOURCED=1 export __HM_SESS_VARS_SOURCED=1
export LOCALE_ARCHIVE_2_27="${pkgs.glibcLocales}/lib/locale/locale-archive" export LOCALE_ARCHIVE_2_27="${pkgs.glibcLocales}/lib/locale/locale-archive"
export NIX_PATH="$NIX_PATH"
export PATH="$PATH"
export V1="v1" export V1="v1"
export V2="v2-v1" export V2="v2-v1"
export XDG_CACHE_HOME="/home/hm-user/.cache" export XDG_CACHE_HOME="/home/hm-user/.cache"
@ -22,6 +24,8 @@ let
if [ -n "$__HM_SESS_VARS_SOURCED" ]; then return; fi if [ -n "$__HM_SESS_VARS_SOURCED" ]; then return; fi
export __HM_SESS_VARS_SOURCED=1 export __HM_SESS_VARS_SOURCED=1
export NIX_PATH="$NIX_PATH"
export PATH="$PATH"
export V1="v1" export V1="v1"
export V2="v2-v1" export V2="v2-v1"
export XDG_CACHE_HOME="/home/hm-user/.cache" export XDG_CACHE_HOME="/home/hm-user/.cache"