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

188 lines
5.1 KiB
Nix
Raw Normal View History

2017-01-07 19:16:26 +01:00
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.xsession;
2020-02-02 00:39:17 +01:00
in {
meta.maintainers = [ maintainers.rycee ];
options = {
xsession = {
enable = mkEnableOption "X Session";
scriptPath = mkOption {
type = types.str;
default = ".xsession";
example = ".xsession-hm";
description = ''
Path, relative to <envar>HOME</envar>, where Home Manager
should write the X session script.
'';
};
profilePath = mkOption {
type = types.str;
default = ".xprofile";
example = ".xprofile-hm";
description = ''
Path, relative to <envar>HOME</envar>, where Home Manager
should write the X profile script.
'';
};
windowManager.command = mkOption {
type = types.str;
example = literalExample ''
let
xmonad = pkgs.xmonad-with-packages.override {
packages = self: [ self.xmonad-contrib self.taffybar ];
};
in
"''${xmonad}/bin/xmonad";
'';
description = ''
Window manager start command.
'';
};
preferStatusNotifierItems = mkOption {
type = types.bool;
default = false;
example = true;
description = ''
Whether tray applets should prefer using the Status Notifier
Items (SNI) protocol, commonly called App Indicators. Note,
not all tray applets or status bars support SNI.
'';
};
profileExtra = mkOption {
type = types.lines;
default = "";
description = "Extra shell commands to run before session start.";
};
2017-01-07 19:16:26 +01:00
initExtra = mkOption {
type = types.lines;
default = "";
description = "Extra shell commands to run during initialization.";
};
importedVariables = mkOption {
type = types.listOf (types.strMatching "[a-zA-Z_][a-zA-Z0-9_]*");
example = [ "GDK_PIXBUF_ICON_LOADER" ];
visible = false;
description = ''
Environment variables to import into the user systemd
session. The will be available for use by graphical
services.
'';
};
2017-01-07 19:16:26 +01:00
};
};
config = mkIf cfg.enable {
xsession.importedVariables = [
"DBUS_SESSION_BUS_ADDRESS"
"DISPLAY"
"SSH_AUTH_SOCK"
"XAUTHORITY"
"XDG_DATA_DIRS"
"XDG_RUNTIME_DIR"
"XDG_SESSION_ID"
];
systemd.user = {
services = mkIf (config.home.keyboard != null) {
2020-02-02 00:39:17 +01:00
setxkbmap = {
Unit = {
Description = "Set up keyboard in X";
After = [ "graphical-session-pre.target" ];
PartOf = [ "graphical-session.target" ];
};
2020-02-02 00:39:17 +01:00
Install = { WantedBy = [ "graphical-session.target" ]; };
Service = {
Type = "oneshot";
RemainAfterExit = true;
2020-02-02 00:39:17 +01:00
ExecStart = with config.home.keyboard;
let
2020-02-02 00:39:17 +01:00
args = optional (layout != null) "-layout '${layout}'"
++ optional (variant != null) "-variant '${variant}'"
++ optional (model != null) "-model '${model}'"
++ [ "-option ''" ] ++ map (v: "-option '${v}'") options;
2020-02-02 00:39:17 +01:00
in "${pkgs.xorg.setxkbmap}/bin/setxkbmap ${toString args}";
};
};
2017-01-07 19:16:26 +01:00
};
targets = {
# A basic graphical session target for Home Manager.
hm-graphical-session = {
Unit = {
Description = "Home Manager X session";
Requires = [ "graphical-session-pre.target" ];
BindsTo = [ "graphical-session.target" "tray.target" ];
};
};
tray = {
Unit = {
Description = "Home Manager System Tray";
Requires = [ "graphical-session-pre.target" ];
};
};
};
};
home.file.${cfg.profilePath}.text = ''
2020-02-02 00:39:17 +01:00
. "${config.home.profileDirectory}/etc/profile.d/hm-session-vars.sh"
2020-02-02 00:39:17 +01:00
if [ -e "$HOME/.profile" ]; then
. "$HOME/.profile"
fi
2020-02-02 00:39:17 +01:00
# If there are any running services from a previous session.
# Need to run this in xprofile because the NixOS xsession
# script starts up graphical-session.target.
systemctl --user stop graphical-session.target graphical-session-pre.target
2020-02-02 00:39:17 +01:00
${optionalString (cfg.importedVariables != [ ])
("systemctl --user import-environment "
+ toString (unique cfg.importedVariables))}
2020-02-02 00:39:17 +01:00
${cfg.profileExtra}
2020-02-02 00:39:17 +01:00
export HM_XPROFILE_SOURCED=1
'';
home.file.${cfg.scriptPath} = {
executable = true;
text = ''
if [ -z "$HM_XPROFILE_SOURCED" ]; then
. "${config.home.homeDirectory}/${cfg.profilePath}"
fi
unset HM_XPROFILE_SOURCED
systemctl --user start hm-graphical-session.target
2017-01-07 19:16:26 +01:00
${cfg.initExtra}
2017-01-07 19:16:26 +01:00
${cfg.windowManager.command}
2017-01-07 19:16:26 +01:00
systemctl --user stop graphical-session.target
systemctl --user stop graphical-session-pre.target
# Wait until the units actually stop.
while [ -n "$(systemctl --user --no-legend --state=deactivating list-units)" ]; do
sleep 0.5
done
'';
};
};
2017-01-07 19:16:26 +01:00
}