mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-18 22:58:34 +01:00
build(nix): schemars-docgen is built and checked by the flake, and in the dev shell
nix/docgen is nix/nixgen for the other tool: its own platform in workspace-src.nix (a stub in every other platform, the templates it embeds kept), docgen-lint and docgen-test in the default check sets, and the package in the dev shell, where `just docgen` runs it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
14c9b615c7
commit
3396a7f1ed
7 files changed
+138
-144
No files matched your search
@@ -36,6 +36,7 @@
|
||||
./nix/macos/flake-module.nix
|
||||
./nix/recorder/flake-module.nix
|
||||
./nix/nixgen/flake-module.nix
|
||||
./nix/docgen/flake-module.nix
|
||||
];
|
||||
};
|
||||
}
|
||||
@@ -61,6 +61,8 @@ let
|
||||
];
|
||||
nixgen-lint = [ "nixgen-clippy" ];
|
||||
nixgen-test = [ "nixgen-nextest" ];
|
||||
docgen-lint = [ "docgen-clippy" ];
|
||||
docgen-test = [ "docgen-nextest" ];
|
||||
recorder-lint = [ "recorder-clippy" ];
|
||||
recorder-test = [ "recorder-nextest" ];
|
||||
macos-lint = [ "macos-clippy" ];
|
||||
@@ -106,6 +108,8 @@ let
|
||||
"recorder-test"
|
||||
"nixgen-lint"
|
||||
"nixgen-test"
|
||||
"docgen-lint"
|
||||
"docgen-test"
|
||||
];
|
||||
in
|
||||
{
|
||||
|
||||
@@ -90,6 +90,8 @@ in
|
||||
pkgs.cargo-outdated
|
||||
# writes the Nix options of the modules from the schemas (`just nixgen-linux`, `just nixgen-macos`)
|
||||
config.packages.schemars-nixgen
|
||||
# writes the reference pages of the docs site from the schemas (`just docgen`)
|
||||
config.packages.schemars-docgen
|
||||
# `komorebi-recorder frames` and `selftest` extract frames with ffmpeg; it is never used for
|
||||
# capture and is not bundled into the packaged binary
|
||||
pkgs.ffmpeg-headless
|
||||
|
||||
+67
-136
@@ -1,143 +1,74 @@
|
||||
# The crane derivations of schemars-docgen, the tool that writes the reference pages of the docs site
|
||||
# (starlight/) from the JSON Schemas, from the one Cargo workspace (nix/workspace-src.nix, platform "docgen": the tool and nothing
|
||||
# else). It is pure Rust, so one build serves every system.
|
||||
{ inputs }:
|
||||
let
|
||||
lib' = import ../lib.nix { inherit inputs; };
|
||||
inherit (inputs) crane;
|
||||
version =
|
||||
(builtins.fromTOML (builtins.readFile ../../crates/schemars-docgen/Cargo.toml)).package.version;
|
||||
in
|
||||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||
flake-parts.url = "github:hercules-ci/flake-parts";
|
||||
crane.url = "github:ipetkov/crane";
|
||||
rust-overlay.url = "github:oxalica/rust-overlay";
|
||||
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
|
||||
treefmt-nix.url = "github:numtide/treefmt-nix";
|
||||
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
|
||||
git-hooks-nix.url = "github:cachix/git-hooks.nix";
|
||||
git-hooks-nix.inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
mkDocgenPackages =
|
||||
{ pkgs }:
|
||||
let
|
||||
toolchain = pkgs.rust-bin.fromRustupToolchainFile ../../rust-toolchain.toml;
|
||||
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
|
||||
|
||||
outputs =
|
||||
inputs@{
|
||||
nixpkgs,
|
||||
flake-parts,
|
||||
crane,
|
||||
rust-overlay,
|
||||
...
|
||||
}:
|
||||
flake-parts.lib.mkFlake { inherit inputs; } {
|
||||
imports = [
|
||||
inputs.treefmt-nix.flakeModule
|
||||
inputs.git-hooks-nix.flakeModule
|
||||
];
|
||||
inherit
|
||||
(import ../workspace-src.nix {
|
||||
inherit pkgs craneLib;
|
||||
repoRoot = ../..;
|
||||
platform = "docgen";
|
||||
})
|
||||
src
|
||||
;
|
||||
|
||||
systems = [
|
||||
"x86_64-linux"
|
||||
"aarch64-linux"
|
||||
"aarch64-darwin"
|
||||
];
|
||||
lockFile = lib'.repoFile "Cargo.lock";
|
||||
tomlFile = lib'.repoFile "Cargo.toml";
|
||||
|
||||
perSystem =
|
||||
{
|
||||
config,
|
||||
system,
|
||||
...
|
||||
}:
|
||||
let
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
overlays = [ rust-overlay.overlays.default ];
|
||||
};
|
||||
|
||||
rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
|
||||
nightlyRustfmt = pkgs.rust-bin.nightly.latest.rustfmt;
|
||||
rustToolchainWithNightlyRustfmt = pkgs.symlinkJoin {
|
||||
name = "rust-toolchain-with-nightly-rustfmt";
|
||||
paths = [
|
||||
nightlyRustfmt
|
||||
rustToolchain
|
||||
];
|
||||
};
|
||||
|
||||
nightlyToolchain = pkgs.rust-bin.nightly.latest.default;
|
||||
cargo-udeps = pkgs.writeShellScriptBin "cargo-udeps" ''
|
||||
export PATH="${nightlyToolchain}/bin:$PATH"
|
||||
exec ${pkgs.cargo-udeps}/bin/cargo-udeps "$@"
|
||||
'';
|
||||
|
||||
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
|
||||
|
||||
src = pkgs.lib.cleanSourceWith {
|
||||
src = ./.;
|
||||
filter =
|
||||
path: type:
|
||||
(craneLib.filterCargoSources path type)
|
||||
|| (builtins.match ".*\\.css$" path != null)
|
||||
|| (builtins.match ".*\\.html$" path != null)
|
||||
|| (builtins.match ".*\\.md$" path != null)
|
||||
|| (builtins.match ".*\\.json$" path != null);
|
||||
};
|
||||
|
||||
commonArgs = {
|
||||
inherit src;
|
||||
strictDeps = true;
|
||||
};
|
||||
|
||||
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
|
||||
|
||||
schemars-docgen = craneLib.buildPackage (
|
||||
commonArgs
|
||||
// {
|
||||
inherit cargoArtifacts;
|
||||
}
|
||||
);
|
||||
in
|
||||
{
|
||||
checks = {
|
||||
clippy = craneLib.cargoClippy (
|
||||
commonArgs
|
||||
// {
|
||||
inherit cargoArtifacts;
|
||||
}
|
||||
);
|
||||
tests = craneLib.cargoTest (
|
||||
commonArgs
|
||||
// {
|
||||
inherit cargoArtifacts;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
packages = {
|
||||
inherit schemars-docgen;
|
||||
default = schemars-docgen;
|
||||
};
|
||||
|
||||
devShells.default = pkgs.mkShell {
|
||||
inputsFrom = [ schemars-docgen ];
|
||||
packages = [
|
||||
rustToolchainWithNightlyRustfmt
|
||||
cargo-udeps
|
||||
pkgs.cargo-outdated
|
||||
pkgs.bacon
|
||||
];
|
||||
};
|
||||
|
||||
pre-commit = {
|
||||
check.enable = true;
|
||||
settings.hooks.treefmt = {
|
||||
enable = true;
|
||||
package = config.treefmt.build.wrapper;
|
||||
pass_filenames = false;
|
||||
};
|
||||
};
|
||||
|
||||
treefmt = {
|
||||
projectRootFile = "flake.nix";
|
||||
programs = {
|
||||
rustfmt = {
|
||||
enable = true;
|
||||
package = nightlyRustfmt;
|
||||
};
|
||||
taplo.enable = true;
|
||||
nixfmt.enable = true;
|
||||
deadnix.enable = true;
|
||||
};
|
||||
};
|
||||
commonArgs = {
|
||||
pname = "schemars-docgen";
|
||||
inherit version src;
|
||||
cargoExtraArgs = "--locked -p schemars-docgen";
|
||||
# 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;
|
||||
inherit (lib') cargoLockParsed;
|
||||
};
|
||||
strictDeps = true;
|
||||
};
|
||||
|
||||
# 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;
|
||||
};
|
||||
|
||||
schemars-docgen = craneLib.buildPackage individualCrateArgs;
|
||||
in
|
||||
{
|
||||
inherit
|
||||
craneLib
|
||||
src
|
||||
individualCrateArgs
|
||||
schemars-docgen
|
||||
;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
# schemars-docgen: the package of the tool that writes the reference pages of the docs site (`just docgen`),
|
||||
# and its checks. It is a development tool: nothing of a release has it.
|
||||
{
|
||||
inputs,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
let
|
||||
lib' = import ../lib.nix { inherit inputs; };
|
||||
docgen = import ./build.nix { inherit inputs; };
|
||||
in
|
||||
{
|
||||
perSystem =
|
||||
{ pkgs, system, ... }:
|
||||
let
|
||||
build = docgen.mkDocgenPackages { inherit pkgs; };
|
||||
in
|
||||
lib.optionalAttrs (builtins.elem system (lib'.macosSystems ++ lib'.linuxSystems)) {
|
||||
allChecks = {
|
||||
# the format, the TOML and the licenses of the tool are checked with those of the rest of
|
||||
# the workspace (`windows-fmt`, `windows-toml-fmt`, `cargo deny` over the workspace)
|
||||
docgen-clippy = build.craneLib.cargoClippy (
|
||||
build.individualCrateArgs
|
||||
// {
|
||||
cargoClippyExtraArgs = "--all-targets -- -D warnings";
|
||||
}
|
||||
);
|
||||
|
||||
docgen-nextest = build.craneLib.cargoNextest (build.individualCrateArgs // { doCheck = true; });
|
||||
};
|
||||
|
||||
packages = {
|
||||
inherit (build) schemars-docgen;
|
||||
};
|
||||
|
||||
apps.schemars-docgen = {
|
||||
type = "app";
|
||||
program = "${build.schemars-docgen}/bin/schemars-docgen";
|
||||
};
|
||||
};
|
||||
}
|
||||
+22
-8
@@ -1,6 +1,6 @@
|
||||
# The source of a build of one platform, cut from the one Cargo workspace of this repository.
|
||||
#
|
||||
# import ./workspace-src.nix { pkgs; craneLib; repoRoot; platform = "windows" | "linux" | "macos" | "recorder" | "nixgen"; }
|
||||
# import ./workspace-src.nix { pkgs; craneLib; repoRoot; platform = "windows" | "linux" | "macos" | "recorder" | "nixgen" | "docgen"; }
|
||||
#
|
||||
# Cargo has to load every member of the workspace (the root manifest lists the members of all three
|
||||
# platforms), but a build of one platform needs the sources of that platform's crates only. The result:
|
||||
@@ -17,8 +17,9 @@
|
||||
# indexes the log statements of the daemons of all three platforms (komorebi-recorder/build.rs), so it
|
||||
# has their sources, whole, and nothing else; the Windows build has the recorder as one of its members.
|
||||
#
|
||||
# The platform "nixgen" is the source of schemars-nixgen's own builds: the tool and nothing else. It is a
|
||||
# stub in every other platform, so that an edit of it changes none of their derivations.
|
||||
# The platforms "nixgen" and "docgen" are the sources of schemars-nixgen's and schemars-docgen's own builds:
|
||||
# the tool and nothing else. Each is a stub in every other platform, so that an edit of it changes none of
|
||||
# their derivations.
|
||||
#
|
||||
# An edit under one platform therefore changes nothing in the derivations of the others, except where
|
||||
# the edit is in a crate they share or in the root manifest, lock or toolchain files.
|
||||
@@ -61,8 +62,12 @@ let
|
||||
"komorebi-shortcuts"
|
||||
];
|
||||
|
||||
# the development tool that writes the Nix options: built by its own checks (nix/nixgen)
|
||||
toolOnly = [ "crates/schemars-nixgen" ];
|
||||
# the development tools: schemars-nixgen writes the Nix options (nix/nixgen) and schemars-docgen the
|
||||
# reference pages of the docs site (nix/docgen); each is built by its own checks
|
||||
toolOnly = [
|
||||
"crates/schemars-nixgen"
|
||||
"crates/schemars-docgen"
|
||||
];
|
||||
|
||||
# the recorder and the crates whose source its build script indexes (komorebi-recorder/build.rs)
|
||||
recorderMembers = [
|
||||
@@ -78,7 +83,8 @@ let
|
||||
|
||||
membersOf = {
|
||||
recorder = recorderMembers;
|
||||
nixgen = toolOnly;
|
||||
nixgen = [ "crates/schemars-nixgen" ];
|
||||
docgen = [ "crates/schemars-docgen" ];
|
||||
# everything but the other two platforms' crates and the tool
|
||||
windows = builtins.filter (m: !(builtins.elem m (linuxOnly ++ macosOnly ++ toolOnly))) allMembers;
|
||||
linux = linuxOnly ++ linuxShared ++ linuxNeutralTests;
|
||||
@@ -109,7 +115,13 @@ let
|
||||
};
|
||||
# the recorder indexes every platform's files
|
||||
otherMarkers =
|
||||
if platform == "recorder" || platform == "nixgen" then
|
||||
if
|
||||
builtins.elem platform [
|
||||
"recorder"
|
||||
"nixgen"
|
||||
"docgen"
|
||||
]
|
||||
then
|
||||
[ ]
|
||||
else
|
||||
builtins.attrValues (removeAttrs markers [ platform ]);
|
||||
@@ -128,7 +140,7 @@ let
|
||||
members
|
||||
++ lib.optional (platform == "windows") "wix"
|
||||
++ (
|
||||
if platform == "nixgen" then
|
||||
if platform == "nixgen" || platform == "docgen" then
|
||||
[ ".cargo" ]
|
||||
else if platform == "recorder" then
|
||||
[
|
||||
@@ -196,6 +208,8 @@ let
|
||||
# the guide and the icon the recorder embeds, and the installer
|
||||
recorder = lib.hasPrefix "komorebi-recorder/" rel || lib.hasPrefix "wix/" rel;
|
||||
nixgen = false;
|
||||
# the templates the tool embeds (include_str!)
|
||||
docgen = lib.hasPrefix "crates/schemars-docgen/src/templates/" rel;
|
||||
}
|
||||
.${platform};
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
"tool": [
|
||||
"komorebi-e2e-agent",
|
||||
"komorebi-testwin",
|
||||
"schemars-docgen",
|
||||
"schemars-nixgen"
|
||||
],
|
||||
"none": [
|
||||
|
||||
Reference in new issue
Block a user