build(nix): one root flake for Windows, KDE Plasma and macOS

One flake.nix and one flake.lock replace the root flake that re-exported two nested flakes.
The inputs are one nixpkgs (the revision the KDE flake was locked to, f05535a0: the VM suites
run against its Plasma and KWin 6.8.2), one crane, rust-overlay (19ecdd08, rustc 1.99.1),
flake-parts, treefmt-nix and git-hooks-nix, all the KDE flake revisions, plus asc. A second
nixpkgs, nixpkgs-x86_64-darwin (16c7794d, the macOS flake pin), serves the x86_64-darwin
outputs only: evaluating that system with the unified pin throws (nixpkgs 26.11 dropped it).

Layout: nix/common.nix (systems, pkgs, treefmt, pre-commit, dev shells default and native,
default overlay), nix/lib.nix, nix/workspace-src.nix (one source per platform from the one Cargo
workspace: the platform members, its files of the shared crates told apart by name, the data
files, and stubs for the other members, which cargo needs), nix/{windows,linux,macos}/
{build,flake-module}.nix. The dependency derivations use a manifests-only dummy source, a plain
path, so crane reads nothing built at evaluation and the Darwin outputs evaluate on Linux.

Names: unprefixed outputs are the native build (Linux: KDE; Darwin: macOS); Windows cross
outputs are windows-*; checks are windows-*, linux-*, macos-* and vm-NAME; table in docs/dev/flake.md
(next revision). One deny.toml, one format-all and one version (workspace) are used by all.
PLACEHOLDER for the agent that owns the check sets: the checks that evaluate a NixOS system
or a VM (vm-*, linux-nixos-module-eval, linux-plasma-guests-eval, linux-run-kde*) are
legacyPackages.<system>.heavyChecks.<name>, not checks, because evaluating them needs more
memory than nix flake check --all-systems can use. The Plasma guests got a stub root file system
and boot loader (mkDefault, replaced by their vmVariant) so that nix flake check can evaluate
their toplevel.

Verified: nix flake check --no-build --all-systems passes (42 s, rc 0); nix flake check
--no-build passes. Not verified: any build (next revisions record them).
This commit is contained in:
LGUG2Z committed 2026-11-05 15:03:27 -08:00
1 parent 05698a34ba
commit ae9ee327f9
11 files changed
+1821 -1084

No files matched your search

+114
View File
@@ -0,0 +1,114 @@
# The crane derivations of the macOS packages, from the macOS members of the one Cargo workspace
# (nix/workspace-src.nix).
{ inputs, self }:
let
lib' = import ../lib.nix { inherit inputs; };
inherit (lib') version;
inherit (inputs) crane;
in
{
mkKomorebiPackages =
{ pkgs }:
let
toolchain = pkgs.rust-bin.fromRustupToolchainFile ../../rust-toolchain.toml;
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
inherit
(import ../workspace-src.nix {
inherit pkgs craneLib;
repoRoot = ../..;
platform = "macos";
})
real
src
stubbedPackages
;
lockFile = lib'.repoFile "Cargo.lock";
tomlFile = lib'.repoFile "Cargo.toml";
packages = "-p komorebi -p komorebi-macos -p komorebic -p komorebi-client -p komorebi-bar";
workspaceArgs = {
pname = "komorebi-workspace-macos";
inherit version;
# the lock and the root manifest as files of their own: a path inside the filtered source
# would put all of it into the context of every derivation, and an edit of any file
# would then change the dependencies
cargoLock = lockFile;
cargoToml = tomlFile;
cargoVendorDir = craneLib.vendorCargoDeps { cargoLock = lockFile; };
};
commonArgs = workspaceArgs // {
cargoExtraArgs = "--locked ${packages}";
inherit src;
strictDeps = true;
# a constant, so that the dependencies and every check are the same derivations for
# every commit; only fullBuild stamps the real one
COMMIT_HASH = "nix-check";
nativeBuildInputs = [
pkgs.darwin.cctools
];
postFixup = ''
for bin in $out/bin/*; do
if [ -f "$bin" ] && [ -x "$bin" ]; then
# Get all linked libraries and fix libiconv references
otool -L "$bin" | grep -o '/nix/store/[^/]*/lib/libiconv[^ ]*' | while read -r lib; do
install_name_tool -change "$lib" /usr/lib/libiconv.dylib "$bin"
done
fi
done
'';
};
# the dummy source is of the manifests alone (nix/lib.nix): the dependencies are the same
# derivations for every source file and every stub, and nothing is built at evaluation
cargoArtifacts = craneLib.buildDepsOnly (
builtins.removeAttrs commonArgs [ "src" ]
// {
dummySrc = craneLib.mkDummySrc {
src = lib'.manifestSource pkgs.lib;
cargoLock = lockFile;
};
}
);
individualCrateArgs = commonArgs // {
inherit cargoArtifacts;
doCheck = false;
doDoc = false;
};
fullBuild = craneLib.buildPackage (
individualCrateArgs
// {
COMMIT_HASH = self.rev or (pkgs.lib.removeSuffix "-dirty" (self.dirtyRev or "unknown"));
}
);
extractBinary =
binaryName:
pkgs.runCommand "komorebi-${binaryName}"
{
meta = fullBuild.meta // { };
}
''
mkdir -p $out/bin
cp ${fullBuild}/bin/${binaryName} $out/bin/
'';
in
{
inherit
craneLib
src
real
workspaceArgs
stubbedPackages
packages
individualCrateArgs
fullBuild
;
komorebi = extractBinary "komorebi";
komorebic = extractBinary "komorebic";
komorebi-bar = extractBinary "komorebi-bar";
};
}
+108
View File
@@ -0,0 +1,108 @@
# komorebi for macOS: the native packages on Apple machines, the `macos-*` checks and the
# nix-darwin module. The Rust packages cannot be built on Linux; `nix flake check --no-build
# --all-systems` evaluates them there.
{
inputs,
self,
lib,
...
}:
let
lib' = import ../lib.nix { inherit inputs; };
macos = import ./build.nix { inherit inputs self; };
inherit (lib') mkPkgs;
in
{
perSystem =
{ pkgs, system, ... }:
let
build = macos.mkKomorebiPackages { inherit pkgs; };
# rustfmt.toml uses options only a nightly rustfmt knows
nightlyRustfmt = pkgs.rust-bin.nightly.latest.rustfmt;
in
lib.optionalAttrs (builtins.elem system lib'.macosSystems) {
checks = {
macos-clippy = build.craneLib.cargoClippy build.individualCrateArgs;
# the nightly rustfmt over the macOS files only (the source of this platform has no others), with
# the 2024 edition of the manifests. `cargo fmt` would follow the `mod windows;` of the shared
# entry files (komorebi-bar, komorebi-client), which the macOS source does not have.
macos-fmt =
pkgs.runCommand "komorebi-macos-fmt"
{
nativeBuildInputs = [ nightlyRustfmt ];
}
''
RUSTFMT=rustfmt bash ${lib'.repoFile "tools/format-all"} --check --root ${build.real}
touch $out
'';
macos-toml-fmt = build.craneLib.taploFmt (
build.workspaceArgs
// {
src = lib.sources.sourceFilesBySuffices build.real [ ".toml" ];
}
);
# cargo deny sees every member of the workspace: leave out the other platforms' packages (stubs
# here); the policy is the one deny.toml of the repository
macos-deny = build.craneLib.cargoDeny (
build.workspaceArgs
// {
inherit (build) src;
cargoDenyExtraArgs =
"--workspace " + lib.concatMapStringsSep " " (p: "--exclude ${p}") build.stubbedPackages;
cargoDenyChecks = "bans licenses sources";
}
);
macos-nextest = build.craneLib.cargoNextest build.individualCrateArgs;
macos-nix-options-validation = import ./tests { inherit pkgs; };
macos-darwin-module-validation = import ./tests/darwin-module.nix { inherit pkgs; };
};
packages = {
inherit (build) komorebi komorebic komorebi-bar;
komorebi-full = build.fullBuild;
default = build.fullBuild;
};
apps = {
komorebi = {
type = "app";
program = "${build.komorebi}/bin/komorebi";
};
komorebic = {
type = "app";
program = "${build.komorebic}/bin/komorebic";
};
komorebi-bar = {
type = "app";
program = "${build.komorebi-bar}/bin/komorebi-bar";
};
default = {
type = "app";
program = "${build.fullBuild}/bin/komorebi";
};
};
};
flake = {
overlays.macos =
final: _:
let
build = macos.mkKomorebiPackages { pkgs = mkPkgs final.stdenv.hostPlatform.system; };
in
{
inherit (build) komorebi komorebic komorebi-bar;
komorebi-full = build.fullBuild;
};
darwinModules.default = import ./darwin-module.nix;
darwinModules.komorebi = import ./darwin-module.nix;
# the name of the root flake before the nested flakes were merged into it
darwinModules.komorebi-for-mac = import ./darwin-module.nix;
};
}