From 0225342a05f6674ac02ca35fdcf97ef84a9dc1d8 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Sat, 12 Aug 2023 15:46:03 +0800 Subject: [PATCH] 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. --- .../config/desktop-session/README.adoc | 4 + .../config/desktop-session/default.nix | 36 ++++++ .../config/desktop-session/meson.build | 73 ++++++++++++ .../config/desktop-session/meson_options.txt | 11 ++ .../mosey-branch.desktop} | 8 +- .../desktop-session/mosey-branch.service | 22 ++++ .../mosey-branch.session.conf.in | 4 + .../desktop-session/mosey-branch.target | 11 ++ .../config/gnome-session/hyprland.session | 3 - .../nixos/workflows/mosey-branch/default.nix | 107 ++---------------- 10 files changed, 177 insertions(+), 102 deletions(-) create mode 100644 modules/nixos/workflows/mosey-branch/config/desktop-session/README.adoc create mode 100644 modules/nixos/workflows/mosey-branch/config/desktop-session/default.nix create mode 100644 modules/nixos/workflows/mosey-branch/config/desktop-session/meson.build create mode 100644 modules/nixos/workflows/mosey-branch/config/desktop-session/meson_options.txt rename modules/nixos/workflows/mosey-branch/config/{wayland-sessions/hyprland.desktop => desktop-session/mosey-branch.desktop} (51%) create mode 100644 modules/nixos/workflows/mosey-branch/config/desktop-session/mosey-branch.service create mode 100644 modules/nixos/workflows/mosey-branch/config/desktop-session/mosey-branch.session.conf.in create mode 100644 modules/nixos/workflows/mosey-branch/config/desktop-session/mosey-branch.target delete mode 100644 modules/nixos/workflows/mosey-branch/config/gnome-session/hyprland.session diff --git a/modules/nixos/workflows/mosey-branch/config/desktop-session/README.adoc b/modules/nixos/workflows/mosey-branch/config/desktop-session/README.adoc new file mode 100644 index 00000000..68aa7c54 --- /dev/null +++ b/modules/nixos/workflows/mosey-branch/config/desktop-session/README.adoc @@ -0,0 +1,4 @@ += Mosey branch custom session +:toc: + +This is an installation script for the custom desktop environment "Mosey branch". diff --git a/modules/nixos/workflows/mosey-branch/config/desktop-session/default.nix b/modules/nixos/workflows/mosey-branch/config/desktop-session/default.nix new file mode 100644 index 00000000..fb0ae309 --- /dev/null +++ b/modules/nixos/workflows/mosey-branch/config/desktop-session/default.nix @@ -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; + }; +} diff --git a/modules/nixos/workflows/mosey-branch/config/desktop-session/meson.build b/modules/nixos/workflows/mosey-branch/config/desktop-session/meson.build new file mode 100644 index 00000000..b7c09285 --- /dev/null +++ b/modules/nixos/workflows/mosey-branch/config/desktop-session/meson.build @@ -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. diff --git a/modules/nixos/workflows/mosey-branch/config/desktop-session/meson_options.txt b/modules/nixos/workflows/mosey-branch/config/desktop-session/meson_options.txt new file mode 100644 index 00000000..b5c626cb --- /dev/null +++ b/modules/nixos/workflows/mosey-branch/config/desktop-session/meson_options.txt @@ -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.', +) diff --git a/modules/nixos/workflows/mosey-branch/config/wayland-sessions/hyprland.desktop b/modules/nixos/workflows/mosey-branch/config/desktop-session/mosey-branch.desktop similarity index 51% rename from modules/nixos/workflows/mosey-branch/config/wayland-sessions/hyprland.desktop rename to modules/nixos/workflows/mosey-branch/config/desktop-session/mosey-branch.desktop index a6f304fe..2db4ac25 100644 --- a/modules/nixos/workflows/mosey-branch/config/wayland-sessions/hyprland.desktop +++ b/modules/nixos/workflows/mosey-branch/config/desktop-session/mosey-branch.desktop @@ -1,7 +1,7 @@ [Desktop Entry] -Name=Hyprland +Name=Mosey Branch Comment=foodogsquared's Hyprland-based desktop environment setup -Exec=@script@ -TryExec=@script@ +Exec=@session_script@ +TryExec=@session_script@ Type=Application -DesktopNames=Hyprland +DesktopNames=Mosey Branch diff --git a/modules/nixos/workflows/mosey-branch/config/desktop-session/mosey-branch.service b/modules/nixos/workflows/mosey-branch/config/desktop-session/mosey-branch.service new file mode 100644 index 00000000..c8dc9b9f --- /dev/null +++ b/modules/nixos/workflows/mosey-branch/config/desktop-session/mosey-branch.service @@ -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@ diff --git a/modules/nixos/workflows/mosey-branch/config/desktop-session/mosey-branch.session.conf.in b/modules/nixos/workflows/mosey-branch/config/desktop-session/mosey-branch.session.conf.in new file mode 100644 index 00000000..98ca72a8 --- /dev/null +++ b/modules/nixos/workflows/mosey-branch/config/desktop-session/mosey-branch.session.conf.in @@ -0,0 +1,4 @@ +[Unit] +@@ + +Requires=one.foodogsquared.MoseyBranch.target diff --git a/modules/nixos/workflows/mosey-branch/config/desktop-session/mosey-branch.target b/modules/nixos/workflows/mosey-branch/config/desktop-session/mosey-branch.target new file mode 100644 index 00000000..6fecea21 --- /dev/null +++ b/modules/nixos/workflows/mosey-branch/config/desktop-session/mosey-branch.target @@ -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 diff --git a/modules/nixos/workflows/mosey-branch/config/gnome-session/hyprland.session b/modules/nixos/workflows/mosey-branch/config/gnome-session/hyprland.session deleted file mode 100644 index dec3317d..00000000 --- a/modules/nixos/workflows/mosey-branch/config/gnome-session/hyprland.session +++ /dev/null @@ -1,3 +0,0 @@ -[GNOME Session] -Name=Hyprland -RequiredComponents=@requiredComponents@ diff --git a/modules/nixos/workflows/mosey-branch/default.nix b/modules/nixos/workflows/mosey-branch/default.nix index 149bfafc..ac8e000d 100644 --- a/modules/nixos/workflows/mosey-branch/default.nix +++ b/modules/nixos/workflows/mosey-branch/default.nix @@ -4,37 +4,17 @@ let cfg = config.workflows.workflows.mosey-branch; workflowName = "mosey-branch"; - # This is used in a similar manner for GNOME desktop applications and its - # services. - prefix = "one.foodogsquared.${workflowName}."; + # A reverse DNS prefix similarly used to GNOME services. + prefix = "one.foodogsquared.MoseyBranch."; - hyprlandCustomGnomeSession = pkgs.substituteAll { - src = ./config/gnome-session/hyprland.session; - name = "${workflowName}.session"; - dir = "share/gnome-session"; - requiredComponents = - lib.concatMapString (component: "${prefix}${component};") ([ - "ags" - "polkit" - ] - ++ lib.optional (config.i18n.inputMethod == "fcitx5") "fcitx5" - ++ lib.optional (config.i18n.inputMethod == "ibus") "ibus"); + customDesktopSession = pkgs.callPackage ./config/desktop-session { + inherit prefix; + serviceScript = "${pkgs.hyprland}/bin/Hyprland --config ${./config/hyprland/hyprland.conf}"; + sessionScript = pkgs.writeShellScript "${workflowName}-hyprland-custom-start" '' + ${pkgs.gnome.gnome-session}/bin/gnome-session --session=${workflowName} + ''; }; - 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; [ # The star of this show: the window manager (or Wayland compositor if you # want to be a hair-pulling semantic bastard). @@ -46,8 +26,8 @@ let ags gtk4-layer-shell - # Install with the custom session. - hyprlandCustomGnomeSession + # Install with the custom desktop session files. + customDesktopSession # Optional dependencies that are required in this workflow module. socat @@ -63,12 +43,6 @@ let # The chosen terminal emulator. wezterm ]; - - createPrefixedServices = name: value: - lib.nameValuePair "${prefix}${name}" (value // { - partOf = [ "graphical-session.target" ]; - wantedBy = [ "gnome-session.target" ]; - }); in { options.workflows.workflows.mosey-branch = { @@ -98,13 +72,14 @@ in config = lib.mkIf cfg.enable (lib.mkMerge [ { environment.systemPackages = cfg.extraApps ++ requiredPackages; + systemd.packages = [ customDesktopSession ]; # Our preferred display manager. services.xserver = { enable = true; displayManager = { gdm.enable = lib.mkDefault true; - sessionPackages = [ hyprlandSessionPackage ]; + sessionPackages = [ customDesktopSession ]; }; 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 # 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