Files
komorebi/flake.nix
T
LGUG2Z db8cf858ff build(nix): pull git rev info from flake inputs
This commit adds a new workspace crate, version, which is consumed by
komorebi and komorebic.

If either of those binaries are being built by
the Nix Flake, the git rev info will be pulled from inputs.self.rev
instead of querying the git repo, because the git files are not passed
to the derivation.

The build.rs for the version crate decides if the build is happening by
querying the shadow-rs build output for BRANCH, which will always be
empty when a "nix build" is running.

Cargo builds will use the standard git information retrieval mechanisms
in shadow-rs.

The information in both cases is exposed as version::LONG_VERSION, and
passed to clap as the string to return when either binary is called with
the --version flag.
2025-11-06 16:57:17 -08:00

186 lines
4.2 KiB
Nix

{
description = "Build komorebi workspace";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
crane.url = "github:ipetkov/crane";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay.url = "github:oxalica/rust-overlay";
};
outputs = {
self,
nixpkgs,
crane,
flake-utils,
rust-overlay,
...
}: let
komorebiBuild = system: let
overlays = [(import rust-overlay)];
pkgs = import nixpkgs {
inherit system overlays;
};
inherit (pkgs) lib;
toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
version = "0.1.0";
src = lib.cleanSourceWith {
src = ./.;
filter = path: type:
(craneLib.filterCargoSources path type)
|| (lib.hasInfix "/docs/" path)
|| (builtins.match ".*/docs/.*" path != null);
};
commonArgs = {
inherit src version;
strictDeps = true;
COMMIT_HASH = self.rev or (lib.removeSuffix "-dirty" self.dirtyRev);
buildInputs = [
pkgs.gcc
pkgs.libiconv
];
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
individualCrateArgs =
commonArgs
// {
inherit cargoArtifacts;
doCheck = false;
doDoc = false;
};
packages = let
fullBuild = craneLib.buildPackage (
individualCrateArgs
// {
pname = "komorebi-workspace";
}
);
extractBinary = binaryName:
pkgs.runCommand "komorebi-${binaryName}"
{
meta = fullBuild.meta // {};
}
''
mkdir -p $out/bin
cp ${fullBuild}/bin/${binaryName} $out/bin/
'';
in {
komorebi-full = fullBuild;
komorebi = extractBinary "komorebi";
komorebic = extractBinary "komorebic";
komorebi-bar = extractBinary "komorebi-bar";
};
in
packages
// {
inherit
pkgs
craneLib
commonArgs
cargoArtifacts
individualCrateArgs
src
;
};
in
flake-utils.lib.eachSystem ["aarch64-darwin"] (
system: let
buildResult = komorebiBuild system;
inherit
(buildResult)
individualCrateArgs
komorebi
komorebic
komorebi-bar
komorebi-full
pkgs
craneLib
src
;
in {
checks = {
komorebi-workspace-clippy = craneLib.cargoClippy individualCrateArgs;
komorebi-workspace-fmt = craneLib.cargoFmt {
inherit src;
};
komorebi-workspace-toml-fmt = craneLib.taploFmt {
src = pkgs.lib.sources.sourceFilesBySuffices src [".toml"];
};
komorebi-workspace-deny = craneLib.cargoDeny {
inherit src;
};
komorebi-workspace-nextest = craneLib.cargoNextest individualCrateArgs;
};
packages = {
inherit
komorebi
komorebic
komorebi-bar
komorebi-full
;
default = komorebi-full;
};
apps = {
komorebi = flake-utils.lib.mkApp {
drv = komorebi;
};
komorebic = flake-utils.lib.mkApp {
drv = komorebic;
};
komorebi-bar = flake-utils.lib.mkApp {
drv = komorebi-bar;
};
default = flake-utils.lib.mkApp {
drv = komorebi-full;
};
};
devShells.default = import ./shell.nix {
inherit pkgs;
};
}
)
// {
overlays.default = final: _: let
buildResult = komorebiBuild final.system;
in {
inherit
(buildResult)
komorebi
komorebic
komorebi-bar
komorebi-full
;
};
overlays.komorebi = final: _: let
buildResult = komorebiBuild final.system;
in {
inherit
(buildResult)
komorebi
komorebic
komorebi-bar
komorebi-full
;
};
};
}