`programs.<program>.enable` doesn't auto-start waybar and nm-applet with Hyprland and SDDM

With Hypyland and SDDM, set programs.waybar.enable and programs.nm-applet.enable to true, then both do not work. In comparison, only enabling waybar here, but setting up nm-applet in environment.systemPackages and auto-starting them mannually with exec-once in hyprland.conf led to proper working.

According to their Nixpkgs files, both programs.waybar and programs.nm-applet seem to be intended to auto-run with their corresponding Systemd services. They are found enabled with systemctl --user list-unit-files (thanks for notification by @peterhoeg ), but nothing shows up as GUI.

configuration.nix

{ config, pkgs, ... }:

{
  imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
      ./cachix.nix
    ];

  boot.loader.systemd-boot = {
    enable = true;
    editor = false;
  };
  boot.loader.efi.canTouchEfiVariables = true;

  services.logind.extraConfig = "HandlePowerKey=ignore";

  networking.hostName = "abcdef";
  networking.networkmanager.enable = true;

  time.timeZone = "Asia/Shanghai";

  i18n = {
        supportedLocales = [
          "en_US.UTF-8/UTF-8"
          "en_GB.UTF-8/UTF-8"
          "zh_CN.UTF-8/UTF-8"
          "zh_TW.UTF-8/UTF-8"
          "ja_JP.UTF-8/UTF-8"
        ];
        inputMethod = {
          enabled = "fcitx5";
          fcitx5.addons = with pkgs; [
                fcitx5-m17n
                fcitx5-chinese-addons
                fcitx5-rime
          ];
        };
  };
  fonts.fonts = with pkgs; [
    dejavu_fonts
    noto-fonts
    freefont_ttf
    noto-fonts-emoji
    twitter-color-emoji
    wqy_zenhei
    wqy_microhei
    noto-fonts-cjk-sans
    noto-fonts-cjk-serif
    arphic-ukai
    arphic-uming
    font-awesome
  ];

  services.xserver = {
        enable = true;
        displayManager.sddm = {
          enable = true;
          autoNumlock = true;
        };
  };
  programs.hyprland = {
        enable = true;
        xwayland.hidpi = true;
  };
  services.pipewire = {
        enable = true;
        wireplumber.enable = true;
  };
  programs.waybar.enable = true;
  programs.nm-applet.enable = true;

  sound.enable = true;
  hardware.pulseaudio.enable = true;

  services.xserver.libinput.enable = true;

  users.users.abcdefg = {
    description = "abcd efg";
    initialPassword = "**********";
    isNormalUser = true;
    extraGroups = [ "wheel" "networkmanager" ];
    packages = with pkgs; [
      nushell
      kitty
      fuzzel
      thunderbird
      libreoffice
      libsForQt5.okular
      freeplane
      guile_3_0
    ];
  };

  environment.systemPackages = with pkgs; [
    cachix
    micro
    helix
    lxqt.lxqt-policykit
    swaylock
    brightnessctl
    dunst
    hyprpaper
    chromium
  ];
  programs.zsh = {
        enable = true;
        ohMyZsh = {
          enable = true;
          plugins = [
            "command-not-found"
            "aliases"
            "emoji-clock"
          ];
          theme = "af-magic";
          customPkgs = with pkgs; [
                nix-zsh-completions
          ];
        };
  };
  programs.git.enable = true;
  services.emacs.enable = true;
  programs.firefox = {
        enable = true;
        package = pkgs.firefox-devedition;
  };
  programs.chromium = {
        enable = true;
        defaultSearchProviderEnabled = true;
        defaultSearchProviderSearchURL = "https://search.nixos.org/options?channel=23.05&query={searchTerms}";
  };

  users.defaultUserShell = pkgs.zsh;
  environment.variables.EDITOR = "micro";
  environment.variables.VISUAL = "hx";
  security.pam.services.swaylock = {};

  services.openssh.enable = true;
  programs.ssh.startAgent = true;

  nix.settings.substituters = [
    "https://mirrors.ustc.edu.cn/nix-channels/store"
    "https://mirrors.bfsu.edu.cn/nix-channels/store"
    "https://mirror.nju.edu.cn/nix-channels/store"
    "https://mirror.iscas.ac.cn/nix-channels/store"
  ];
  nix.gc = {
    automatic = true;
    dates = "weekly";
  };
  system.autoUpgrade = {
    enable = true;
    dates = "weekly";
    allowReboot = true;
  };

  system.copySystemConfiguration = true;

  system.stateVersion = "23.05";

}

I cannot say anything about hyprland, but graphical-session.target is a user target, so you need systemctl --user list-units.

1 Like

Xorg will execute a variety of scripts after it launches, to do things like starting services that need a graphical environment to run, or set up monitor settings and whatnot. This mechanism is what is used to start the graphical session target under NixOS.

Wayland sessions however are not X sessions, and therefore don’t necessarily follow Xorg’s rules. In theory the compositor would be in charge of running these scripts, since the graphical environment must already be running for them to work, and only the compositor can know when that is, but as far as I know at least none of the wlroots compositors have support for X init scripts.

This means that yes, those options don’t work for Hyprland.

I don’t necessarily think Hyprland should have support for running X init scripts either, but currently the only alternative is stuff like exec-once in individual compositor’s user configuration, which obviously doesn’t really work for distros packaging these compositors, and is ultimately why you’re running into this problem.

As a workaround, for now you can add exec-once = systemctl --user start graphical-session.target to your hyprland config. You’ll probably want to at least import user variables into systemd too, so that whatever you run with it actually knows what wayland session to display on. Or figure out how to run the X session init script with exec-once, ideally with the X-specific things patched out.

I think there’s an issue about this on GitHub somewhere, I commented on it around April this year when I chased this exact same problem.

Sadly I don’t think NixOS can really do much about this. At best we’d introduce some nonstandard /etc/wayland-init that users must execute as part of their compositor config or such.

Ultimately this is a flaw of the wayland ecosystem. It’s in sore need of some standards, gnome and wlroots are also extremely at odds around things like virtual input and screensharing protocols, which currently breaks a lot of applications. I hope freedesktop gets around to looking at this some day.

2 Likes