nix: add overlay, remove flake-parts, and other changes

Most of the changes are heavily inspired by the structure of Niri's
flake.nix.
- add overlay
- add formatter for nix
- remove flake-parts
- use rust-overlay only for the dev shell. end users can set `inputs.rust-overlay.follows = ""` to skip downloading it.
- add rust-analyzer and rust-src extensions in the dev shell
- filter the source in order to reduce rebuilds
- support all Linux systems that the nixpkgs flake exposes
- override VERGEN_GIT_DESCRIBE to include the git rev as well
- remove `clangStdenv` from the dev shell.  I'm not sure what purpose it served. If the intention was faster linking with lld, then it's not needed anymore, now that lld has become the default linker in rust 1.90.0.
This commit is contained in:
stefan 2026-01-23 23:08:43 -08:00 committed by Supreeeme
parent 37ec78ee26
commit 1fa632c291
3 changed files with 136 additions and 120 deletions

221
flake.nix
View file

@ -1,106 +1,155 @@
{
description = "Xwayland outside your Wayland";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
flake-utils.url = "github:numtide/flake-utils";
# NOTE: This is not necessary for end users
# You can omit it with `inputs.rust-overlay.follows = ""`
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, rust-overlay, flake-utils }:
let systems = [ "x86_64-linux" "aarch64-linux" ];
in flake-utils.lib.eachSystem systems (system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs { inherit system overlays; };
outputs =
{
self,
nixpkgs,
rust-overlay,
}:
let
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
cargoPackageVersion = cargoToml.package.version;
commitHash = self.shortRev or self.dirtyShortRev or "unknown";
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
cargoPackageVersion = cargoToml.package.version;
xwayland-satellite-package =
{
lib,
rustPlatform,
pkg-config,
makeBinaryWrapper,
libxcb,
xcb-util-cursor,
xwayland,
withSystemd ? true,
}:
rustPlatform.buildRustPackage (finalAttrs: {
pname = "xwayland-satellite";
version = "${cargoPackageVersion}-${commitHash}";
commitHash = self.shortRev or self.dirtyShortRev or "unknown";
version = "${cargoPackageVersion}-${commitHash}";
buildXwaylandSatellite =
{ lib
, rustPlatform
, pkg-config
, makeBinaryWrapper
, libxcb
, xcb-util-cursor
, xwayland
, withSystemd ? true
}:
rustPlatform.buildRustPackage rec {
pname = "xwayland-satellite";
inherit version;
src = self;
cargoLock = {
lockFile = "${src}/Cargo.lock";
allowBuiltinFetchGit = true;
};
nativeBuildInputs = [
rustPlatform.bindgenHook
pkg-config
makeBinaryWrapper
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
./OpenSans-Regular.ttf
./build.rs
./macros
./testwl
./wl_drm
./resources
./src
./Cargo.toml
./Cargo.lock
];
buildInputs = [
libxcb
xcb-util-cursor
];
buildNoDefaultFeatures = true;
buildFeatures = lib.optionals withSystemd [ "systemd" ];
postPatch = ''
substituteInPlace resources/xwayland-satellite.service \
--replace-fail '/usr/local/bin' "$out/bin"
'';
postInstall = lib.optionalString withSystemd ''
install -Dm0644 resources/xwayland-satellite.service -t $out/lib/systemd/user
'';
postFixup = ''
wrapProgram $out/bin/xwayland-satellite \
--prefix PATH : "${lib.makeBinPath [ xwayland ]}"
'';
doCheck = false;
meta = with lib; {
description = "Xwayland outside your Wayland";
homepage = "https://github.com/Supreeeme/xwayland-satellite";
license = licenses.mpl20;
mainProgram = "xwayland-satellite";
platforms = platforms.linux;
};
};
xwayland-satellite = pkgs.callPackage buildXwaylandSatellite { };
in
{
devShell = (pkgs.mkShell.override { stdenv = pkgs.clangStdenv; }) {
buildInputs = with pkgs; [
cargoLock = {
lockFile = ./Cargo.lock;
allowBuiltinFetchGit = true;
};
nativeBuildInputs = [
rustPlatform.bindgenHook
rust-bin.stable.latest.default
pkg-config
xcb-util-cursor
xorg.libxcb
xwayland
makeBinaryWrapper
];
};
packages = {
xwayland-satellite = xwayland-satellite;
buildInputs = [
libxcb
xcb-util-cursor
];
buildNoDefaultFeatures = true;
buildFeatures = lib.optional withSystemd "systemd";
doCheck = false;
env.VERGEN_GIT_DESCRIBE = finalAttrs.version;
postInstall = ''
wrapProgram $out/bin/xwayland-satellite \
--prefix PATH : "${lib.makeBinPath [ xwayland ]}"
''
+ lib.optionalString withSystemd ''
install -Dm0644 resources/xwayland-satellite.service -t $out/lib/systemd/user
'';
postFixup = lib.optionalString withSystemd ''
substituteInPlace $out/lib/systemd/user/xwayland-satellite.service \
--replace-fail /usr/local/bin $out/bin
'';
meta = with lib; {
description = "Xwayland outside your Wayland";
homepage = "https://github.com/Supreeeme/xwayland-satellite";
license = licenses.mpl20;
mainProgram = "xwayland-satellite";
platforms = platforms.linux;
};
});
inherit (nixpkgs) lib;
# Support all Linux systems that the nixpkgs flake exposes
systems = lib.intersectLists lib.systems.flakeExposed lib.platforms.linux;
forAllSystems = lib.genAttrs systems;
nixpkgsFor = forAllSystems (system: nixpkgs.legacyPackages.${system});
in
{
devShells = forAllSystems (
system:
let
pkgs = nixpkgsFor.${system};
rust-bin = rust-overlay.lib.mkRustBin { } pkgs;
inherit (self.packages.${system}) xwayland-satellite;
in
{
default = pkgs.mkShell {
packages = [
(rust-bin.stable.latest.default.override {
extensions = [
"rust-analyzer"
"rust-src"
];
})
];
nativeBuildInputs = [
pkgs.rustPlatform.bindgenHook
pkgs.pkg-config
pkgs.makeBinaryWrapper
];
buildInputs = xwayland-satellite.buildInputs ++ [ pkgs.xwayland ];
};
}
);
formatter = forAllSystems (system: nixpkgsFor.${system}.nixfmt);
packages = forAllSystems (
system:
let
xwayland-satellite = nixpkgsFor.${system}.callPackage xwayland-satellite-package { };
in
{
inherit xwayland-satellite;
default = xwayland-satellite;
};
});
}
);
overlays.default = final: _: {
xwayland-satellite = final.callPackage xwayland-satellite-package { };
};
};
}