Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flake: use nightly rust-analyzer and add rust-src component #735

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
276 changes: 146 additions & 130 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,130 @@
rust-overlay,
}:
let
niri-package =
{
lib,
Copy link
Contributor Author

@sodiboo sodiboo Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's easy to miss in the diff but when moving this package declaration up here, i've also separately added the lib parameter so that comes from pkgs.callPackage instead of our outermost inherit (nixpkgs) lib;. this is the only change to the package declaration; the actual contents are identical to what they previously were

cairo,
clang,
dbus,
libGL,
libclang,
libdisplay-info,
libinput,
libseat,
libxkbcommon,
mesa,
pango,
pipewire,
pkg-config,
rustPlatform,
systemd,
wayland,
withDbus ? true,
withSystemd ? true,
withScreencastSupport ? true,
withDinit ? false,
}:

rustPlatform.buildRustPackage {
pname = "niri";
version = self.shortRev or self.dirtyShortRev or "unknown";

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

postPatch = ''
patchShebangs resources/niri-session
substituteInPlace resources/niri.service \
--replace-fail '/usr/bin' "$out/bin"
'';

cargoLock = {
# NOTE: This is only used for Git dependencies
allowBuiltinFetchGit = true;
lockFile = ./Cargo.lock;
};

strictDeps = true;

nativeBuildInputs = [
clang
pkg-config
];

buildInputs =
[
cairo
dbus
libGL
libdisplay-info
libinput
libseat
libxkbcommon
mesa # libgbm
pango
wayland
]
++ lib.optional (withDbus || withScreencastSupport || withSystemd) dbus
++ lib.optional withScreencastSupport pipewire
# Also includes libudev
++ lib.optional withSystemd systemd;

buildFeatures =
lib.optional withDbus "dbus"
++ lib.optional withDinit "dinit"
++ lib.optional withScreencastSupport "xdp-gnome-screencast"
++ lib.optional withSystemd "systemd";
buildNoDefaultFeatures = true;

postInstall =
''
install -Dm644 resources/niri.desktop -t $out/share/wayland-sessions
install -Dm644 resources/niri-portals.conf -t $out/share/xdg-desktop-portal
''
+ lib.optionalString withSystemd ''
install -Dm755 resources/niri-session $out/bin/niri-session
install -Dm644 resources/niri{.service,-shutdown.target} -t $out/share/systemd/user
'';

env = {
LIBCLANG_PATH = lib.getLib libclang + "/lib";

# Force linking with libEGL and libwayland-client
# so they can be discovered by `dlopen()`
CARGO_BUILD_RUSTFLAGS = toString (
map (arg: "-C link-arg=" + arg) [
"-Wl,--push-state,--no-as-needed"
"-lEGL"
"-lwayland-client"
"-Wl,--pop-state"
]
);
};

passthru = {
providedSessions = [ "niri" ];
};

meta = {
description = "Scrollable-tiling Wayland compositor";
homepage = "https://github.com/YaLTeR/niri";
license = lib.licenses.gpl3Only;
mainProgram = "niri";
platforms = lib.platforms.linux;
};
};

inherit (nixpkgs) lib;
# Support all Linux systems that the nixpkgs flake exposes
systems = lib.intersectLists lib.systems.flakeExposed lib.platforms.linux;
Expand All @@ -39,17 +163,31 @@
system:
let
pkgs = nixpkgsFor.${system};
rust-bin = rust-overlay.lib.mkRustBin { } pkgs;
inherit (self.packages.${system}) niri;
in
{
default = pkgs.mkShell {
packages = [
# NOTE: Nixpkgs' Rust toolchain isn't used here as we prefer
# a nightly toolchain for development, and *require* a nightly
# `rustfmt`
rust-overlay.packages.${system}.rust-nightly

pkgs.rust-analyzer
# We don't use the toolchain from nixpkgs
# because we prefer a nightly toolchain
# and we *require* a nightly rustfmt
(rust-bin.selectLatestNightlyWith (
toolchain:
toolchain.default.override {
extensions = [
# includes already:
# rustc
# cargo
# rust-std
# rust-docs
# rustfmt-preview
# clippy-preview
"rust-analyzer"
"rust-src"
];
}
))
];

nativeBuildInputs = [
Expand Down Expand Up @@ -81,7 +219,7 @@
packages = forAllSystems (
system:
let
inherit (self.overlays.default nixpkgsFor.${system} null) niri;
niri = nixpkgsFor.${system}.callPackage niri-package { };
in
{
inherit niri;
Expand All @@ -107,129 +245,7 @@
);

overlays.default = final: _: {
niri = final.callPackage (
{
cairo,
clang,
dbus,
libGL,
libclang,
libdisplay-info,
libinput,
libseat,
libxkbcommon,
mesa,
pango,
pipewire,
pkg-config,
rustPlatform,
systemd,
wayland,
withDbus ? true,
withSystemd ? true,
withScreencastSupport ? true,
withDinit ? false,
}:

rustPlatform.buildRustPackage {
pname = "niri";
version = self.shortRev or self.dirtyShortRev or "unknown";

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

postPatch = ''
patchShebangs resources/niri-session
substituteInPlace resources/niri.service \
--replace-fail '/usr/bin' "$out/bin"
'';

cargoLock = {
# NOTE: This is only used for Git dependencies
allowBuiltinFetchGit = true;
lockFile = ./Cargo.lock;
};

strictDeps = true;

nativeBuildInputs = [
clang
pkg-config
];

buildInputs =
[
cairo
dbus
libGL
libdisplay-info
libinput
libseat
libxkbcommon
mesa # libgbm
pango
wayland
]
++ lib.optional (withDbus || withScreencastSupport || withSystemd) dbus
++ lib.optional withScreencastSupport pipewire
# Also includes libudev
++ lib.optional withSystemd systemd;

buildFeatures =
lib.optional withDbus "dbus"
++ lib.optional withDinit "dinit"
++ lib.optional withScreencastSupport "xdp-gnome-screencast"
++ lib.optional withSystemd "systemd";
buildNoDefaultFeatures = true;

postInstall =
''
install -Dm644 resources/niri.desktop -t $out/share/wayland-sessions
install -Dm644 resources/niri-portals.conf -t $out/share/xdg-desktop-portal
''
+ lib.optionalString withSystemd ''
install -Dm755 resources/niri-session $out/bin/niri-session
install -Dm644 resources/niri{.service,-shutdown.target} -t $out/share/systemd/user
'';

env = {
LIBCLANG_PATH = lib.getLib libclang + "/lib";

# Force linking with libEGL and libwayland-client
# so they can be discovered by `dlopen()`
CARGO_BUILD_RUSTFLAGS = toString (
map (arg: "-C link-arg=" + arg) [
"-Wl,--push-state,--no-as-needed"
"-lEGL"
"-lwayland-client"
"-Wl,--pop-state"
]
);
};

passthru = {
providedSessions = [ "niri" ];
};

meta = {
description = "Scrollable-tiling Wayland compositor";
homepage = "https://github.com/YaLTeR/niri";
license = lib.licenses.gpl3Only;
mainProgram = "niri";
platforms = lib.platforms.linux;
};
}
) { };
niri = final.callPackage niri-package { };
};
};
}