mirror of
https://github.com/nix-community/home-manager
synced 2024-11-10 15:14:26 +00:00
acf8d4e985
The systemd targets don't allow direct startup so we create our own target for graphical sessions managed by Home Environment.
105 lines
2.7 KiB
Nix
105 lines
2.7 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.xsession;
|
|
|
|
in
|
|
|
|
{
|
|
options = {
|
|
xsession = {
|
|
enable = mkEnableOption "X Session";
|
|
|
|
windowManager = 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 = "Path to window manager to exec.";
|
|
};
|
|
|
|
initExtra = mkOption {
|
|
type = types.lines;
|
|
default = "";
|
|
description = "Extra shell commands to run during initialization.";
|
|
};
|
|
};
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
systemd.user.services.setxkbmap = {
|
|
Unit = {
|
|
Description = "Set up keyboard in X";
|
|
};
|
|
|
|
Install = {
|
|
WantedBy = [ "graphical-session.target" ];
|
|
};
|
|
|
|
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}";
|
|
};
|
|
};
|
|
|
|
# A basic graphical session target for Home Manager.
|
|
systemd.user.targets.he-graphical-session = {
|
|
Unit = {
|
|
Description = "Home Manager X session";
|
|
Requires = [ "graphical-session-pre.target" ];
|
|
BindsTo = [ "graphical-session.target" ];
|
|
};
|
|
};
|
|
|
|
home.file.".xsession" = {
|
|
mode = "555";
|
|
text = ''
|
|
if [[ -e "$HOME/.profile" ]]; then
|
|
. "$HOME/.profile"
|
|
fi
|
|
|
|
# If there are any running services from a previous session.
|
|
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 start he-graphical-session.target
|
|
|
|
${cfg.initExtra}
|
|
|
|
${cfg.windowManager}
|
|
|
|
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
|
|
'';
|
|
};
|
|
};
|
|
}
|