Add comprehensive NixOS support with flake and home-manager integration#778
Add comprehensive NixOS support with flake and home-manager integration#778truongsinh wants to merge 10 commits intoRedBearAK:mainfrom
Conversation
Enables seamless declarative installation on NixOS via flake, matching Ubuntu's ease of use. Includes NixOS and home-manager modules, overlay for packages, comprehensive VM integration tests, and complete documentation. Users can now install with a simple nixos-rebuild switch after adding to their config.
|
This is pretty extensive, and I'm wholly unqualified to say how good the nix parts are. Looks like a lot of work was put into it though, and I like to see all the testing stuff. Testing is usually a good idea. I'm interested in why the GNOME window manager is apparently not being identified correctly, necessitating this addition to the config file: elif SESSION_TYPE == 'wayland' and DESKTOP_ENV == 'gnome' and WINDOW_MGR == 'WM_unidentified_by_logic':
# GNOME Wayland - window manager detection may fail, use DESKTOP_ENV as fallback
debug(f"GNOME Wayland detected, using DESKTOP_ENV as compositor.", ctx="CG")
_wl_compositor = 'gnome'This kind of thing should probably be dealt with in the environment context module. And from what I've encountered the actual window manager/compositor is generally "gnome-shell", not "gnome". Unless something has changed with recent GNOME. Is the process list not available to the user on NixOS? I can't imagine why else the window manager would be unidentified. |
|
I just made a bunch of changes in the main branch, while implementing support for Gentoo Linux. So you'd need to update this to avoid a conflict, at least in the setup script. Previous attempts at NixOS support from other Toshy users have been pretty fragile, locking in a specific version/state of Toshy. I'd like to hear about how this PR would handle Toshy updates and changes over time. Particularly around the list of packages that get installed in the Python virtual environment. |
- Include both nixos-based and gentoo-based distro groups - Add tests for GNOME window manager detection on NixOS - Update to latest main branch changes
Root cause: On NixOS, binaries are wrapped, so gnome-shell becomes .gnome-shell-wrapped, which is truncated to .gnome-shell-wr (15 chars). The pgrep -x exact match fails because it looks for 'gnome-shell' but finds '.gnome-shell-wr'. Solution: On NixOS, if exact match fails, fallback to substring match using pgrep without -x flag. This detects wrapped binaries correctly. Changes: - env_context.py: Add NixOS-specific fallback in is_process_running() - toshy_config.py: Remove workaround (no longer needed) - test_env_context_nixos.py: Add tests for wrapped process detection Tested on NixOS 26.05 with GNOME 49.3 - WINDOW_MGR now correctly detected as 'mutter' instead of 'WM_unidentified_by_logic'.
The fix correctly detects WINDOW_MGR as 'mutter' on GNOME, but environ_api only accepts 'gnome-shell' as a valid compositor name for GNOME Wayland. Add mapping logic to convert 'mutter' → 'gnome-shell' for GNOME desktops.
Fixes race condition where Toshy starts before GNOME Shell is fully ready, causing window manager detection to fail. On GNOME, the service now waits for org.gnome.Shell.target to ensure gnome-shell process is running before attempting detection.
WORKAROUND for issue where window manager detection works manually but fails in systemd service context on NixOS GNOME. Changes: - Add windowManager option to home-manager.nix module - Add TOSHY_WM_OVERRIDE environment variable support - Config reads TOSHY_WM_OVERRIDE to override auto-detection Usage (NixOS configuration): services.toshy.windowManager = "gnome-shell"; Root cause identified: NixOS wraps gnome-shell binary, appears as .gnome-shell-wr in process list. Fallback detection works when tested manually but fails in service context for unknown reasons. This override provides immediate fix while we investigate why execution context affects process detection.
Documents: - Problem description (works manually, fails in service) - Root cause (NixOS wrapped binaries) - Fix implementation (fallback detection + WM mapping) - The mystery (why context matters) - Workaround usage (windowManager option) - Investigation next steps (5 hypotheses to test) This provides comprehensive reference for future debugging and helps other NixOS users encountering the same issue.
Documents the window manager detection problem on NixOS GNOME, root cause investigation, and current workaround using windowManager override option. Includes: - Problem summary and symptoms - Root cause analysis (NixOS binary wrapping) - Investigation timeline and findings - Current workaround configuration - Next steps for permanent fix - Testing checklist
Adds wrapper scripts for GUI and CLI service control: - toshy-config-stop/restart - toshy-services-start/stop/restart/status/log - toshy-devices These scripts are needed for the GUI preferences app to function correctly, and provide a familiar CLI interface for users. Scripts are copied to libexec/toshy/bin and wrapped with appropriate PATH.
|
I took the provided information about NixOS wrapping processes, confirmed it with some online research, and then put together an update for the environment context module to hopefully accurately deal with process detection in NixOS. I didn't want to completely give up on the exact matching, so it will adjust to the NixOS patterns. And, inside the keymapper's (different repo) window context module, I added a tuple to allow Mutter to be a valid Wayland compositor value for the GNOME window context provider. Together these should solve the issue with identifying the WM and using the correct window context method on NixOS GNOME. If you can update, these changes are in the main branch of both repos, and you should see the keymapper version update to 1.11.3, and the env_context module should show "2026-02-02". Both appear in the output of Let me know how it goes. This should allow completely removing the adjustments from the config file. |
|
This seems to have two different install paths. The native NixOS flake-only approach, and then the changes to the setup script as an alternative. Is there a reason you didn't add something like this to the package install function, to prevent the need to use "--skip-native"? def install_distro_pkgs():
print(f'\n\n§ Installing native packages...\n{cnfg.separator}')
# NixOS: packages managed declaratively, skip native install
if cnfg.DISTRO_ID == 'nixos':
print('NixOS detected - native packages managed via configuration.nix')
print('Skipping native package installation.')
return
# ... rest of functionSeems like you've thought of pretty much everything else. Are you volunteering to respond to any issues with NixOS support if this were to be integrated into Toshy? I certainly can't do much with it myself, and it will need to be periodically updated. |
Summary
Enables seamless declarative installation on NixOS via flake, matching Ubuntu's ease of use.
Fixes #104
Changes
Benefits
Users can now install Toshy with a simple
nixos-rebuild switchafter adding to their configuration.Test Plan