1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-01 00:39:45 +01:00

bash: generate files using writeShellScript

This ensures that the generated file is syntactically valid.

Issue #2015
This commit is contained in:
Robert Helgesson 2021-05-18 00:46:04 +02:00
parent 794d08a1d8
commit e9b7d12e06
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
5 changed files with 19 additions and 28 deletions

View file

@ -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;
};
}
);

View file

@ -1,4 +0,0 @@
# -*- mode: sh -*-
clear-console

View file

@ -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
''
}
'';
};
}

View file

@ -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"

View file

@ -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"
''
}
'';
};
}