stylix icon indicating copy to clipboard operation
stylix copied to clipboard

qt: puts NixOS systemd on non-NixOS distro path

Open toofewtooextra opened this issue 9 months ago • 10 comments

I use arch (btw) + home-manager on flakes. When stylix is enabled it makes systemd part unusable, especially things like run0, resolvectl etc: Failed to execute /run/current-system/sw/bin/pkttyagent: No such file or directory. running which run0 gives /home/admin/.nix-profile/bin/run0 and this occurs with all systemd pieces, altering fhs with nix's systemd.

Toggling stylix.enable = false; fix this behavior

Here's my flake.nix:

{
  description = "Benis";

  inputs = {
    nixpkgs.url = "nixpkgs/fca94f7ffffa10bbe9127624e3f29d1822ad397e";
    nixgl = {
      url = "github:johanneshorner/nixGL";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    stylix = {
      url = "github:danth/stylix";
      inputs.nixpkgs.follows = "nixpkgs";
      inputs.home-manager.follows = "home-manager";
    };
  };

  outputs = {nixpkgs, home-manager, nixgl, stylix, ... }:
    let
      lib = nixpkgs.lib;
      system = "x86_64-linux";
      pkgs = import nixpkgs {
        inherit system;
      };
    in {
      homeConfigurations = {
        admin = home-manager.lib.homeManagerConfiguration {
          inherit pkgs;
          extraSpecialArgs = {
            inherit nixgl;
          };
          modules = [ stylix.homeManagerModules.stylix ./home.nix ];
        };
      };
    };
}

and home.nix:

{inputs, config, lib, pkgs, nixgl, ... }:


{
  nix = {
    package = pkgs.nix;
    settings.experimental-features = [ "nix-command" "flakes" ];
  };
  targets.genericLinux.enable = true;
  nixGL.packages = nixgl.packages;
  nixGL.defaultWrapper = "mesa";
  nixGL.offloadWrapper = "nvidiaPrime";
  nixGL.installScripts = [ "mesa" "nvidiaPrime" ];

  home.username = "admin";
  home.homeDirectory = "/home/admin";
  home.sessionVariables = {
    EDITOR = "nvim";
  };
  nixpkgs.config = {
    allowUnfree = true;
    allowUnfreePredicate = (pkg: true);
  };
  nixpkgs.overlays = [
    #(final: prev: {wl-clipboard = final.wl-clipboard-rs;})
    (final: prev: {hyprland = config.lib.nixGL.wrap prev.hyprland;})
  ];
  xdg = {
    enable = true;
    mime.enable = true;
    portal = {
      enable = true;
      extraPortals = [ pkgs.xdg-desktop-portal-hyprland ];
      configPackages = [ pkgs.hyprland ];
    };
    mimeApps = {
      enable = true;
      #defaultApplications = {
      #  "application/pdf" = [ "librewolf.desktop" ];
      #};
    };
  };
  home.stateVersion = "24.11"; # Please read the comment before changing.

  home.packages = [
    pkgs.kitty
    pkgs.eaglemode
    pkgs.monero-gui
    pkgs.wl-clipboard
    pkgs.cliphist
    pkgs.grim
    pkgs.slurp
    pkgs.wluma
    (config.lib.nixGL.wrapOffload pkgs.pcsx2)
    pkgs.brightnessctl
    pkgs.rquickshare
    #pkgs.nvtopPackages.nvidia

    pkgs.fzf
    pkgs.gitui
    pkgs.ripgrep
    pkgs.tlrc
    pkgs.libarchive
    pkgs.fastfetch
    pkgs.dash
    pkgs.netcat
    pkgs.htop
    pkgs.zsh
    pkgs.aider-chat
    pkgs.exiv2
    pkgs.mediainfo
    pkgs.bluetui
    pkgs.binsider
    pkgs.android-tools
    pkgs.devenv

    pkgs.inter
    pkgs.nerd-fonts.symbols-only

  ];

  wayland.windowManager.hyprland = {
    enable = true;
    package = pkgs.hyprland;
    systemd.enableXdgAutostart = true;
    systemd.variables = ["--all"];
    plugins = [pkgs.hyprlandPlugins.hyprwinwrap pkgs.hyprlandPlugins.hypr-dynamic-cursors];
    settings = {
      env = [
        "ELECTRON_OZONE_PLATFORM_HINT,wayland"
        "QT_QPA_PLATFORM,wayland"];
      exec-once = [
        "dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP"
        "wl-paste --type text --watch cliphist store"
        "wl-paste --type image --watch cliphist store"
        "systemctl --user start hyprpolkitagent"
        "wluma"
        "waybar"
        "hyprctl setcursor Bibata-Modern-Ice 16"
      ];
      "$mod" = "SUPER";
      bind = [
        "$mod, Q, killactive"
        "$mod, P, exit"
        "$mod, L, exec, hyprlock"
        "$mod, T, exec, kitty"
        "$mod, B, exec, librewolf"
        "$mod, N, exec, code" # somehow it fix giant cursor
        "SUPER_SHIFT, S, exec, grim -g \"$(slurp)\" - | wl-copy"
        "$mod, F, fullscreen"
        "$mod, J, movefocus, d"
        "$mod, K, movefocus, u"
        "$mod, H, movefocus, l"
        "$mod, L, movefocus, r"
        "$mod, 1, workspace, 1"
        "$mod, 2, workspace, 2" 
        "$mod, 3, workspace, 3"
        "$mod, 4, workspace, 4"
        "$mod, 5, workspace, 5"
        "$mod, 6, workspace, 6"
        "$mod, 7, workspace, 7"
        "$mod, 8, workspace, 8"
        "$mod, 9, workspace, 9"
        "$mod SHIFT, 1, movetoworkspace, 1"
        "$mod SHIFT, 2, movetoworkspace, 2"
        "$mod SHIFT, 3, movetoworkspace, 3"
        "$mod SHIFT, 4, movetoworkspace, 4"
        "$mod SHIFT, 5, movetoworkspace, 5"
        "$mod SHIFT, 6, movetoworkspace, 6"
        "$mod SHIFT, 7, movetoworkspace, 7"
        "$mod SHIFT, 8, movetoworkspace, 8"
        "$mod SHIFT, 9, movetoworkspace, 9"
      ];
      bindel = [
        "$mod SHIFT, right, resizeactive, 15% 0"
        "$mod SHIFT, left, resizeactive, -15% 0"
        "$mod SHIFT, up, resizeactive, 0 -15%"
        "$mod SHIFT, down, resizeactive, 0 15%"
        ",XF86AudioRaiseVolume, exec, wpctl set-volume -l 1 @DEFAULT_AUDIO_SINK@ 5%+"
        ",XF86AudioLowerVolume, exec, wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-"
        ",XF86AudioMute, exec, wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle"
        ",XF86AudioMicMute, exec, wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle"
        ",XF86MonBrightnessUp, exec, brightnessctl s 10%+"
        ",XF86MonBrightnessDown, exec, brightnessctl s 10%-"
      ];
      input = {
        kb_layout = "us,ru";
        kb_options = "grp:win_space_toggle";
      };
      general = {
        gaps_in = 1;
      	gaps_out = 0;
      	border_size = 0;
      };
      animations.enabled = false;
      decoration = {
        rounding = 0;
        blur.enabled = false;
      	shadow.enabled = false;
      };
      xwayland = {
        force_zero_scaling = true;
      };
      misc = {
        disable_autoreload = true;
      };
      "plugin:dynamic-cursors" = {
        enabled = true;
        mode = "stretch";
        stretch.limit = 5000;
        shake = {
          enabled = true;
          threshold = 5.0;
          timeout = 600;
        };
        hyprcursor.nearest = false;
      };
      plugins = {
      #  hyprwinwrap = {
      #    class = "kitty-bg";
      #  };
      };
    };
  };

  # Home Manager is pretty good at managing dotfiles. The primary way to manage
  # plain files is through 'home.file'.
  home.file = {
    # # Building this configuration will create a copy of 'dotfiles/screenrc' in
    # # the Nix store. Activating the configuration will then make '~/.screenrc' a
    # # symlink to the Nix store copy.
    # ".screenrc".source = dotfiles/screenrc;

    # # You can also set the file content immediately.
    # ".gradle/gradle.properties".text = ''
    #   org.gradle.console=verbose
    #   org.gradle.daemon.idletimeout=3600000
    # '';
  };

  systemd.user = {
    enable = true;
    systemctlPath = "/usr/bin/systemctl";
    startServices = "sd-switch";
  };

  programs = {
    home-manager.enable = true;
    git = {
      enable = true;
      userEmail = "[email protected]";
      userName = "john doe";
    };
    hyprlock = {
      # needs a workaround for pam.d - install from native package manager
      enable = false;
      settings = {
        general = {
          disable_loading_bar = true;
          hide_cursor = true;
          ignore_empty_input = true;
          immediate_render = true;
        };
        animations.enabled = false;
        background = {
          color = "rgba(0, 0, 0)";
        };
        label = {
          text = "cmd[update:1000] echo \"<b><big> $(date +\"%H:%M\") </big></b>\"";
          color = "rgb(255, 255, 255)";
          font_size = 128;
          font_family = "Inter Display";
          position = "0%, 20%";
          halign = "left";
          valign = "bottom";
        };
        input-field = {
          size = "200, 50";
          outline_thickness = 0;
          dots_size = 0.25;
          dots_spacing = 0.3;
          dots_center = true;
          dots_rounding = -1;
          inner_color = "rgba(0, 0, 0, 0.2)";
          font_color = "rgba(255, 255, 255, 0.6)";
          fail_color = "rgba(255, 60, 60, 0.2)";
          fade_on_empty = true;
          fade_timeout = 200;
          placeholder_text = "";
          fail_text = "Wrong password <b>($ATTEMPTS)</b>";
          fail_transition = 300;
          hide_input = false;
          rounding = -1;
          position = "0, -200";
          halign = "center";
          valign = "center";
        };
      };
    };
    waybar = {
      enable = true;
      settings = {
        mainBar = {
          layer = "top";
          height = 16;
          modules-left = [];
          modules-center = ["clock" "battery"];
          modules-right = ["group/right"];
          "hyprland/workspaces" = {
            "format" = "{name}";
            "on-click" = "activate";
          };
          "clock" = {
            "format-alt" = "{:%H:%M}";
          };
          "group/right" = {
            "orientation" = "inherit";
            "modules" = ["hyprland/language" "backlight" "network" "bluetooth" "tray"];
          };
          "battery" = {
            "format" = "{capacity}%";
            "format-charging" = "{capacity}%";
            "format-icons" = ["󰁺" "󰁼" "󰁾" "󰂀" "󰁹"];
          };
          "hyprland/language" = {
            "format" = "{}";
            "format-en" = "en";
            "format-ru" = "ru";
            position = "top";
          };
          "wireplumber" = {
            "format" = "{percent} 󰕿";
            "tooltip" = false;
            "format-muted" = "󰖁";
          };
          "wireplumber#mic" = {
            "format" = "{format_source}";
            "format-source" = "";
            "format-source-muted" = "";
            "tooltip" = false;
          };
          "backlight" = {
            "format" = "{icon}";
            "format-icons" = ["" "" "" "" "" "" "" "" "" ""];
          };
          "network" = {
            "format" = "{icon}";
            "format-wifi" = "󰤨";
            "format-ethernet" = "󰈁";
            "format-disconnected" = "󰖪";
            "format-linked" = "󰈁";
            "tooltip" = false;
          };
          "bluetooth" = {
            "format-on" = "";
            "format-off" = "󰂲";
            "format-disabled" = "";
            "format-connected" = "";
            "tooltip" = false;
          };
          "tray" = {
            "icon-size" = 12;
          };
        };
      };
      style = ''
* {
  font-family: 'Symbols Nerd Font', 'Inter Display', sans-serif;
  font-size: 13px;
  border: none;
  border-radius: 0px;
  box-shadow: none;
  text-shadow: none;
}

window#waybar {
  border-radius: 0px;
}

#window {
  padding: 2px 10px;
  margin: 4px 2px 4px 4px;
  border-radius: 10px;
}

#workspaces {
  margin: 4px 4px;
  border-radius: 10px;
}

#workspaces button {
  padding: 0px 4px;
  margin: 4px 4px;
}

#control-center {
  padding: 0px 8px;
  margin: 8px 4px;
  border-radius: 10px;
}

#bluetooth,
#network,
#backlight,
#tray {
  padding: 0px 0 0 5px;
}

#language {
  padding: 0px 3px 2px 0px;
}
'';
    };
    kitty = {
      enable = true;
      shellIntegration.enableZshIntegration = true;
      settings = {
        confirm_os_window_close = 0;
        enable_audio_bell = 0;
        tab_bar_style = "separator";
      	tab_separator = " | ";
        input_delay = 0;
        cursor_trail = 1;
        cursor_trail_decay = "0.07 0.15";
        sync_to_monitor = false;
      };
      keybindings = {
        "alt+t" = "new_tab_with_cwd";
        "alt+q" = "close_tab";
	      "alt+tab" = "next_tab";
        "alt+shift+tab" = "previous_tab";
      };
    };
    neovim = {
      enable = true;
      defaultEditor = true;
      viAlias = true;
      vimdiffAlias = true;
    };
    vscode = {
      enable = true;
      package = pkgs.vscode-fhs;
      userSettings = {
        "window.titleBarStyle" = "custom";
        "window.dialogStyle" = "custom";
        "window.menuBarVisibility" = "compact";
        "editor.fontLigatures" = "'calt' 0, 'HSKL' 1";
        "editor.fontFamily" = "'Symbols Nerd Font', 'Iosevka Term SS10', 'monospace', monospace";
        "workbench.colorTheme" = "Omni";
        "workbench.layoutControl.enabled" = false;
        "window.restoreFullscreen" = true;
        "window.newWindowDimensions" = "maximized";
        "window.experimentalControlOverlay" = false;
        "update.mode" = "manual";
        "files.trimFinalNewlines" = true;
        "files.insertFinalNewline" = true;
        #"terminal.integrated.profiles.linux" = {
        #  "zsh" = {
        #    "path" = "host-spawn";
        #    "args" = ["zsh"];
        #    "overrideName" = true;
        #  };
        #};
        #"terminal.integrated.defaultProfile.linux" = "sh";
        "console" = "externalTerminal";
        "telemetry.telemetryLevel" = "off";
      };
    };
    zsh = {
      enable = true;
      enableCompletion = true;
      autosuggestion.enable = true;
      localVariables = {ZSH_COMPDUMP = "$HOME/.cache/.zcompdump-$HOST";};
      history = {
        append = true;
        ignoreDups = true;
        ignoreAllDups = true;
        extended = true;
      };
      shellAliases = {
        hmu = "NIXPKGS_ALLOW_UNFREE=1 home-manager switch --flake ~/.config/home-manager --impure";
        touch = "_touch() { mkdir -p \"$(dirname \"$@\")\" && touch \"$@\"; }; _touch";
      };
      prezto = {
        enable = false;
        caseSensitive = false;
        editor.keymap = "vi";
      };
      oh-my-zsh = {
        enable = true;
        plugins = ["git" "fzf"];
        theme = "kardan";
      };
    };
    mpv = {
      enable = true;
      package = (config.lib.nixGL.wrapOffload pkgs.mpv);
      config = {
        embeddedfonts = "no";
        sub-font = "Inter Display";
        sub-font-size = 26;
        sub-color = "#92FFFFFF";
        sub-back-color = "#92000000";
        sub-border-style = "background-box";
        sub-border-size = 0;
        sub-pos = 5;
        sub-ass-override = "force";
      };
    };
    rtorrent = {
      enable = true;
    };
    yazi = {
      enable = true;
      enableZshIntegration = true;
      settings = {
        log.enabled = false;
        manager = {
          show_hidden = true;
        };
        opener = {
          img = [
            {run = "open \"$@\""; desc = "Open";}
            {run = "exiv2 \"$1\"; echo \"Press enter to exit\"; read"; block = true; desc = "EXIF";}
          ];
        };
        open.prepend_rules = [{mime = "image/*"; use = "img";}];
      };
    };
  };

  stylix = {
    enable = true;
    image = pkgs.fetchurl {
      url = "https://i.redd.it/up178ywbevee1.jpeg";
      hash = "sha256-smwzZaP9qbp0920hMqs0kI2ZWEiS0ycLJS5T32zA9Yo=";
    };
    base16Scheme = "${pkgs.base16-schemes}/share/themes/atelier-heath.yaml";
    cursor = {
      name = "Bibata-Modern-Ice";
      package = pkgs.bibata-cursors;
      size = 16;
    };
    iconTheme = {
      enable = true;
      package = pkgs.papirus-icon-theme;
      dark = "Papirus-Dark";
      light = "Papirus-Light";
    };
    fonts = {
      serif = config.stylix.fonts.sansSerif;
      sansSerif = {
        package = pkgs.noto-fonts-lgc-plus;
        name = "Noto Sans";
      };
      emoji = {
        package = pkgs.noto-fonts-color-emoji;
        name = "Noto Color Emoji";
      };
      monospace = {
        package = (pkgs.iosevka-bin.override { variant = "SGr-IosevkaTermSS10"; });
        name = "Iosevka Term SS10";
      };
    };
    polarity = "dark";
    targets.neovim.enable = false;
    targets.vscode.enable = false;
    targets.hyprlock.enable = false;
  };
}

toofewtooextra avatar Mar 01 '25 10:03 toofewtooextra

i did some searches of the codebase, and Stylix itself never seems to be directly interacting with systemd. some targets, though, use home-manager options which make systemd services. going through home-manager's implementation of each of these services, i didn't see anything out of the ordinary that should've caused this to happen.

for debugging, consider disabling stylix.autoEnable and instead enable targets you need manually. if you still have problems, note that the hyprpaper target, which i assume you want to use given that you use hyprland, utilizes a systemd service through home-manager.

i'm not yet sure what is causing your problem, but hopefully some information about enabling and disabling specific targets will shed some light.

Flameopathic avatar Mar 01 '25 20:03 Flameopathic

yes, adding targets.qt.enable = false; removes systemd doppelganger. I am not sure should I close this issue, maybe I'll go deeper in that module and find some workaround

toofewtooextra avatar Mar 01 '25 21:03 toofewtooextra

yes, adding targets.qt.enable = false; removes systemd doppelganger.

great sleuthing, that narrows it down a lot.

I am not sure should I close this issue

leave it open as this is unexpected behavior

maybe I'll go deeper in that module and find some workaround

i'll look into the Stylix module itself and try to solve the problem at its source rather than requiring people use workarounds, but it'd be great if you still took a look. if you find anything while looking into a workaround, please share it here

Flameopathic avatar Mar 01 '25 22:03 Flameopathic

@Mikilio would you give this a look? i don't see anything obvious that would be causing this problem

Flameopathic avatar Mar 01 '25 22:03 Flameopathic

turns out the main issue is about home-manager's qt kvantum, at least stylix module for qt contains it. Setting stylix.enable = false and adding this to home-manager:

  qt = {
    enable = true;
    style.name = "kvantum";
    platformTheme.name = "qtqc";
  };

makes nix systemd on path. Commenting style.name fixes it. I opened an issue in home-manager repo

toofewtooextra avatar Mar 02 '25 12:03 toofewtooextra

turns out the main issue is about home-manager's qt kvantum, at least stylix module for qt contains it.

great information. i believe that precedent here is to leave upstream issues open here, but would you rename the issue to something like "qt: puts NixOS systemd on non-NixOS distro path" for future users?

Flameopathic avatar Mar 02 '25 13:03 Flameopathic

the culprit is this: https://github.com/NixOS/nixpkgs/blob/f9387c450afd6fcd99c5ba4bc8fdd899bd2610f8/pkgs/os-specific/linux/systemd/default.nix#L780

... and I don't know yet what to do about this

@Flameopathic this is super hard to fix tbh. and it's probably not gonna happen any time soon.

Mikilio avatar Aug 04 '25 15:08 Mikilio

the culprit is this: https://github.com/NixOS/nixpkgs/blob/f9387c450afd6fcd99c5ba4bc8fdd899bd2610f8/pkgs/os-specific/linux/systemd/default.nix#L780

... and I don't know yet what to do about this

@Flameopathic this is super hard to fix tbh. and it's probably not gonna happen any time soon.

Alright. I don't know that this issue should be closed, though, as it is still absolutely an issue; we could logically close it as "Not Planned," but that goes against precedent AFAIK.

You may want to share your findings in the upstream issue.

Flameopathic avatar Aug 04 '25 15:08 Flameopathic

we could add !targets.genericLinux.enable to hm qt's autoEnable to reduce the number of people who will run into this issue.

0xda157 avatar Aug 06 '25 00:08 0xda157

we could add !targets.genericLinux.enable to hm qt's autoEnable to reduce the number of people who will run into this issue.

This option should be enabled by default and would essentially allow end-users hotfixing the upstream issue in the meantime. Should we provide this hotfix option or simply wait on upstream?

trueNAHO avatar Aug 07 '25 19:08 trueNAHO