1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-12-02 16:09:46 +01:00

nushell: Simplify file creation

This commit is contained in:
Joaquín Triñanes 2024-06-03 09:09:22 +02:00
parent 2cacdd6a27
commit c41e54ac3d
No known key found for this signature in database
GPG key ID: 6E1446DD451C6BAF

View file

@ -157,37 +157,36 @@ in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
home.packages = [ cfg.package ]; home.packages = [ cfg.package ];
home.file = mkMerge [ home.file."${configDir}/config.nu" = let
(let
writeConfig = cfg.configFile != null || cfg.extraConfig != "" writeConfig = cfg.configFile != null || cfg.extraConfig != ""
|| aliasesStr != ""; || aliasesStr != "";
aliasesStr = concatStringsSep "\n" aliasesStr = concatStringsSep "\n"
(mapAttrsToList (k: v: "alias ${k} = ${v}") cfg.shellAliases); (mapAttrsToList (k: v: "alias ${k} = ${v}") cfg.shellAliases);
in mkIf writeConfig { in mkIf writeConfig {
"${configDir}/config.nu".text = mkMerge [ text = mkMerge [
(mkIf (cfg.configFile != null) cfg.configFile.text) (mkIf (cfg.configFile != null) cfg.configFile.text)
cfg.extraConfig cfg.extraConfig
aliasesStr aliasesStr
]; ];
}) };
(let home.file."${configDir}/env.nu" = let
envVarsStr = concatStringsSep "\n" envVarsStr = concatStringsSep "\n"
(mapAttrsToList (k: v: "$env.${k} = ${v}") cfg.environmentVariables); (mapAttrsToList (k: v: "$env.${k} = ${v}") cfg.environmentVariables);
in mkIf (cfg.envFile != null || cfg.extraEnv != "" || envVarsStr != "") { in mkIf (cfg.envFile != null || cfg.extraEnv != "" || envVarsStr != "") {
"${configDir}/env.nu".text = mkMerge [ text = mkMerge [
(mkIf (cfg.envFile != null) cfg.envFile.text) (mkIf (cfg.envFile != null) cfg.envFile.text)
cfg.extraEnv cfg.extraEnv
envVarsStr envVarsStr
]; ];
}) };
(mkIf (cfg.loginFile != null || cfg.extraLogin != "") {
"${configDir}/login.nu".text = mkMerge [ home.file."${configDir}/login.nu" =
mkIf (cfg.loginFile != null || cfg.extraLogin != "") {
text = mkMerge [
(mkIf (cfg.loginFile != null) cfg.loginFile.text) (mkIf (cfg.loginFile != null) cfg.loginFile.text)
cfg.extraLogin cfg.extraLogin
]; ];
}) };
];
}; };
} }