workflows/mosey-branch: create desktop session files package

This should make it easier to manage the custom desktop files with the
usual toolchain for configuring and installing custom desktop files
(i.e., Meson). While this could be done with Nix, some parts of
installing files is easier with Meson.

Who knows, it might be reverted because my Nix-fu is pretty weak right
now.
This commit is contained in:
Gabriel Arazas 2023-08-12 15:46:03 +08:00
parent fa698a64cc
commit 0225342a05
No known key found for this signature in database
GPG Key ID: ADE0C41DAB221FCC
10 changed files with 177 additions and 102 deletions

View File

@ -0,0 +1,4 @@
= Mosey branch custom session
:toc:
This is an installation script for the custom desktop environment "Mosey branch".

View File

@ -0,0 +1,36 @@
{ stdenv
, lib
, meson
, ninja
, pkg-config
# This is the prefix used for the installed files in the output.
, prefix ? "one.foodogsquared.MoseyBranch"
, serviceScript ? "Hyprland"
, sessionScript ? "gnome-session --session=mosey-branch"
}:
stdenv.mkDerivation rec {
pname = "mosey-branch-custom-desktop-session";
version = "2023-08-11";
src = ./.;
nativeBulidInputs = [
meson
ninja
pkg-config
];
mesonFlags = [
"-Dsession_script=${sessionScript}"
"-Dservice_script=${serviceScript}"
];
passthru.providedSessions = [ "mosey-branch" ];
meta = with lib; {
description = "Custom desktop files for the custom desktop environment";
license = licenses.gpl3Plus;
platforms = platforms.linux;
};
}

View File

@ -0,0 +1,73 @@
project('mosey-branch',
version: '2023-08-11',
license: 'GPL-3.0-or-later',
meson_version: '>=0.54.0',
)
app_id = 'one.foodogsquared.MoseyBranch'
prefix = get_option('prefix')
datadir = join_paths(prefix, get_option('datadir'))
systemddir = join_paths(prefix, 'share/systemd')
systemduserdir = join_paths(systemddir, 'user')
required_components = [
#'polkit',
#'ibus',
#'ags',
]
session_dropins = [
'gnome-session@mosey-branch.target.d',
]
session_wants = ''
foreach component : required_components
session_wants += 'Wants=' + app_id + '.' + component + '.target\n'
endforeach
# Install each gnome-session overrides.
sessionconf = configuration_data()
sessionconf.set('session_wants', session_wants)
foreach session_dropin : session_dropins
configure_file(
input: 'mosey-branch.session.conf.in',
output: 'session.conf',
install_dir: join_paths(systemduserdir, session_dropin),
configuration: sessionconf,
install: true
)
endforeach
# Installing the Wayland session desktop entry.
desktopentryconf = configuration_data()
desktopentryconf.set('session_script', get_option('session_script'))
configure_file(
input: 'mosey-branch.desktop',
install_dir: join_paths(datadir, 'wayland-sessions'),
configuration: desktopentryconf,
install: true,
)
# Installing the core systemd units for the desktop session.
targetconf = configuration_data()
targetconf.set('app_id', app_id)
configure_file(
input: 'mosey-branch.target',
output: app_id + '.target',
install_dir: systemduserdir,
configuration: targetconf,
install: true,
)
serviceconf = configuration_data()
serviceconf.set('script', get_option('service_script'))
configure_file(
input: 'mosey-branch.service',
output: app_id + '.service',
install_dir: systemduserdir,
configuration: serviceconf,
install: true,
)
# TODO: Install the systemd units for the core components of the desktop
# environment.

View File

@ -0,0 +1,11 @@
option('service_script',
type: 'string',
value: 'Hyprland',
description: 'Executable for the main session script.'
)
option('session_script',
type: 'string',
value: 'gnome-session --session=mosey-branch',
description: 'Program (including its arguments) for the Wayland session entry file.',
)

View File

@ -1,7 +1,7 @@
[Desktop Entry] [Desktop Entry]
Name=Hyprland Name=Mosey Branch
Comment=foodogsquared's Hyprland-based desktop environment setup Comment=foodogsquared's Hyprland-based desktop environment setup
Exec=@script@ Exec=@session_script@
TryExec=@script@ TryExec=@session_script@
Type=Application Type=Application
DesktopNames=Hyprland DesktopNames=Mosey Branch

View File

@ -0,0 +1,22 @@
# This user service is intended to be started with gnome-session.
[Unit]
Description=Mosey Branch, a custom desktop session with Hyprland
Documentation=https://wiki.hyprland.org
After=gnome-manager-manager.target
Requisite=gnome-session-initialized.target
PartOf=gnome-session-initialized.target
OnFailure=gnome-session-shutdown.target
OnFailureJobMode=replace-irreversibly
CollectMode=inactive-or-failed
RefuseManualStart=true
RefuseManualStop=true
StartLimitBurst=4
[Service]
Type=notify
Slice=session.slice
Restart=on-failure
ExecStart=@script@

View File

@ -0,0 +1,4 @@
[Unit]
@@
Requires=one.foodogsquared.MoseyBranch.target

View File

@ -0,0 +1,11 @@
[Unit]
Description=Mosey Branch
Documentation=man:systemd.special(7)
DefaultDependencies=no
Requisite=gnome-session-initialized.target
PartOf=gnome-session-initialized.target
Before=gnome-session-initialized.target
Requires=@app_id@.service
After=@app_id@.service

View File

@ -1,3 +0,0 @@
[GNOME Session]
Name=Hyprland
RequiredComponents=@requiredComponents@

View File

@ -4,37 +4,17 @@ let
cfg = config.workflows.workflows.mosey-branch; cfg = config.workflows.workflows.mosey-branch;
workflowName = "mosey-branch"; workflowName = "mosey-branch";
# This is used in a similar manner for GNOME desktop applications and its # A reverse DNS prefix similarly used to GNOME services.
# services. prefix = "one.foodogsquared.MoseyBranch.";
prefix = "one.foodogsquared.${workflowName}.";
hyprlandCustomGnomeSession = pkgs.substituteAll { customDesktopSession = pkgs.callPackage ./config/desktop-session {
src = ./config/gnome-session/hyprland.session; inherit prefix;
name = "${workflowName}.session"; serviceScript = "${pkgs.hyprland}/bin/Hyprland --config ${./config/hyprland/hyprland.conf}";
dir = "share/gnome-session"; sessionScript = pkgs.writeShellScript "${workflowName}-hyprland-custom-start" ''
requiredComponents = ${pkgs.gnome.gnome-session}/bin/gnome-session --session=${workflowName}
lib.concatMapString (component: "${prefix}${component};") ([ '';
"ags"
"polkit"
]
++ lib.optional (config.i18n.inputMethod == "fcitx5") "fcitx5"
++ lib.optional (config.i18n.inputMethod == "ibus") "ibus");
}; };
hyprlandStartScript = pkgs.writeShellScript "${workflowName}-hyprland-custom-start" ''
${pkgs.gnome.gnome-session}/bin/gnome-session --session=${workflowName}
'';
hyprlandSessionPackage =
(pkgs.substituteAll {
src = ./config/wayland-sessions/hyprland.desktop;
name = "${workflowName}.desktop";
dir = "share/wayland-sessions";
script = hyprlandStartScript;
}).overrideAttrs {
passthru.providedSessions = [ workflowName ];
};
requiredPackages = with pkgs; [ requiredPackages = with pkgs; [
# The star of this show: the window manager (or Wayland compositor if you # The star of this show: the window manager (or Wayland compositor if you
# want to be a hair-pulling semantic bastard). # want to be a hair-pulling semantic bastard).
@ -46,8 +26,8 @@ let
ags ags
gtk4-layer-shell gtk4-layer-shell
# Install with the custom session. # Install with the custom desktop session files.
hyprlandCustomGnomeSession customDesktopSession
# Optional dependencies that are required in this workflow module. # Optional dependencies that are required in this workflow module.
socat socat
@ -63,12 +43,6 @@ let
# The chosen terminal emulator. # The chosen terminal emulator.
wezterm wezterm
]; ];
createPrefixedServices = name: value:
lib.nameValuePair "${prefix}${name}" (value // {
partOf = [ "graphical-session.target" ];
wantedBy = [ "gnome-session.target" ];
});
in in
{ {
options.workflows.workflows.mosey-branch = { options.workflows.workflows.mosey-branch = {
@ -98,13 +72,14 @@ in
config = lib.mkIf cfg.enable (lib.mkMerge [ config = lib.mkIf cfg.enable (lib.mkMerge [
{ {
environment.systemPackages = cfg.extraApps ++ requiredPackages; environment.systemPackages = cfg.extraApps ++ requiredPackages;
systemd.packages = [ customDesktopSession ];
# Our preferred display manager. # Our preferred display manager.
services.xserver = { services.xserver = {
enable = true; enable = true;
displayManager = { displayManager = {
gdm.enable = lib.mkDefault true; gdm.enable = lib.mkDefault true;
sessionPackages = [ hyprlandSessionPackage ]; sessionPackages = [ customDesktopSession ];
}; };
updateDbusEnvironment = true; updateDbusEnvironment = true;
}; };
@ -152,64 +127,6 @@ in
}; };
} }
# These are all intended to be started with gnome-session.
# Much of the templates used are from Phosh systemd templates at
# https://gitlab.gnome.org/World/Phosh/phosh/-/blob/main/data/systemd.
# Big thanks to them! :)
{
systemd.user.targets."${prefix}" = {
description = "${workflowName} Hyprland shell";
documentation = [ "man:systemd.special(7)" ];
unitConfig.DefaultDependencies = "no";
requisite = [ "gnome-session-initialized.target" ];
partOf = [ "gnome-session-initialized.target" ];
before = [ "gnome-session-initialized.target" ];
wants = [ "${prefix}.service" ];
after = [ "${prefix}.service" ];
};
systemd.user.services = lib.mapAttrs' createPrefixedServices {
ags = {
description = "Widget system layer for the desktop";
script = "${pkgs.ags}/bin/ags";
};
polkit = {
description = "Authentication agent for the desktop session";
script = "${pkgs.polkit_gnome}/libexec/polkit-gnome-authentication-agent-1";
};
fcitx5 = lib.mkIf (config.i18n.inputMethod.enabled == "fcitx5") {
description = "Input method engine for the desktop session";
script = "${config.i18n.inputMethod.package}/bin/fcitx5";
};
ibus = lib.mkIf (config.i18n.inputMethod.enabled == "ibus") {
description = "Input method engine for the desktop session";
script = "${config.i18n.inputMethod.package}/bin/ibus start";
};
} // {
"${prefix}" = {
description = "${workflowName}, a custom desktop session with Hyprland";
documentation = [ "https://wiki.hyprland.org" ];
after = [ "gnome-manager-manager.target" ];
requisite = [ "gnome-session-initialized.target" ];
partOf = [ "gnome-session-initialized.target" ];
unitConfig = {
OnFailure = "gnome-session-shutdown.target";
OnFailureJobMode = "replace-irreversibly";
CollectMode = "inactive-or-failed";
RefuseManualStart = true;
RefuseManualStop = true;
};
script = "${pkgs.hyprland}/bin/Hyprland --config ${./config/hyprland/hyprland.conf}";
};
};
}
# Setting up my project-specific profiles. This is only to be applied for # Setting up my project-specific profiles. This is only to be applied for
# my setup. If you're not foodogsquared and you're using my project as one # my setup. If you're not foodogsquared and you're using my project as one
# of the flake input, this shouldn't be applied nor be used in the first # of the flake input, this shouldn't be applied nor be used in the first