Skip to content

Commit

Permalink
Add Nix Flake (#77)
Browse files Browse the repository at this point in the history
* Add Nix Flake

Co-authored-by: Bryce Berger <[email protected]>

* Describe nix flake in readme

* Add `niri-config` to build source list

* Add maintainer info

Add comment at top to indicate the Nix Flake file
is community maintained.

* Clarify Nix/NixOS README instructions

* Shorten Nix/NixOS build instructions

Co-authored-by: Ivan Molodetskikh <[email protected]>

* Move NixOS installation instruction to "Tip" section

---------

Co-authored-by: Bryce Berger <[email protected]>
Co-authored-by: Ivan Molodetskikh <[email protected]>
  • Loading branch information
3 people authored Jan 11, 2024
1 parent b2df3e1 commit 236abd9
Show file tree
Hide file tree
Showing 4 changed files with 254 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
/result
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ When a monitor disconnects, its workspaces will move to another monitor, but upo
> [!TIP]
> For Fedora users, there's a COPR with built and packaged niri: https://copr.fedorainfracloud.org/coprs/yalter/niri/
>
> NixOS users, check out https://github.com/sodiboo/niri-flake
> For NixOS users, check out https://github.com/sodiboo/niri-flake
First, install the dependencies for your distribution.

Expand All @@ -57,6 +57,16 @@ First, install the dependencies for your distribution.

Next, build niri with `cargo build --release`.

### NixOS/Nix

We have a community-maintained flake which provides a devshell with required dependencies. Use `nix build` to build niri, and then run `./results/bin/niri`.

If you're not on NixOS, you may need [NixGL](https://github.com/nix-community/nixGL) to run the resulting binary:
```
nix run --impure github:guibou/nixGL -- ./results/bin/niri
```
## Installation
The recommended way to install and run niri is as a standalone desktop session.
Expand Down
138 changes: 138 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

104 changes: 104 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# This flake file is community maintained
# Maintainers:
# Bill Sun (github/billksun)
{
description = "Niri: A scrollable-tiling Wayland compositor.";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils.url = "github:numtide/flake-utils";
nix-filter.url = "github:numtide/nix-filter";
fenix = {
url = "github:nix-community/fenix/monthly";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = {
self,
nixpkgs,
crane,
nix-filter,
flake-utils,
fenix,
...
}: let
systems = ["aarch64-linux" "x86_64-linux"];
in
flake-utils.lib.eachSystem systems (
system: let
pkgs = nixpkgs.legacyPackages.${system};
toolchain = fenix.packages.${system}.complete.toolchain;
craneLib = crane.lib.${system}.overrideToolchain toolchain;

craneArgs = {
pname = "niri";
version = self.rev or "dirty";

src = nix-filter.lib.filter {
root = ./.;
include = [
./src
./niri-config
./Cargo.toml
./Cargo.lock
./resources
];
};

nativeBuildInputs = with pkgs; [
pkg-config
autoPatchelfHook
clang
];

buildInputs = with pkgs; [
wayland
systemd # For libudev
seatd # For libseat
libxkbcommon
libinput
mesa # For libgbm
fontconfig
stdenv.cc.cc.lib
pipewire
];

runtimeDependencies = with pkgs; [
wayland
mesa
libglvnd # For libEGL
];

LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
};

cargoArtifacts = craneLib.buildDepsOnly craneArgs;
niri = craneLib.buildPackage (craneArgs // {inherit cargoArtifacts;});
in {
formatter = pkgs.alejandra;

checks.niri = niri;
packages.default = niri;

devShells.default = pkgs.mkShell.override {stdenv = pkgs.clangStdenv;} {
inherit (niri) nativeBuildInputs buildInputs LIBCLANG_PATH;
packages = niri.runtimeDependencies;

# Force linking to libEGL, which is always dlopen()ed, and to
# libwayland-client, which is always dlopen()ed except by the
# obscure winit backend.
RUSTFLAGS = map (a: "-C link-arg=${a}") [
"-Wl,--push-state,--no-as-needed"
"-lEGL"
"-lwayland-client"
"-Wl,--pop-state"
];
};
}
);
}

0 comments on commit 236abd9

Please sign in to comment.