hyprland-wiki/pages/Nix/_index.md

293 lines
7.3 KiB
Markdown
Raw Normal View History

# Table of contents
2022-08-13 19:06:18 +02:00
{{< toc format=html >}}
2022-08-29 18:32:20 +02:00
{{< hint type=warning >}}
Hyprland is NOT supported on NixOS stable. It may (not) compile or
2022-08-13 19:06:18 +02:00
work as intended. Please use the
[flake](https://github.com/hyprwm/Hyprland/blob/main/flake.nix).
2022-08-29 18:32:20 +02:00
{{< /hint >}}
2022-08-12 20:46:36 +02:00
# Install and configure Hyprland on NixOS
2022-08-12 20:46:36 +02:00
2022-12-09 13:38:13 +01:00
First of all, it is a good idea to set up [Cachix](#cachix) before enabling
any of the modules/installing Hyprland.
2022-08-12 20:46:36 +02:00
Make sure to check out the options of the
[Nix module](https://github.com/hyprwm/Hyprland/blob/main/nix/module.nix).
Do note that the Nixpkgs Hyprland package is not actively maintained, and may be outdated.
As such, installation using the Flake is recommended.
## With flakes
2022-08-12 20:46:36 +02:00
```nix
# flake.nix
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
2022-12-09 13:38:13 +01:00
hyprland.url = "github:hyprwm/Hyprland";
2022-08-12 20:46:36 +02:00
};
2022-12-09 13:38:13 +01:00
outputs = {self, nixpkgs, hyprland, ...}: {
2022-08-12 20:46:36 +02:00
nixosConfigurations.HOSTNAME = nixpkgs.lib.nixosSystem {
# ...
modules = [
hyprland.nixosModules.default
2022-12-09 13:38:13 +01:00
{programs.hyprland.enable = true;}
2022-08-12 20:46:36 +02:00
# ...
];
};
};
```
Don't forget to replace `HOSTNAME` with your hostname!
## Without flakes
2022-08-12 20:46:36 +02:00
2022-08-13 19:06:18 +02:00
{{< hint >}}
If you're using Hyprland through an overlay, set
2022-08-12 20:46:36 +02:00
`programs.hyprland.package = pkgs.hyprland;`.
2022-08-13 19:06:18 +02:00
{{< /hint >}}
2022-08-12 20:46:36 +02:00
```nix
# configuration.nix
{config, pkgs, ...}: let
flake-compat = builtins.fetchTarball "https://github.com/edolstra/flake-compat/archive/master.tar.gz";
hyprland = (import flake-compat {
src = builtins.fetchTarball "https://github.com/hyprwm/Hyprland/archive/master.tar.gz";
}).defaultNix;
in {
imports = [
hyprland.nixosModules.default
];
2022-08-12 20:46:36 +02:00
programs.hyprland = {
enable = true;
2022-08-13 19:06:18 +02:00
package = hyprland.packages.${pkgs.system}.default;
2022-08-12 20:46:36 +02:00
};
}
```
# Install and configure through Home Manager
2022-08-12 20:46:36 +02:00
You can use the Home Manager module by adding it to your configuration:
## With flakes
2022-09-09 16:53:49 +02:00
2022-08-12 20:46:36 +02:00
```nix
2022-09-09 16:53:49 +02:00
# flake.nix
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
2022-12-09 13:38:13 +01:00
2022-09-09 16:53:49 +02:00
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
2022-12-09 13:38:13 +01:00
hyprland.url = "github:hyprwm/Hyprland";
2022-09-09 16:53:49 +02:00
};
2022-12-09 13:38:13 +01:00
outputs = {self, nixpkgs, home-manager, hyprland, ...}: {
homeConfigurations."user@hostname" = home-manager.lib.homeManagerConfiguration {
2022-09-09 16:53:49 +02:00
pkgs = nixpkgs.legacyPackages.x86_64-linux;
2022-12-09 13:38:13 +01:00
2022-09-09 16:53:49 +02:00
modules = [
hyprland.homeManagerModules.default
2022-12-09 13:38:13 +01:00
{wayland.windowManager.hyprland.enable = true;}
2022-09-09 16:53:49 +02:00
# ...
];
};
};
```
2022-12-09 13:38:13 +01:00
Don't forget to replace `user@hostname` with your username and hostname!
2022-09-09 16:53:49 +02:00
## Without flakes
2022-09-09 16:53:49 +02:00
```nix
# home config
2022-12-09 13:38:13 +01:00
{config, pkgs, inputs, ...}: let
2022-09-09 16:53:49 +02:00
flake-compat = builtins.fetchTarball "https://github.com/edolstra/flake-compat/archive/master.tar.gz";
2022-12-09 13:38:13 +01:00
2022-09-09 16:53:49 +02:00
hyprland = (import flake-compat {
src = builtins.fetchTarball "https://github.com/hyprwm/Hyprland/archive/master.tar.gz";
}).defaultNix;
in {
2022-08-12 20:46:36 +02:00
imports = [
2022-09-09 16:53:49 +02:00
hyprland.homeManagerModules.default
2022-08-12 20:46:36 +02:00
];
wayland.windowManager.hyprland.enable = true;
# ...
}
```
For a list of available options, check the
[module file](https://github.com/hyprwm/Hyprland/blob/main/nix/hm-module.nix).
# Modules mix'n'match
2022-08-12 20:46:36 +02:00
2022-12-09 13:38:13 +01:00
- If you're on NixOS and also use HM it's a good idea to use Hyprland modules
for both. Make sure the package options are the same for both modules.
2022-08-12 20:46:36 +02:00
2022-08-13 19:06:18 +02:00
- If you don't plan on using the NixOS module, but want to use the HM module, you
will have to enable all the options the NixOS module enables.
2022-08-12 20:46:36 +02:00
2022-08-13 19:06:18 +02:00
- If you don't plan on using any module, manually enable whatever options the
modules set.
2022-08-12 20:46:36 +02:00
# Non-NixOS install
2022-08-13 19:06:18 +02:00
## With flakes
2022-08-26 19:04:30 +02:00
First, [enable flakes](https://nixos.wiki/wiki/Flakes#Enable_flakes).
Once you have flakes working, install Hyprland through `nix profile`:
```sh
nix profile install github:hyprwm/Hyprland
2022-08-26 19:04:30 +02:00
```
Since you're using Hyprland outside of NixOS, it won't be able to find graphics
drivers. To get around that, you can use [nixGL](https://github.com/guibou/nixGL).
First, install it, in the same manner you installed Hyprland:
2022-08-26 19:04:30 +02:00
```sh
nix profile install github:guibou/nixGL --impure
2022-08-26 19:04:30 +02:00
```
2022-09-02 14:41:56 +02:00
Impure is needed due to `nixGL`'s reliance on hardware information.
2022-08-26 19:04:30 +02:00
From now on, you can run Hyprland by invoking it with nixGL
2022-08-26 19:04:30 +02:00
```sh
nixGL Hyprland
2022-08-26 19:04:30 +02:00
```
2022-08-26 19:04:30 +02:00
or by creating a wrapper script that runs the above command inside.
## Upgrading
2022-08-26 19:04:30 +02:00
2022-08-26 19:10:44 +02:00
In order to upgrade all your packages, you can run
2022-08-26 19:04:30 +02:00
```sh
nix profile upgrade '.*'
2022-08-26 19:04:30 +02:00
```
2022-08-26 19:04:30 +02:00
Check the
[nix profile](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-profile.html)
command documentation for other upgrade options.
2022-08-13 19:06:18 +02:00
# XWayland
2022-08-29 18:32:20 +02:00
XWayland is enabled by default in the Nix package. You can disable it either
2022-12-09 13:38:13 +01:00
in the package itself, or through the module options.
2022-08-29 18:32:20 +02:00
## Package
2022-08-29 18:32:20 +02:00
```nix
(inputs.hyprland.packages.${pkgs.default}.default.override {
enableXWayland = false;
})
```
### HM module
2022-08-29 18:32:20 +02:00
```nix
wayland.windowManager.hyprland = {
enable = true;
xwayland.enable = false;
}
```
2022-12-09 13:38:13 +01:00
### NixOS module
```nix
programs.hyprland = {
enable = true;
xwayland.enable = false;
}
```
## HiDPI
2022-08-29 18:32:20 +02:00
By default, the Nix package includes a patched wlroots that can render HiDPI
XWayland windows.
In order to enable the functionality, you have to add:
```toml
exec-once=xprop -root -f _XWAYLAND_GLOBAL_OUTPUT_SCALE 32c -set _XWAYLAND_GLOBAL_OUTPUT_SCALE 2
```
2022-12-09 13:38:13 +01:00
This will make XWayland programs look as if they were unscaled. To fix this, you
2022-08-29 18:32:20 +02:00
have to export different environment variables to make the specific toolkits
render at the proper scaling. For example
```sh
export GDK_SCALE=2
export XCURSOR_SIZE=32
```
{{< hint >}}
The GDK_SCALE variable won't conflict with wayland-native GTK programs.
{{< /hint >}}
Usually, there's no reason to disable this functionality, as it won't affect
people who don't have HiDPI screens.
If you _do_ insist on disabling it though (e.g. for adding your own patches
2022-08-29 18:32:20 +02:00
to wlroots), you can do so by either using the `hyprland-no-hidpi` package,
or by passing the `hidpiXWayland = false;` flag, the same way as
[disabling XWayland](#package)
# Cachix
2022-08-12 20:46:36 +02:00
2022-12-09 13:38:13 +01:00
Hyprland often needs dependencies which aren't yet cached in `cache.nixos.org`.
Instead of requiring you to build those dependencies (which may include `mesa`,
`ffmpeg`, etc), we provide a Cachix cache that you can add to your Nix
substituters.
2022-08-12 20:46:36 +02:00
2022-12-09 13:38:13 +01:00
The [Hyprland Cachix](https://app.cachix.org/cache/hyprland) exists to cache the
`hyprland` packages and any dependencies not found in `cache.nixos.org`.
{{< hint >}}
In order for Nix to take advantage of the cache, it has to be enabled **before**
enabling the Hyprland module(s) or adding the package.
{{< /hint >}}
{{< hint type=important >}}
Overriding Hyprland's `nixpkgs` input
(`inputs.hyprland.inputs.nixpkgs.follows = "nixpkgs";`) will make the cache
useless, since you're building from a different Nixpkgs commit.
{{< /hint >}}
2022-08-12 20:46:36 +02:00
```nix
# configuration.nix
{
nix.settings = {
substituters = ["https://hyprland.cachix.org"];
trusted-public-keys = ["hyprland.cachix.org-1:a7pgxzMz7+chwVL3/pzj6jIBMioiJM7ypFP8PwtkuGc="];
};
}
```
2022-09-02 14:41:56 +02:00
# Overrides
2022-09-02 14:41:56 +02:00
You can override the package through `.override` or `.overrideAttrs`. This is
easily achievable through NixOS or Home Manager.
If you're using Nix (and not NixOS or Home Manager) and you want to override,
you can do it like this
```sh
$ nix repl
nix-repl> :lf "github:hyprwm/Hyprland"
2022-12-09 13:38:13 +01:00
nix-repl> :bl outputs.packages.x86_64-linux.hyprland.override {nvidiaPatches = true;} # option = value
2022-09-02 14:41:56 +02:00
```
Then you can run Hyprland from the built path.