nixpkgs/nixos/modules/services/x11/desktop-managers/default.nix

123 lines
3.5 KiB
Nix
Raw Normal View History

{
config,
lib,
pkgs,
...
}:
let
inherit (lib) mkOption types;
xcfg = config.services.xserver;
cfg = xcfg.desktopManager;
# If desktop manager `d' isn't capable of setting a background and
# the xserver is enabled, `feh' or `xsetroot' are used as a fallback.
needBGCond = d: !(d ? bgSupport && d.bgSupport) && xcfg.enable;
in
{
# Note: the order in which desktop manager modules are imported here
# determines the default: later modules (if enabled) are preferred.
# E.g., if Plasma 5 is enabled, it supersedes xterm.
imports = [
./none.nix
./xterm.nix
./phosh.nix
./xfce.nix
./plasma5.nix
../../desktop-managers/plasma6.nix
./lumina.nix
./lxqt.nix
./enlightenment.nix
./retroarch.nix
./kodi.nix
./mate.nix
./pantheon.nix
./surf-display.nix
./cde.nix
./cinnamon.nix
./budgie.nix
./deepin.nix
../../desktop-managers/lomiri.nix
2025-03-24 01:39:32 +05:30
../../desktop-managers/cosmic.nix
../../desktop-managers/gnome.nix
];
options = {
services.xserver.desktopManager = {
wallpaper = {
mode = mkOption {
type = types.enum [
"center"
"fill"
"max"
"scale"
"tile"
];
default = "scale";
example = "fill";
description = ''
The file {file}`~/.background-image` is used as a background image.
This option specifies the placement of this image onto your desktop.
Possible values:
`center`: Center the image on the background. If it is too small, it will be surrounded by a black border.
`fill`: Like `scale`, but preserves aspect ratio by zooming the image until it fits. Either a horizontal or a vertical part of the image will be cut off.
`max`: Like `fill`, but scale the image to the maximum size that fits the screen with black borders on one side.
`scale`: Fit the file into the background without repeating it, cutting off stuff or using borders. But the aspect ratio is not preserved either.
`tile`: Tile (repeat) the image in case it is too small for the screen.
'';
};
combineScreens = mkOption {
type = types.bool;
default = false;
description = ''
When set to `true` the wallpaper will stretch across all screens.
When set to `false` the wallpaper is duplicated to all screens.
'';
};
};
session = mkOption {
2013-10-30 17:37:45 +01:00
internal = true;
default = [ ];
example = lib.singleton {
name = "kde";
bgSupport = true;
start = "...";
};
description = ''
Internal option used to add some common line to desktop manager
scripts before forwarding the value to the
`displayManager`.
2013-10-30 17:37:45 +01:00
'';
apply = map (
d:
d
// {
manage = "desktop";
start =
d.start
# literal newline to ensure d.start's last line is not appended to
+ lib.optionalString (needBGCond d) ''
nixos/desktop-manager: Use literal newline to fix shell syntax Running `nixos/tests/keepassxc.nix` shows: ``` machine # [ 18.705390] xsession[985]: /nix/store/2g2jx5c6x3p152wbiijr0rmky7byqivc-xsession: line 13: nn: command not found ``` This garbled bash script runs without `set -o errexit` and thus skips "\n\n" as invalid command: ``` $ cat -n /nix/store/2g2jx5c6x3p152wbiijr0rmky7byqivc-xsession ... \n\n if [ -e $HOME/.background-image ]; then /nix/store/wq1d1ph8wj4alpx78akvpbd0a0m9qkd1-feh-3.8/bin/feh --bg-scale $HOME/.background-image fi ... ``` KeePassXC uses it through `nixos/modules/services/x11/display-managers/default.nix`: ``` ... # Script responsible for starting the window manager and the desktop manager. xsession = dm: wm: pkgs.writeScript "xsession" '' #! ${pkgs.bash}/bin/bash # Legacy session script used to construct .desktop files from # `services.xserver.displayManager.session` entries. Called from # `sessionWrapper`. # Start the window manager. ${wm.start} # Start the desktop manager. ${dm.start} ... ''; ... ``` The bogus line was introduced in PR #160752: ``` commit 0bc0dc8090e6609838816f43dc7799e32c674434 Author: Shaw Vrana <shaw@vranix.com> Date: Fri Feb 18 11:27:42 2022 -0800 desktop manager script: start properly Adds a missing line feed when X is enabled to the start script name and the appended if check. Resolves #160735 ``` I have not tried to reproduce the original issue and thus don't know why "\n\n" apparently gets interpreted fine in one place but remains literal the `xsession` case. However, using a literal newline must be valid for all cases and certainly fixes the warning seen in KeePassXC tests. Furthermore, starting the nix string (`''`) with a newline as usual also fixes its overall indentation.
2022-07-01 16:10:14 +04:00
if [ -e $HOME/.background-image ]; then
${pkgs.feh}/bin/feh --bg-${cfg.wallpaper.mode} ${lib.optionalString cfg.wallpaper.combineScreens "--no-xinerama"} $HOME/.background-image
fi
'';
}
);
};
};
};
config.services.xserver.displayManager.session = cfg.session;
}