2017-01-07 18:16:26 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.xsession;
|
|
|
|
|
2017-10-31 13:05:54 +00:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
meta.maintainers = [ maintainers.rycee ];
|
|
|
|
|
|
|
|
options = {
|
|
|
|
xsession = {
|
|
|
|
enable = mkEnableOption "X Session";
|
|
|
|
|
2018-09-15 20:49:53 +00:00
|
|
|
scriptPath = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = ".xsession";
|
|
|
|
example = ".xsession-hm";
|
|
|
|
description = ''
|
|
|
|
Path, relative <envar>HOME</envar>, where Home Manager
|
|
|
|
should write the X session script.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-10-31 13:05:54 +00:00
|
|
|
windowManager.command = mkOption {
|
2017-09-22 22:34:25 +00:00
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-07-24 10:48:53 +00:00
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-10-21 12:37:30 +00:00
|
|
|
profileExtra = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
description = "Extra shell commands to run before session start.";
|
|
|
|
};
|
|
|
|
|
2017-01-07 18:16:26 +00:00
|
|
|
initExtra = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
description = "Extra shell commands to run during initialization.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-10-31 13:05:54 +00:00
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.user.services.setxkbmap = {
|
|
|
|
Unit = {
|
|
|
|
Description = "Set up keyboard in X";
|
|
|
|
After = [ "graphical-session-pre.target" ];
|
|
|
|
PartOf = [ "graphical-session.target" ];
|
2017-01-07 18:16:26 +00:00
|
|
|
};
|
|
|
|
|
2017-10-31 13:05:54 +00:00
|
|
|
Install = {
|
|
|
|
WantedBy = [ "graphical-session.target" ];
|
2017-01-09 21:45:42 +00:00
|
|
|
};
|
|
|
|
|
2017-10-31 13:05:54 +00:00
|
|
|
Service = {
|
|
|
|
Type = "oneshot";
|
|
|
|
ExecStart =
|
|
|
|
let
|
|
|
|
args = concatStringsSep " " (
|
|
|
|
[
|
|
|
|
"-layout '${config.home.keyboard.layout}'"
|
|
|
|
"-variant '${config.home.keyboard.variant}'"
|
|
|
|
] ++
|
|
|
|
(map (v: "-option '${v}'") config.home.keyboard.options)
|
|
|
|
);
|
|
|
|
in
|
|
|
|
"${pkgs.xorg.setxkbmap}/bin/setxkbmap ${args}";
|
|
|
|
};
|
|
|
|
};
|
2017-01-15 09:46:20 +00:00
|
|
|
|
2017-10-31 13:05:54 +00:00
|
|
|
# A basic graphical session target for Home Manager.
|
|
|
|
systemd.user.targets.hm-graphical-session = {
|
|
|
|
Unit = {
|
|
|
|
Description = "Home Manager X session";
|
|
|
|
Requires = [ "graphical-session-pre.target" ];
|
|
|
|
BindsTo = [ "graphical-session.target" ];
|
|
|
|
};
|
|
|
|
};
|
2017-10-21 12:37:30 +00:00
|
|
|
|
2017-10-31 13:05:54 +00:00
|
|
|
home.file.".xprofile".text = ''
|
2018-07-29 16:15:50 +00:00
|
|
|
. "${config.home.profileDirectory}/etc/profile.d/hm-session-vars.sh"
|
2018-01-04 12:28:55 +00:00
|
|
|
|
2017-10-31 13:05:54 +00:00
|
|
|
if [[ -e "$HOME/.profile" ]]; then
|
|
|
|
. "$HOME/.profile"
|
|
|
|
fi
|
2017-10-21 12:37:30 +00:00
|
|
|
|
2017-10-31 13:05:54 +00: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
|
|
|
|
|
|
|
|
systemctl --user import-environment DBUS_SESSION_BUS_ADDRESS
|
|
|
|
systemctl --user import-environment DISPLAY
|
|
|
|
systemctl --user import-environment SSH_AUTH_SOCK
|
|
|
|
systemctl --user import-environment XAUTHORITY
|
|
|
|
systemctl --user import-environment XDG_DATA_DIRS
|
|
|
|
systemctl --user import-environment XDG_RUNTIME_DIR
|
|
|
|
systemctl --user import-environment XDG_SESSION_ID
|
|
|
|
|
|
|
|
${cfg.profileExtra}
|
|
|
|
|
|
|
|
export HM_XPROFILE_SOURCED=1
|
|
|
|
'';
|
|
|
|
|
2018-09-15 20:49:53 +00:00
|
|
|
home.file.${cfg.scriptPath} = {
|
2017-11-06 09:28:44 +00:00
|
|
|
executable = true;
|
2017-10-31 13:05:54 +00:00
|
|
|
text = ''
|
|
|
|
if [[ ! -v HM_XPROFILE_SOURCED ]]; then
|
|
|
|
. ~/.xprofile
|
|
|
|
fi
|
|
|
|
unset HM_XPROFILE_SOURCED
|
2017-10-21 12:37:30 +00:00
|
|
|
|
2017-10-31 13:05:54 +00:00
|
|
|
systemctl --user start hm-graphical-session.target
|
2017-01-07 18:16:26 +00:00
|
|
|
|
2017-10-31 13:05:54 +00:00
|
|
|
${cfg.initExtra}
|
2017-01-07 18:16:26 +00:00
|
|
|
|
2017-10-31 13:05:54 +00:00
|
|
|
${cfg.windowManager.command}
|
2017-01-07 18:16:26 +00:00
|
|
|
|
2017-10-31 13:05:54 +00:00
|
|
|
systemctl --user stop graphical-session.target
|
|
|
|
systemctl --user stop graphical-session-pre.target
|
2017-01-15 09:46:20 +00:00
|
|
|
|
2017-10-31 13:05:54 +00:00
|
|
|
# Wait until the units actually stop.
|
|
|
|
while [[ -n "$(systemctl --user --no-legend --state=deactivating list-units)" ]]; do
|
|
|
|
sleep 0.5
|
|
|
|
done
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2017-01-07 18:16:26 +00:00
|
|
|
}
|