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 {
|
2017-10-31 14:05:54 +01:00
|
|
|
meta.maintainers = [ maintainers.rycee ];
|
|
|
|
|
|
|
|
options = {
|
|
|
|
xsession = {
|
2023-07-02 01:45:18 +02:00
|
|
|
enable = mkEnableOption "X Session";
|
2017-10-31 14:05:54 +01:00
|
|
|
|
2018-09-15 22:49:53 +02:00
|
|
|
scriptPath = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = ".xsession";
|
|
|
|
example = ".xsession-hm";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2023-07-01 01:30:13 +02:00
|
|
|
Path, relative to {env}`HOME`, where Home Manager
|
2018-09-15 22:49:53 +02:00
|
|
|
should write the X session script.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-06-28 17:11:15 +02:00
|
|
|
profilePath = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = ".xprofile";
|
|
|
|
example = ".xprofile-hm";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2023-07-01 01:30:13 +02:00
|
|
|
Path, relative to {env}`HOME`, where Home Manager
|
2021-06-28 17:11:15 +02:00
|
|
|
should write the X profile script.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-10-31 14:05:54 +01:00
|
|
|
windowManager.command = mkOption {
|
2017-09-23 00:34:25 +02:00
|
|
|
type = types.str;
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2017-09-23 00:34:25 +02:00
|
|
|
let
|
|
|
|
xmonad = pkgs.xmonad-with-packages.override {
|
|
|
|
packages = self: [ self.xmonad-contrib self.taffybar ];
|
|
|
|
};
|
|
|
|
in
|
|
|
|
"''${xmonad}/bin/xmonad";
|
|
|
|
'';
|
2021-08-18 03:44:23 +02:00
|
|
|
default = ''test -n "$1" && eval "$@"'';
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2021-08-18 03:44:23 +02:00
|
|
|
Command to use to start the window manager.
|
2023-07-01 01:30:13 +02:00
|
|
|
|
2021-08-18 03:44:23 +02:00
|
|
|
The default value allows integration with NixOS' generated xserver configuration.
|
2023-07-01 01:30:13 +02:00
|
|
|
|
|
|
|
Extra actions and commands can be specified in {option}`xsession.initExtra`.
|
2017-09-23 00:34:25 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-07-24 12:48:53 +02:00
|
|
|
preferStatusNotifierItems = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
example = true;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2018-07-24 12:48:53 +02:00
|
|
|
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 14:37:30 +02:00
|
|
|
profileExtra = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Extra shell commands to run before session start.";
|
2017-10-21 14:37:30 +02:00
|
|
|
};
|
|
|
|
|
2017-01-07 19:16:26 +01:00
|
|
|
initExtra = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Extra shell commands to run during initialization.";
|
2017-01-07 19:16:26 +01:00
|
|
|
};
|
2019-06-23 14:06:29 +02:00
|
|
|
|
|
|
|
importedVariables = mkOption {
|
|
|
|
type = types.listOf (types.strMatching "[a-zA-Z_][a-zA-Z0-9_]*");
|
2023-05-07 23:59:56 +02:00
|
|
|
apply = unique;
|
2019-06-23 14:06:29 +02:00
|
|
|
example = [ "GDK_PIXBUF_ICON_LOADER" ];
|
|
|
|
visible = false;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2019-06-23 14:06:29 +02:00
|
|
|
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
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-10-31 14:05:54 +01:00
|
|
|
config = mkIf cfg.enable {
|
2021-07-07 23:24:27 +02:00
|
|
|
assertions =
|
|
|
|
[ (hm.assertions.assertPlatform "xsession" pkgs platforms.linux) ];
|
|
|
|
|
2019-06-23 14:06:29 +02:00
|
|
|
xsession.importedVariables = [
|
|
|
|
"DBUS_SESSION_BUS_ADDRESS"
|
|
|
|
"DISPLAY"
|
|
|
|
"SSH_AUTH_SOCK"
|
|
|
|
"XAUTHORITY"
|
|
|
|
"XDG_DATA_DIRS"
|
|
|
|
"XDG_RUNTIME_DIR"
|
|
|
|
"XDG_SESSION_ID"
|
|
|
|
];
|
|
|
|
|
2019-04-11 01:09:27 +02:00
|
|
|
systemd.user = {
|
|
|
|
services = mkIf (config.home.keyboard != null) {
|
2020-02-02 00:39:17 +01:00
|
|
|
setxkbmap = {
|
2019-04-11 01:09:27 +02:00
|
|
|
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" ]; };
|
2019-04-11 01:09:27 +02:00
|
|
|
|
|
|
|
Service = {
|
|
|
|
Type = "oneshot";
|
2019-08-14 20:40:40 +02:00
|
|
|
RemainAfterExit = true;
|
2020-02-02 00:39:17 +01:00
|
|
|
ExecStart = with config.home.keyboard;
|
2019-04-11 01:09:27 +02:00
|
|
|
let
|
2020-02-02 00:39:17 +01:00
|
|
|
args = optional (layout != null) "-layout '${layout}'"
|
2019-09-05 01:37:45 +02:00
|
|
|
++ optional (variant != null) "-variant '${variant}'"
|
2019-09-05 01:56:14 +02:00
|
|
|
++ optional (model != null) "-model '${model}'"
|
2021-07-12 03:15:18 +02:00
|
|
|
++ [ "-option ''" ] ++ map (v: "-option '${v}'") options;
|
2020-02-02 00:39:17 +01:00
|
|
|
in "${pkgs.xorg.setxkbmap}/bin/setxkbmap ${toString args}";
|
2019-04-11 01:09:27 +02:00
|
|
|
};
|
|
|
|
};
|
2021-12-23 21:38:44 +01:00
|
|
|
|
|
|
|
xplugd = {
|
|
|
|
Unit = {
|
|
|
|
Description = "Rerun setxkbmap.service when I/O is changed";
|
|
|
|
After = [ "graphical-session-pre.target" ];
|
|
|
|
PartOf = [ "graphical-session.target" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
Install = { WantedBy = [ "graphical-session.target" ]; };
|
|
|
|
|
|
|
|
Service = {
|
|
|
|
Type = "forking";
|
2023-10-17 19:34:00 +02:00
|
|
|
Restart = "on-failure";
|
2021-12-23 21:38:44 +01:00
|
|
|
ExecStart = let
|
|
|
|
script = pkgs.writeShellScript "xplugrc" ''
|
|
|
|
case "$1,$3" in
|
|
|
|
keyboard,connected)
|
|
|
|
systemctl --user restart setxkbmap.service
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
'';
|
|
|
|
in "${pkgs.xplugd}/bin/xplugd ${script}";
|
|
|
|
};
|
|
|
|
};
|
2017-01-07 19:16:26 +01:00
|
|
|
};
|
|
|
|
|
2021-05-22 04:15:12 +02: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" ];
|
|
|
|
};
|
2019-04-11 01:09:27 +02:00
|
|
|
};
|
2017-10-31 14:05:54 +01:00
|
|
|
};
|
|
|
|
};
|
2017-10-21 14:37:30 +02:00
|
|
|
|
2021-06-28 17:11:15 +02:00
|
|
|
home.file.${cfg.profilePath}.text = ''
|
2020-02-02 00:39:17 +01:00
|
|
|
. "${config.home.profileDirectory}/etc/profile.d/hm-session-vars.sh"
|
2018-01-04 13:28:55 +01:00
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
if [ -e "$HOME/.profile" ]; then
|
|
|
|
. "$HOME/.profile"
|
|
|
|
fi
|
2017-10-21 14:37:30 +02:00
|
|
|
|
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
|
2017-10-31 14:05:54 +01:00
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
${optionalString (cfg.importedVariables != [ ])
|
|
|
|
("systemctl --user import-environment "
|
2023-05-07 23:59:56 +02:00
|
|
|
+ escapeShellArgs cfg.importedVariables)}
|
2017-10-31 14:05:54 +01:00
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
${cfg.profileExtra}
|
2017-10-31 14:05:54 +01:00
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
export HM_XPROFILE_SOURCED=1
|
2017-10-31 14:05:54 +01:00
|
|
|
'';
|
|
|
|
|
2018-09-15 22:49:53 +02:00
|
|
|
home.file.${cfg.scriptPath} = {
|
2017-11-06 10:28:44 +01:00
|
|
|
executable = true;
|
2017-10-31 14:05:54 +01:00
|
|
|
text = ''
|
2019-09-11 20:11:16 +02:00
|
|
|
if [ -z "$HM_XPROFILE_SOURCED" ]; then
|
2021-06-28 17:11:15 +02:00
|
|
|
. "${config.home.homeDirectory}/${cfg.profilePath}"
|
2017-10-31 14:05:54 +01:00
|
|
|
fi
|
|
|
|
unset HM_XPROFILE_SOURCED
|
2017-10-21 14:37:30 +02:00
|
|
|
|
2017-10-31 14:05:54 +01:00
|
|
|
systemctl --user start hm-graphical-session.target
|
2017-01-07 19:16:26 +01:00
|
|
|
|
2017-10-31 14:05:54 +01:00
|
|
|
${cfg.initExtra}
|
2017-01-07 19:16:26 +01:00
|
|
|
|
2017-10-31 14:05:54 +01:00
|
|
|
${cfg.windowManager.command}
|
2017-01-07 19:16:26 +01:00
|
|
|
|
2017-10-31 14:05:54 +01:00
|
|
|
systemctl --user stop graphical-session.target
|
|
|
|
systemctl --user stop graphical-session-pre.target
|
2017-01-15 10:46:20 +01:00
|
|
|
|
2017-10-31 14:05:54 +01:00
|
|
|
# Wait until the units actually stop.
|
2019-09-11 20:11:16 +02:00
|
|
|
while [ -n "$(systemctl --user --no-legend --state=deactivating list-units)" ]; do
|
2017-10-31 14:05:54 +01:00
|
|
|
sleep 0.5
|
|
|
|
done
|
2023-05-07 23:59:56 +02:00
|
|
|
|
|
|
|
${optionalString (cfg.importedVariables != [ ])
|
|
|
|
("systemctl --user unset-environment "
|
|
|
|
+ escapeShellArgs cfg.importedVariables)}
|
2017-10-31 14:05:54 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2017-01-07 19:16:26 +01:00
|
|
|
}
|