From c2f151258a90e33a1512baf196ebfdc1f4eafa98 Mon Sep 17 00:00:00 2001 From: Tobias Happ Date: Sat, 1 Jan 2022 18:06:55 +0100 Subject: [PATCH] bash: remove unnecessary shebang and executable bit for dotfiles (#2599) --- modules/programs/bash.nix | 15 +++++++++++---- tests/modules/programs/bash/logout.nix | 2 +- tests/modules/programs/bash/session-variables.nix | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/modules/programs/bash.nix b/modules/programs/bash.nix index c0165fe76..86d223492 100644 --- a/modules/programs/bash.nix +++ b/modules/programs/bash.nix @@ -6,6 +6,13 @@ let cfg = config.programs.bash; + writeBashScript = name: text: pkgs.writeTextFile { + inherit name text; + checkPhase = '' + ${pkgs.stdenv.shell} -n $out + ''; + }; + in { @@ -178,7 +185,7 @@ in } )); in mkIf cfg.enable { - home.file.".bash_profile".source = pkgs.writeShellScript "bash_profile" '' + home.file.".bash_profile".source = writeBashScript "bash_profile" '' # include .profile if it exists [[ -f ~/.profile ]] && . ~/.profile @@ -186,7 +193,7 @@ in [[ -f ~/.bashrc ]] && . ~/.bashrc ''; - home.file.".profile".source = pkgs.writeShellScript "profile" '' + home.file.".profile".source = writeBashScript "profile" '' . "${config.home.profileDirectory}/etc/profile.d/hm-session-vars.sh" ${sessionVarsStr} @@ -194,7 +201,7 @@ in ${cfg.profileExtra} ''; - home.file.".bashrc".source = pkgs.writeShellScript "bashrc" '' + home.file.".bashrc".source = writeBashScript "bashrc" '' ${cfg.bashrcExtra} # Commands that should be applied only for interactive shells. @@ -210,7 +217,7 @@ in ''; home.file.".bash_logout" = mkIf (cfg.logoutExtra != "") { - source = pkgs.writeShellScript "bash_logout" cfg.logoutExtra; + source = writeBashScript "bash_logout" cfg.logoutExtra; }; } ); diff --git a/tests/modules/programs/bash/logout.nix b/tests/modules/programs/bash/logout.nix index 7b7f738ab..a34292858 100644 --- a/tests/modules/programs/bash/logout.nix +++ b/tests/modules/programs/bash/logout.nix @@ -17,7 +17,7 @@ with lib; assertFileContent \ home-files/.bash_logout \ ${ - pkgs.writeShellScript "logout-expected" '' + builtins.toFile "logout-expected" '' clear-console '' } diff --git a/tests/modules/programs/bash/session-variables.nix b/tests/modules/programs/bash/session-variables.nix index 47ed2130d..09c69814d 100644 --- a/tests/modules/programs/bash/session-variables.nix +++ b/tests/modules/programs/bash/session-variables.nix @@ -18,7 +18,7 @@ with lib; assertFileContent \ home-files/.profile \ ${ - pkgs.writeShellScript "session-variables-expected" '' + builtins.toFile "session-variables-expected" '' . "/home/hm-user/.nix-profile/etc/profile.d/hm-session-vars.sh" export V1="v1"