aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Helgesson <robert@rycee.net>2017-01-16 23:54:45 +0100
committerRobert Helgesson <robert@rycee.net>2017-01-16 23:54:45 +0100
commit5fbbbd1ea4978c22d527af00c9b8af66b0bfcba8 (patch)
tree36b8dc888e2138bfb21ec1a5d09e14dc49915fa5
parentf35b9a9970ef66eb8ede5a5595b01777e55fde4a (diff)
pam: add module
Also make it possible to set session variables using PAM rather than Bash.
-rw-r--r--modules/default.nix1
-rw-r--r--modules/home-environment.nix19
-rw-r--r--modules/misc/pam.nix20
-rw-r--r--modules/programs/bash.nix3
-rw-r--r--modules/xsession.nix8
5 files changed, 47 insertions, 4 deletions
diff --git a/modules/default.nix b/modules/default.nix
index 7f5f48b58b2..b9a4be4d9ca 100644
--- a/modules/default.nix
+++ b/modules/default.nix
@@ -8,6 +8,7 @@ let
modules = [
./home-environment.nix
./manual.nix
+ ./misc/pam.nix
./programs/bash.nix
./programs/beets.nix
./programs/eclipse.nix
diff --git a/modules/home-environment.nix b/modules/home-environment.nix
index c4dda2ef8c8..3623bc20380 100644
--- a/modules/home-environment.nix
+++ b/modules/home-environment.nix
@@ -150,7 +150,24 @@ in
default = {};
type = types.attrs;
example = { EDITOR = "emacs"; GS_OPTIONS = "-sPAPERSIZE=a4"; };
- description = "Environment variables to always set at login.";
+ description = ''
+ Environment variables to always set at login.
+ '';
+ };
+
+ home.sessionVariableSetter = mkOption {
+ default = "pam";
+ type = types.enum [ "pam" "bash" ];
+ example = "bash";
+ description = ''
+ Identifies the module that should set the session variables.
+ </para><para>
+ If "bash" 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
+ environment.
+ '';
};
home.packages = mkOption {
diff --git a/modules/misc/pam.nix b/modules/misc/pam.nix
new file mode 100644
index 00000000000..89040aa841c
--- /dev/null
+++ b/modules/misc/pam.nix
@@ -0,0 +1,20 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+
+ homeCfg = config.home;
+
+in
+
+{
+ options = {};
+
+ config = mkIf (homeCfg.sessionVariableSetter == "pam") {
+ home.file.".pam_environment".text =
+ concatStringsSep "\n" (
+ mapAttrsToList (n: v: "${n} OVERRIDE=${v}") homeCfg.sessionVariables
+ ) + "\n";
+ };
+}
diff --git a/modules/programs/bash.nix b/modules/programs/bash.nix
index a2000274c81..a8004580d8a 100644
--- a/modules/programs/bash.nix
+++ b/modules/programs/bash.nix
@@ -127,7 +127,8 @@ in
home.file.".profile".text = ''
# -*- mode: sh -*-
- ${envVarsStr}
+ ${optionalString (config.home.sessionVariableSetter == "bash")
+ envVarsStr}
${cfg.profileExtra}
'';
diff --git a/modules/xsession.nix b/modules/xsession.nix
index 3b36a5b537f..f498d51786a 100644
--- a/modules/xsession.nix
+++ b/modules/xsession.nix
@@ -72,8 +72,12 @@ in
home.file.".xsession" = {
mode = "555";
text = ''
- # Rely on Bash to set session variables.
- . "$HOME/.profile"
+ ${
+ # If we want bash to set the session variables then we need
+ # to pull in .profile since that's where they are.
+ optionalString (config.home.sessionVariableSetter == "bash")
+ ". \"$HOME/.profile\""
+ }
systemctl --user import-environment DBUS_SESSION_BUS_ADDRESS
systemctl --user import-environment DISPLAY