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

envvars: add module

This module generalises the session variables configuration to
make adding new shells easier
This commit is contained in:
adisbladis 2017-08-02 17:46:31 +08:00
parent be432c8654
commit 7679971176
No known key found for this signature in database
GPG key ID: ED58F95069B004F5
6 changed files with 35 additions and 10 deletions

View file

@ -8,6 +8,7 @@ with lib;
let
modules = [
./shell-session-vars.nix
./home-environment.nix
./manual.nix
./misc/gtk.nix

View file

@ -164,13 +164,13 @@ in
};
home.sessionVariableSetter = mkOption {
default = "bash";
type = types.enum [ "pam" "bash" ];
default = "shell";
type = types.enum [ "pam" "shell" "bash" ];
example = "pam";
description = ''
Identifies the module that should set the session variables.
</para><para>
If "bash" is set then <varname>config.bash.enable</varname>
If "shell" is set then <varname>config.bash.enable</varname>
must also be enabled.
</para><para>
If "pam" is set then PAM must be used to set the system

View file

@ -110,9 +110,6 @@ in
histControlStr = concatStringsSep ":" cfg.historyControl;
histIgnoreStr = concatStringsSep ":" cfg.historyIgnore;
envVarsStr = concatStringsSep "\n" (
mapAttrsToList export config.home.sessionVariables
);
in mkIf cfg.enable {
home.file.".bash_profile".text = ''
# -*- mode: sh -*-
@ -127,8 +124,9 @@ in
home.file.".profile".text = ''
# -*- mode: sh -*-
${optionalString (config.home.sessionVariableSetter == "bash")
envVarsStr}
${optionalString (config.home.sessionVariableSetter == "shell"
|| config.home.sessionVariableSetter == "bash")
"~/.local/share/home-manager/env.sh"}
${cfg.profileExtra}
'';

View file

@ -60,7 +60,7 @@ in
}];
home.sessionVariables.INFOPATH =
"${cfg.homeInfoDirLocation}\${INFOPATH:+:}\${INFOPATH}";
"${cfg.homeInfoDirLocation}\$INFOPATH:+:\$INFOPATH";
home.activation.createHomeInfoDir = dagEntryAfter ["installPackages"] ''
$DRY_RUN_CMD mkdir -p "${cfg.homeInfoDirLocation}"

View file

@ -41,7 +41,7 @@ in
home.sessionVariables =
optionalAttrs cfg.enableSshSupport {
SSH_AUTH_SOCK = "\${XDG_RUNTIME_DIR}/gnupg/S.gpg-agent.ssh";
SSH_AUTH_SOCK = "\$XDG_RUNTIME_DIR/gnupg/S.gpg-agent.ssh";
};
programs.bash.initExtra = ''

View file

@ -0,0 +1,26 @@
{ config, lib, pkgs, ... }:
with lib;
{
config = (
let
export = n: v: "export ${n}=\"${toString v}\"";
setenv = n: v: "setenv ${n} \"${toString v}\"";
shEnvVarsStr = concatStringsSep "\n" (
mapAttrsToList export config.home.sessionVariables
);
cshEnvVarsStr = concatStringsSep "\n" (
mapAttrsToList setenv config.home.sessionVariables
);
in mkIf (config.home.sessionVariableSetter == "shell"
|| config.home.sessionVariableSetter == "bash") {
home.file.".local/share/home-manager/env.sh".text = ''
${shEnvVarsStr}
'';
home.file.".local/share/home-manager/env.csh".text = ''
${cshEnvVarsStr}
'';
}
);
}