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

1
.gitignore vendored
View file

@ -1 +1,2 @@
/target /target
/result

34
flake.lock generated
View file

@ -1,23 +1,5 @@
{ {
"nodes": { "nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1764522689, "lastModified": 1764522689,
@ -36,7 +18,6 @@
}, },
"root": { "root": {
"inputs": { "inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay" "rust-overlay": "rust-overlay"
} }
@ -60,21 +41,6 @@
"repo": "rust-overlay", "repo": "rust-overlay",
"type": "github" "type": "github"
} }
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
} }
}, },
"root": "root", "root": "root",

153
flake.nix
View file

@ -1,46 +1,60 @@
{ {
description = "Xwayland outside your Wayland";
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11"; 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 = { rust-overlay = {
url = "github:oxalica/rust-overlay"; url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
}; };
outputs = { self, nixpkgs, rust-overlay, flake-utils }: outputs =
let systems = [ "x86_64-linux" "aarch64-linux" ]; {
in flake-utils.lib.eachSystem systems (system: self,
nixpkgs,
rust-overlay,
}:
let let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs { inherit system overlays; };
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml); cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
cargoPackageVersion = cargoToml.package.version; cargoPackageVersion = cargoToml.package.version;
commitHash = self.shortRev or self.dirtyShortRev or "unknown"; commitHash = self.shortRev or self.dirtyShortRev or "unknown";
xwayland-satellite-package =
{
lib,
rustPlatform,
pkg-config,
makeBinaryWrapper,
libxcb,
xcb-util-cursor,
xwayland,
withSystemd ? true,
}:
rustPlatform.buildRustPackage (finalAttrs: {
pname = "xwayland-satellite";
version = "${cargoPackageVersion}-${commitHash}"; version = "${cargoPackageVersion}-${commitHash}";
buildXwaylandSatellite = src = lib.fileset.toSource {
{ lib root = ./.;
, rustPlatform fileset = lib.fileset.unions [
, pkg-config ./OpenSans-Regular.ttf
, makeBinaryWrapper ./build.rs
, libxcb ./macros
, xcb-util-cursor ./testwl
, xwayland ./wl_drm
, withSystemd ? true ./resources
}: ./src
./Cargo.toml
rustPlatform.buildRustPackage rec { ./Cargo.lock
pname = "xwayland-satellite"; ];
inherit version; };
src = self;
cargoLock = { cargoLock = {
lockFile = "${src}/Cargo.lock"; lockFile = ./Cargo.lock;
allowBuiltinFetchGit = true; allowBuiltinFetchGit = true;
}; };
@ -56,24 +70,25 @@
]; ];
buildNoDefaultFeatures = true; buildNoDefaultFeatures = true;
buildFeatures = lib.optionals withSystemd [ "systemd" ]; buildFeatures = lib.optional withSystemd "systemd";
postPatch = '' doCheck = false;
substituteInPlace resources/xwayland-satellite.service \
--replace-fail '/usr/local/bin' "$out/bin"
'';
postInstall = lib.optionalString withSystemd '' 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 install -Dm0644 resources/xwayland-satellite.service -t $out/lib/systemd/user
''; '';
postFixup = '' postFixup = lib.optionalString withSystemd ''
wrapProgram $out/bin/xwayland-satellite \ substituteInPlace $out/lib/systemd/user/xwayland-satellite.service \
--prefix PATH : "${lib.makeBinPath [ xwayland ]}" --replace-fail /usr/local/bin $out/bin
''; '';
doCheck = false;
meta = with lib; { meta = with lib; {
description = "Xwayland outside your Wayland"; description = "Xwayland outside your Wayland";
homepage = "https://github.com/Supreeeme/xwayland-satellite"; homepage = "https://github.com/Supreeeme/xwayland-satellite";
@ -81,26 +96,60 @@
mainProgram = "xwayland-satellite"; mainProgram = "xwayland-satellite";
platforms = platforms.linux; platforms = platforms.linux;
}; };
}; });
xwayland-satellite = pkgs.callPackage buildXwaylandSatellite { }; 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 in
{ {
devShell = (pkgs.mkShell.override { stdenv = pkgs.clangStdenv; }) { devShells = forAllSystems (
buildInputs = with pkgs; [ system:
rustPlatform.bindgenHook let
rust-bin.stable.latest.default pkgs = nixpkgsFor.${system};
pkg-config rust-bin = rust-overlay.lib.mkRustBin { } pkgs;
inherit (self.packages.${system}) xwayland-satellite;
xcb-util-cursor in
xorg.libxcb {
xwayland default = pkgs.mkShell {
packages = [
(rust-bin.stable.latest.default.override {
extensions = [
"rust-analyzer"
"rust-src"
];
})
]; ];
};
packages = { nativeBuildInputs = [
xwayland-satellite = xwayland-satellite; pkgs.rustPlatform.bindgenHook
default = xwayland-satellite; 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 { };
};
}; };
});
} }