tests: improve test purity
Before the XDG variables would be set from the user's environment, if available. This would break some tests. With this change the tests should be fully deterministic. Fixes #1190
This commit is contained in:
parent
cfaf213980
commit
95b95b1407
|
@ -14,7 +14,15 @@ let
|
||||||
modules = import ../modules/modules.nix {
|
modules = import ../modules/modules.nix {
|
||||||
inherit lib pkgs;
|
inherit lib pkgs;
|
||||||
check = false;
|
check = false;
|
||||||
};
|
} ++ [
|
||||||
|
# Fix impurities. Without these some of the user's environment
|
||||||
|
# will leak into the tests through `builtins.getEnv`.
|
||||||
|
{
|
||||||
|
xdg.enable = true;
|
||||||
|
home.username = "hm-user";
|
||||||
|
home.homeDirectory = "/home/hm-user";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
in
|
in
|
||||||
|
|
||||||
|
|
|
@ -4,3 +4,6 @@ export __HM_SESS_VARS_SOURCED=1
|
||||||
|
|
||||||
export V1="v1"
|
export V1="v1"
|
||||||
export V2="v2-v1"
|
export V2="v2-v1"
|
||||||
|
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"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
. "/test-home/.nix-profile/etc/profile.d/hm-session-vars.sh"
|
. "/home/hm-user/.nix-profile/etc/profile.d/hm-session-vars.sh"
|
||||||
|
|
||||||
if [ -e "$HOME/.profile" ]; then
|
if [ -e "$HOME/.profile" ]; then
|
||||||
. "$HOME/.profile"
|
. "$HOME/.profile"
|
||||||
|
|
|
@ -4,8 +4,6 @@ with lib;
|
||||||
|
|
||||||
{
|
{
|
||||||
config = {
|
config = {
|
||||||
home.homeDirectory = "/test-home";
|
|
||||||
|
|
||||||
xsession = {
|
xsession = {
|
||||||
enable = true;
|
enable = true;
|
||||||
windowManager.command = "window manager command";
|
windowManager.command = "window manager command";
|
||||||
|
|
|
@ -6,8 +6,6 @@ with lib;
|
||||||
config = {
|
config = {
|
||||||
home.stateVersion = "19.09";
|
home.stateVersion = "19.09";
|
||||||
|
|
||||||
home.homeDirectory = "/test-home";
|
|
||||||
|
|
||||||
home.keyboard = { options = [ "ctrl:nocaps" "altwin:no_win" ]; };
|
home.keyboard = { options = [ "ctrl:nocaps" "altwin:no_win" ]; };
|
||||||
|
|
||||||
xsession = {
|
xsession = {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# -*- mode: sh -*-
|
# -*- mode: sh -*-
|
||||||
|
|
||||||
. "/home/testuser/.nix-profile/etc/profile.d/hm-session-vars.sh"
|
. "/home/hm-user/.nix-profile/etc/profile.d/hm-session-vars.sh"
|
||||||
|
|
||||||
export V1="v1"
|
export V1="v1"
|
||||||
export V2="v2-v1"
|
export V2="v2-v1"
|
||||||
|
|
|
@ -13,8 +13,6 @@ with lib;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
home.homeDirectory = "/home/testuser";
|
|
||||||
|
|
||||||
nmt.script = ''
|
nmt.script = ''
|
||||||
assertFileExists home-files/.profile
|
assertFileExists home-files/.profile
|
||||||
assertFileContent \
|
assertFileContent \
|
||||||
|
|
|
@ -6,9 +6,6 @@ with lib;
|
||||||
imports = [ ../../accounts/email-test-accounts.nix ];
|
imports = [ ../../accounts/email-test-accounts.nix ];
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
home.username = "hm-user";
|
|
||||||
home.homeDirectory = "/home/hm-user";
|
|
||||||
|
|
||||||
accounts.email.accounts = {
|
accounts.email.accounts = {
|
||||||
"hm@example.com" = {
|
"hm@example.com" = {
|
||||||
getmail = {
|
getmail = {
|
||||||
|
|
|
@ -6,9 +6,6 @@ with lib;
|
||||||
imports = [ ../../accounts/email-test-accounts.nix ];
|
imports = [ ../../accounts/email-test-accounts.nix ];
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
home.username = "hm-user";
|
|
||||||
home.homeDirectory = "/home/hm-user";
|
|
||||||
|
|
||||||
programs.lieer.enable = true;
|
programs.lieer.enable = true;
|
||||||
|
|
||||||
accounts.email.accounts = { "hm@example.com".lieer.enable = true; };
|
accounts.email.accounts = { "hm@example.com".lieer.enable = true; };
|
||||||
|
|
|
@ -6,9 +6,6 @@ with lib;
|
||||||
imports = [ ../../accounts/email-test-accounts.nix ];
|
imports = [ ../../accounts/email-test-accounts.nix ];
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
home.username = "hm-user";
|
|
||||||
home.homeDirectory = "/home/hm-user";
|
|
||||||
|
|
||||||
programs.mbsync = {
|
programs.mbsync = {
|
||||||
enable = true;
|
enable = true;
|
||||||
groups.inboxes = {
|
groups.inboxes = {
|
||||||
|
|
|
@ -6,11 +6,6 @@ with lib;
|
||||||
imports = [ ../../accounts/email-test-accounts.nix ];
|
imports = [ ../../accounts/email-test-accounts.nix ];
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
home.username = "hm-user";
|
|
||||||
home.homeDirectory = "/home/hm-user";
|
|
||||||
xdg.configHome = mkForce "/home/hm-user/.config";
|
|
||||||
xdg.cacheHome = mkForce "/home/hm-user/.cache";
|
|
||||||
|
|
||||||
accounts.email.accounts = {
|
accounts.email.accounts = {
|
||||||
"hm@example.com" = {
|
"hm@example.com" = {
|
||||||
primary = true;
|
primary = true;
|
||||||
|
|
|
@ -6,11 +6,6 @@ with lib;
|
||||||
imports = [ ../../accounts/email-test-accounts.nix ];
|
imports = [ ../../accounts/email-test-accounts.nix ];
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
home.username = "hm-user";
|
|
||||||
home.homeDirectory = "/home/hm-user";
|
|
||||||
xdg.configHome = mkForce "/home/hm-user/.config";
|
|
||||||
xdg.cacheHome = mkForce "/home/hm-user/.cache";
|
|
||||||
|
|
||||||
accounts.email.accounts = {
|
accounts.email.accounts = {
|
||||||
"hm@example.com" = {
|
"hm@example.com" = {
|
||||||
primary = true;
|
primary = true;
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
# Only source this once.
|
|
||||||
if [ -n "$__HM_SESS_VARS_SOURCED" ]; then return; fi
|
|
||||||
export __HM_SESS_VARS_SOURCED=1
|
|
||||||
|
|
||||||
export TMUX_TMPDIR="${XDG_RUNTIME_DIR:-"/run/user/\$(id -u)"}"
|
|
|
@ -11,9 +11,8 @@ with lib;
|
||||||
|
|
||||||
nmt.script = ''
|
nmt.script = ''
|
||||||
assertFileExists home-path/etc/profile.d/hm-session-vars.sh
|
assertFileExists home-path/etc/profile.d/hm-session-vars.sh
|
||||||
assertFileContent home-path/etc/profile.d/hm-session-vars.sh ${
|
assertFileContains home-path/etc/profile.d/hm-session-vars.sh \
|
||||||
./hm-session-vars.sh
|
'export TMUX_TMPDIR="''${XDG_RUNTIME_DIR:-"/run/user/\$(id -u)"}"'
|
||||||
}
|
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,6 @@ with lib;
|
||||||
imports = [ ../../accounts/email-test-accounts.nix ];
|
imports = [ ../../accounts/email-test-accounts.nix ];
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
home.username = "hm-user";
|
|
||||||
home.homeDirectory = "/home/hm-user";
|
|
||||||
|
|
||||||
services.lieer.enable = true;
|
services.lieer.enable = true;
|
||||||
|
|
||||||
accounts.email.accounts = {
|
accounts.email.accounts = {
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
# Only source this once.
|
|
||||||
if [ -n "$__HM_SESS_VARS_SOURCED" ]; then return; fi
|
|
||||||
export __HM_SESS_VARS_SOURCED=1
|
|
||||||
|
|
||||||
export XDG_DATA_DIRS="/nix/var/nix/profiles/default/share:/homeless-shelter/.nix-profile/share${XDG_DATA_DIRS:+:}$XDG_DATA_DIRS"
|
|
||||||
. "@nix@/etc/profile.d/nix.sh"
|
|
|
@ -4,20 +4,16 @@ with lib;
|
||||||
|
|
||||||
{
|
{
|
||||||
config = {
|
config = {
|
||||||
home.homeDirectory = "/homeless-shelter";
|
|
||||||
|
|
||||||
targets.genericLinux.enable = true;
|
targets.genericLinux.enable = true;
|
||||||
|
|
||||||
nmt.script = ''
|
nmt.script = ''
|
||||||
assertFileExists home-path/etc/profile.d/hm-session-vars.sh
|
assertFileExists home-path/etc/profile.d/hm-session-vars.sh
|
||||||
assertFileContent \
|
assertFileContains \
|
||||||
home-path/etc/profile.d/hm-session-vars.sh \
|
home-path/etc/profile.d/hm-session-vars.sh \
|
||||||
${
|
'export XDG_DATA_DIRS="/nix/var/nix/profiles/default/share:/home/hm-user/.nix-profile/share''${XDG_DATA_DIRS:+:}$XDG_DATA_DIRS"'
|
||||||
pkgs.substituteAll {
|
assertFileContains \
|
||||||
src = ./generic-linux-session-vars-expected.txt;
|
home-path/etc/profile.d/hm-session-vars.sh \
|
||||||
nix = pkgs.nix;
|
'. "${pkgs.nix}/etc/profile.d/nix.sh"'
|
||||||
}
|
|
||||||
}
|
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue