From e9b7d12e06dd353334de98e0cbd9cd8e19d7d510 Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Tue, 18 May 2021 00:46:04 +0200 Subject: [PATCH] bash: generate files using writeShellScript This ensures that the generated file is syntactically valid. Issue #2015 --- modules/programs/bash.nix | 18 ++++-------------- .../modules/programs/bash/logout-expected.txt | 4 ---- tests/modules/programs/bash/logout.nix | 6 +++++- .../bash/session-variables-expected.txt | 8 -------- .../programs/bash/session-variables.nix | 11 ++++++++++- 5 files changed, 19 insertions(+), 28 deletions(-) delete mode 100644 tests/modules/programs/bash/logout-expected.txt delete mode 100644 tests/modules/programs/bash/session-variables-expected.txt diff --git a/modules/programs/bash.nix b/modules/programs/bash.nix index bcaab88e9..5140e1aad 100644 --- a/modules/programs/bash.nix +++ b/modules/programs/bash.nix @@ -169,9 +169,7 @@ in } )); in mkIf cfg.enable { - home.file.".bash_profile".text = '' - # -*- mode: sh -*- - + home.file.".bash_profile".source = pkgs.writeShellScript "bash_profile" '' # include .profile if it exists [[ -f ~/.profile ]] && . ~/.profile @@ -179,9 +177,7 @@ in [[ -f ~/.bashrc ]] && . ~/.bashrc ''; - home.file.".profile".text = '' - # -*- mode: sh -*- - + home.file.".profile".source = pkgs.writeShellScript "profile" '' . "${config.home.profileDirectory}/etc/profile.d/hm-session-vars.sh" ${sessionVarsStr} @@ -189,9 +185,7 @@ in ${cfg.profileExtra} ''; - home.file.".bashrc".text = '' - # -*- mode: sh -*- - + home.file.".bashrc".source = pkgs.writeShellScript "bashrc" '' ${cfg.bashrcExtra} # Commands that should be applied only for interactive shells. @@ -207,11 +201,7 @@ in ''; home.file.".bash_logout" = mkIf (cfg.logoutExtra != "") { - text = '' - # -*- mode: sh -*- - - ${cfg.logoutExtra} - ''; + source = pkgs.writeShellScript "bash_logout" cfg.logoutExtra; }; } ); diff --git a/tests/modules/programs/bash/logout-expected.txt b/tests/modules/programs/bash/logout-expected.txt deleted file mode 100644 index 9462f58f7..000000000 --- a/tests/modules/programs/bash/logout-expected.txt +++ /dev/null @@ -1,4 +0,0 @@ -# -*- mode: sh -*- - -clear-console - diff --git a/tests/modules/programs/bash/logout.nix b/tests/modules/programs/bash/logout.nix index 8f96dc7e1..7b7f738ab 100644 --- a/tests/modules/programs/bash/logout.nix +++ b/tests/modules/programs/bash/logout.nix @@ -16,7 +16,11 @@ with lib; assertFileExists home-files/.bash_logout assertFileContent \ home-files/.bash_logout \ - ${./logout-expected.txt} + ${ + pkgs.writeShellScript "logout-expected" '' + clear-console + '' + } ''; }; } diff --git a/tests/modules/programs/bash/session-variables-expected.txt b/tests/modules/programs/bash/session-variables-expected.txt deleted file mode 100644 index 0d93217a9..000000000 --- a/tests/modules/programs/bash/session-variables-expected.txt +++ /dev/null @@ -1,8 +0,0 @@ -# -*- mode: 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 1ef65a344..47ed2130d 100644 --- a/tests/modules/programs/bash/session-variables.nix +++ b/tests/modules/programs/bash/session-variables.nix @@ -17,7 +17,16 @@ with lib; assertFileExists home-files/.profile assertFileContent \ home-files/.profile \ - ${./session-variables-expected.txt} + ${ + pkgs.writeShellScript "session-variables-expected" '' + . "/home/hm-user/.nix-profile/etc/profile.d/hm-session-vars.sh" + + export V1="v1" + export V2="v2-v1" + + + '' + } ''; }; }