aboutsummaryrefslogtreecommitdiffhomepage
path: root/nix/module.nix
blob: a5ecee7287fd52a8fcce1d81527e7c3b91626bb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
inputs: {
  config,
  lib,
  pkgs,
  ...
}:
with lib; let
  cfg = config.programs.hyprland;

  finalPortalPackage = cfg.portalPackage.override {
    hyprland-share-picker = inputs.xdph.packages.${pkgs.system}.hyprland-share-picker.override {
      hyprland = cfg.finalPackage;
    };
  };
in {
  options.programs.hyprland = {
    enable =
      mkEnableOption null
      // {
        description = mdDoc ''
          Hyprland, the dynamic tiling Wayland compositor that doesn't sacrifice on its looks.

          You can manually launch Hyprland by executing {command}`Hyprland` on a TTY.

          A configuration file will be generated in {file}`~/.config/hypr/hyprland.conf`.
          See <https://wiki.hyprland.org> for more information.
        '';
      };

    package = mkPackageOptionMD inputs.packages.${pkgs.system} "hyprland" {};

    finalPackage = mkOption {
      type = types.package;
      readOnly = true;
      default = cfg.package.override {
        enableXWayland = cfg.xwayland.enable;
        enableNvidiaPatches = cfg.enableNvidiaPatches;
      };
      defaultText =
        literalExpression
        "`programs.hyprland.package` with applied configuration";
      description = mdDoc ''
        The Hyprland package after applying configuration.
      '';
    };

    portalPackage = mkPackageOptionMD inputs.xdph.packages.${pkgs.system} "xdg-desktop-portal-hyprland" {};

    xwayland.enable = mkEnableOption (mdDoc "support for XWayland") // {default = true;};

    enableNvidiaPatches = mkEnableOption null // {
      description = mdDoc "Whether to apply patches to wlroots for better Nvidia support.";
    };
  };

  config = mkIf cfg.enable {
    environment.systemPackages = [cfg.finalPackage];

    fonts =
      if versionOlder config.system.stateVersion "23.11"
      then {enableDefaultFonts = mkDefault true;}
      else {enableDefaultPackages = mkDefault true;};

    hardware.opengl.enable = mkDefault true;

    programs = {
      dconf.enable = mkDefault true;
      xwayland.enable = mkDefault cfg.xwayland.enable;
    };

    security.polkit.enable = true;

    services.xserver.displayManager.sessionPackages = [cfg.finalPackage];

    xdg.portal = {
      enable = mkDefault true;
      extraPortals = [finalPortalPackage];
    };
  };

  imports = with lib; [
    (
      mkRemovedOptionModule
      ["programs" "hyprland" "xwayland" "hidpi"]
      "XWayland patches are deprecated. Refer to https://wiki.hyprland.org/Configuring/XWayland"
    )
    (
      mkRenamedOptionModule
      ["programs" "hyprland" "nvidiaPatches"]
      ["programs" "hyprland" "enableNvidiaPatches"]
    )
  ];
}