diff --git a/tests/default.nix b/tests/default.nix index b29b27ac..9eb5afcd 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -14,7 +14,15 @@ let modules = import ../modules/modules.nix { inherit lib pkgs; 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 diff --git a/tests/modules/home-environment/session-variables-expected.txt b/tests/modules/home-environment/session-variables-expected.txt index 5c3868c3..4e18e2b3 100644 --- a/tests/modules/home-environment/session-variables-expected.txt +++ b/tests/modules/home-environment/session-variables-expected.txt @@ -4,3 +4,6 @@ export __HM_SESS_VARS_SOURCED=1 export V1="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" diff --git a/tests/modules/misc/xsession/basic-xprofile-expected.txt b/tests/modules/misc/xsession/basic-xprofile-expected.txt index 05733a97..282f8f5c 100644 --- a/tests/modules/misc/xsession/basic-xprofile-expected.txt +++ b/tests/modules/misc/xsession/basic-xprofile-expected.txt @@ -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 . "$HOME/.profile" diff --git a/tests/modules/misc/xsession/basic.nix b/tests/modules/misc/xsession/basic.nix index 39df6362..d6756291 100644 --- a/tests/modules/misc/xsession/basic.nix +++ b/tests/modules/misc/xsession/basic.nix @@ -4,8 +4,6 @@ with lib; { config = { - home.homeDirectory = "/test-home"; - xsession = { enable = true; windowManager.command = "window manager command"; diff --git a/tests/modules/misc/xsession/keyboard-without-layout.nix b/tests/modules/misc/xsession/keyboard-without-layout.nix index 015efe61..90038cfd 100644 --- a/tests/modules/misc/xsession/keyboard-without-layout.nix +++ b/tests/modules/misc/xsession/keyboard-without-layout.nix @@ -6,8 +6,6 @@ with lib; config = { home.stateVersion = "19.09"; - home.homeDirectory = "/test-home"; - home.keyboard = { options = [ "ctrl:nocaps" "altwin:no_win" ]; }; xsession = { diff --git a/tests/modules/programs/bash/session-variables-expected.txt b/tests/modules/programs/bash/session-variables-expected.txt index e13d63d4..0d93217a 100644 --- a/tests/modules/programs/bash/session-variables-expected.txt +++ b/tests/modules/programs/bash/session-variables-expected.txt @@ -1,6 +1,6 @@ # -*- 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 V2="v2-v1" diff --git a/tests/modules/programs/bash/session-variables.nix b/tests/modules/programs/bash/session-variables.nix index ea789a1d..1ef65a34 100644 --- a/tests/modules/programs/bash/session-variables.nix +++ b/tests/modules/programs/bash/session-variables.nix @@ -13,8 +13,6 @@ with lib; }; }; - home.homeDirectory = "/home/testuser"; - nmt.script = '' assertFileExists home-files/.profile assertFileContent \ diff --git a/tests/modules/programs/getmail/getmail.nix b/tests/modules/programs/getmail/getmail.nix index fe10b98f..b0d979c4 100644 --- a/tests/modules/programs/getmail/getmail.nix +++ b/tests/modules/programs/getmail/getmail.nix @@ -6,9 +6,6 @@ with lib; imports = [ ../../accounts/email-test-accounts.nix ]; config = { - home.username = "hm-user"; - home.homeDirectory = "/home/hm-user"; - accounts.email.accounts = { "hm@example.com" = { getmail = { diff --git a/tests/modules/programs/lieer/lieer.nix b/tests/modules/programs/lieer/lieer.nix index 1671f4f5..2ce4fb4e 100644 --- a/tests/modules/programs/lieer/lieer.nix +++ b/tests/modules/programs/lieer/lieer.nix @@ -6,9 +6,6 @@ with lib; imports = [ ../../accounts/email-test-accounts.nix ]; config = { - home.username = "hm-user"; - home.homeDirectory = "/home/hm-user"; - programs.lieer.enable = true; accounts.email.accounts = { "hm@example.com".lieer.enable = true; }; diff --git a/tests/modules/programs/mbsync/mbsync.nix b/tests/modules/programs/mbsync/mbsync.nix index 03a54c17..fa8e28cb 100644 --- a/tests/modules/programs/mbsync/mbsync.nix +++ b/tests/modules/programs/mbsync/mbsync.nix @@ -6,9 +6,6 @@ with lib; imports = [ ../../accounts/email-test-accounts.nix ]; config = { - home.username = "hm-user"; - home.homeDirectory = "/home/hm-user"; - programs.mbsync = { enable = true; groups.inboxes = { diff --git a/tests/modules/programs/neomutt/neomutt-with-msmtp.nix b/tests/modules/programs/neomutt/neomutt-with-msmtp.nix index 5f94d21a..22f65599 100644 --- a/tests/modules/programs/neomutt/neomutt-with-msmtp.nix +++ b/tests/modules/programs/neomutt/neomutt-with-msmtp.nix @@ -6,11 +6,6 @@ with lib; imports = [ ../../accounts/email-test-accounts.nix ]; 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 = { "hm@example.com" = { primary = true; diff --git a/tests/modules/programs/neomutt/neomutt.nix b/tests/modules/programs/neomutt/neomutt.nix index 91cb9dca..c0caa44a 100644 --- a/tests/modules/programs/neomutt/neomutt.nix +++ b/tests/modules/programs/neomutt/neomutt.nix @@ -6,11 +6,6 @@ with lib; imports = [ ../../accounts/email-test-accounts.nix ]; 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 = { "hm@example.com" = { primary = true; diff --git a/tests/modules/programs/tmux/hm-session-vars.sh b/tests/modules/programs/tmux/hm-session-vars.sh deleted file mode 100644 index 40d9c24b..00000000 --- a/tests/modules/programs/tmux/hm-session-vars.sh +++ /dev/null @@ -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)"}" diff --git a/tests/modules/programs/tmux/secure-socket-enabled.nix b/tests/modules/programs/tmux/secure-socket-enabled.nix index 7e8c535c..ca2de663 100644 --- a/tests/modules/programs/tmux/secure-socket-enabled.nix +++ b/tests/modules/programs/tmux/secure-socket-enabled.nix @@ -11,9 +11,8 @@ with lib; nmt.script = '' assertFileExists home-path/etc/profile.d/hm-session-vars.sh - assertFileContent home-path/etc/profile.d/hm-session-vars.sh ${ - ./hm-session-vars.sh - } + assertFileContains home-path/etc/profile.d/hm-session-vars.sh \ + 'export TMUX_TMPDIR="''${XDG_RUNTIME_DIR:-"/run/user/\$(id -u)"}"' ''; }; } diff --git a/tests/modules/services/lieer/lieer-service.nix b/tests/modules/services/lieer/lieer-service.nix index faef5053..03dcdc74 100644 --- a/tests/modules/services/lieer/lieer-service.nix +++ b/tests/modules/services/lieer/lieer-service.nix @@ -6,9 +6,6 @@ with lib; imports = [ ../../accounts/email-test-accounts.nix ]; config = { - home.username = "hm-user"; - home.homeDirectory = "/home/hm-user"; - services.lieer.enable = true; accounts.email.accounts = { diff --git a/tests/modules/targets/generic-linux-session-vars-expected.txt b/tests/modules/targets/generic-linux-session-vars-expected.txt deleted file mode 100644 index ad9e0ada..00000000 --- a/tests/modules/targets/generic-linux-session-vars-expected.txt +++ /dev/null @@ -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" diff --git a/tests/modules/targets/generic-linux.nix b/tests/modules/targets/generic-linux.nix index 2e06b254..8596ac3d 100644 --- a/tests/modules/targets/generic-linux.nix +++ b/tests/modules/targets/generic-linux.nix @@ -4,20 +4,16 @@ with lib; { config = { - home.homeDirectory = "/homeless-shelter"; - targets.genericLinux.enable = true; nmt.script = '' assertFileExists home-path/etc/profile.d/hm-session-vars.sh - assertFileContent \ + assertFileContains \ home-path/etc/profile.d/hm-session-vars.sh \ - ${ - pkgs.substituteAll { - src = ./generic-linux-session-vars-expected.txt; - nix = pkgs.nix; - } - } + 'export XDG_DATA_DIRS="/nix/var/nix/profiles/default/share:/home/hm-user/.nix-profile/share''${XDG_DATA_DIRS:+:}$XDG_DATA_DIRS"' + assertFileContains \ + home-path/etc/profile.d/hm-session-vars.sh \ + '. "${pkgs.nix}/etc/profile.d/nix.sh"' ''; }; }