Skip to content

Commit

Permalink
gnome-flashback: add option to remove gnome-panel, auto-generate wmName
Browse files Browse the repository at this point in the history
  • Loading branch information
chpatrick committed May 28, 2021
1 parent 572eb44 commit 424cd7d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 33 deletions.
61 changes: 40 additions & 21 deletions nixos/modules/services/x11/desktop-managers/gnome.nix
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ let
'';

flashbackEnabled = cfg.flashback.enableMetacity || length cfg.flashback.customSessions > 0;
flashbackWms = optional cfg.flashback.enableMetacity {
wmName = "metacity";
wmLabel = "Metacity";
wmCommand = "${pkgs.gnome.metacity}/bin/metacity";
enableGnomePanel = true;
} ++ cfg.flashback.customSessions;

notExcluded = pkg: mkDefault (!(lib.elem pkg config.environment.gnome.excludePackages));

Expand Down Expand Up @@ -216,20 +222,25 @@ in
debug = mkEnableOption "gnome-session debug messages";

flashback = {
enableMetacity = mkEnableOption "the standard GNOME Flashback session with Metacity";
enableMetacity = mkOption {
type = types.bool;
default = true;
example = "false";
description = "Whether to enable the standard Metacity GNOME flashback session.";
};

customSessions = mkOption {
type = types.listOf (types.submodule {
options = {
wmName = mkOption {
type = types.str;
description = "The filename-compatible name of the window manager to use.";
type = types.strMatching "[a-zA-Z0-9_-]+";
description = "A unique identifier for the window manager.";
example = "xmonad";
};

wmLabel = mkOption {
type = types.str;
description = "The pretty name of the window manager to use.";
description = "The name of the window manager to show in the session chooser.";
example = "XMonad";
};

Expand All @@ -238,6 +249,13 @@ in
description = "The executable of the window manager to use.";
example = "\${pkgs.haskellPackages.xmonad}/bin/xmonad";
};

enableGnomePanel = mkOption {
type = types.bool;
default = true;
example = "false";
description = "Whether to enable the GNOME panel in this session.";
};
};
});
default = [];
Expand Down Expand Up @@ -295,30 +313,31 @@ in
})

(mkIf flashbackEnabled {
services.xserver.displayManager.sessionPackages = map
(wm: pkgs.gnome.gnome-flashback.mkSessionForWm {
inherit (wm) wmName wmLabel wmCommand;
}) (optional cfg.flashback.enableMetacity {
wmName = "metacity";
wmLabel = "Metacity";
wmCommand = "${pkgs.gnome.metacity}/bin/metacity";
} ++ cfg.flashback.customSessions);
services.xserver.displayManager.sessionPackages =
let
wmNames = map (wm: wm.wmName) flashbackWms;
namesAreUnique = lib.unique wmNames == wmNames;
in
assert (assertMsg namesAreUnique "Flashback WM names must be unique.");
map
(wm:
pkgs.gnome.gnome-flashback.mkSessionForWm {
inherit (wm) wmName wmLabel wmCommand enableGnomePanel;
}
) flashbackWms;

security.pam.services.gnome-flashback = {
enableGnomeKeyring = true;
};

systemd.packages = with pkgs.gnome; [
gnome-flashback
] ++ (map
(wm: gnome-flashback.mkSystemdTargetForWm {
inherit (wm) wmName;
}) cfg.flashback.customSessions);

# gnome-panel needs these for menu applet
environment.sessionVariables.XDG_DATA_DIRS = [ "${pkgs.gnome.gnome-flashback}/share" ];
# TODO: switch to sessionVariables (resolve conflict)
environment.variables.XDG_CONFIG_DIRS = [ "${pkgs.gnome.gnome-flashback}/etc/xdg" ];
] ++ map gnome-flashback.mkSystemdTargetForWm flashbackWms;

# gnome-panel needs these for menu applet
environment.sessionVariables.XDG_DATA_DIRS = [ "${pkgs.gnome.gnome-flashback}/share" ];
# TODO: switch to sessionVariables (resolve conflict)
environment.variables.XDG_CONFIG_DIRS = [ "${pkgs.gnome.gnome-flashback}/etc/xdg" ];
})

(mkIf serviceCfg.core-os-services.enable {
Expand Down
1 change: 1 addition & 0 deletions nixos/modules/services/x11/desktop-managers/gnome.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
wmName = "xmonad";
wmLabel = "XMonad";
wmCommand = "${pkgs.haskellPackages.xmonad}/bin/xmonad";
enableGnomePanel = false;
}
];
</programlisting>
Expand Down
24 changes: 12 additions & 12 deletions pkgs/desktops/gnome/misc/gnome-flashback/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ let
version = "3.40.0";

# From data/sessions/Makefile.am
requiredComponentsCommon = [
"gnome-flashback"
"gnome-panel"
];
requiredComponentsCommon = enableGnomePanel:
[ "gnome-flashback" ]
++ lib.optional enableGnomePanel "gnome-panel";
requiredComponentsGsd = [
"org.gnome.SettingsDaemon.A11ySettings"
"org.gnome.SettingsDaemon.Color"
Expand All @@ -55,7 +54,8 @@ let
"org.gnome.SettingsDaemon.Wacom"
"org.gnome.SettingsDaemon.XSettings"
];
requiredComponents = wmName: "RequiredComponents=${lib.concatStringsSep ";" ([ wmName ] ++ requiredComponentsCommon ++ requiredComponentsGsd)};";
requiredComponents = wmName: enableGnomePanel: "RequiredComponents=${lib.concatStringsSep ";" ([ wmName ] ++ requiredComponentsCommon enableGnomePanel ++ requiredComponentsGsd)};";

gnome-flashback = stdenv.mkDerivation rec {
name = "${pname}-${version}";

Expand All @@ -77,7 +77,7 @@ let
postInstall = ''
# Check that our expected RequiredComponents match the stock session files, but then don't install them.
# They can be installed using mkSessionForWm.
grep '${requiredComponents "metacity"}' $out/share/gnome-session/sessions/gnome-flashback-metacity.session || (echo "RequiredComponents have changed, please update gnome-flashback/default.nix."; false)
grep '${requiredComponents "metacity" true}' $out/share/gnome-session/sessions/gnome-flashback-metacity.session || (echo "RequiredComponents have changed, please update gnome-flashback/default.nix."; false)
rm -r $out/share/gnome-session
rm -r $out/share/xsessions
Expand Down Expand Up @@ -126,7 +126,7 @@ let
versionPolicy = "odd-unstable";
};

mkSessionForWm = { wmName, wmLabel, wmCommand }:
mkSessionForWm = { wmName, wmLabel, wmCommand, enableGnomePanel }:
let
wmApplication = writeTextFile {
name = "gnome-flashback-${wmName}-wm";
Expand All @@ -151,7 +151,7 @@ let
text = ''
[GNOME Session]
Name=GNOME Flashback (${wmLabel})
${requiredComponents wmName}
${requiredComponents wmName enableGnomePanel}
'';
};

Expand Down Expand Up @@ -183,11 +183,11 @@ let
providedSessions = [ "gnome-flashback-${wmName}" ];
};

mkSystemdTargetForWm = { wmName }:
runCommand "gnome-flashback-${wmName}.target" { } ''
mkSystemdTargetForWm = { wmName, wmLabel, wmCommand, enableGnomePanel }:
runCommand "gnome-flashback-${wmName}.target" {} ''
mkdir -p $out/lib/systemd/user
cp "${gnome-flashback}/lib/systemd/user/gnome-session-x11@gnome-flashback-metacity.target" \
"$out/lib/systemd/user/gnome-session-x11@gnome-flashback-${wmName}.target"
cp -r "${gnome-flashback}/lib/systemd/user/[email protected].d" \
"$out/lib/systemd/user/gnome-session@gnome-flashback-${wmName}.target.d"
'';
};

Expand Down

0 comments on commit 424cd7d

Please sign in to comment.