1
0
mirror of https://github.com/nix-community/home-manager synced 2024-06-01 04:23:34 +02:00
home-manager/tests/modules/home-environment/session-variables-explicit.nix
Robert Helgesson 61475c4779
experiment
2021-02-04 23:53:19 +01:00

58 lines
1.6 KiB
Nix

# 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:+:$NIX_PATH}"
export PATH="''${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:+:$NIX_PATH}"
export PATH="''${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}
'';
};
}