Skip to content

build(nix): add flake#27

Merged
PTFOPlayer merged 1 commit into
PTFOPlayer:masterfrom
brhutchins:build/nix/add-flake
Jun 14, 2026
Merged

build(nix): add flake#27
PTFOPlayer merged 1 commit into
PTFOPlayer:masterfrom
brhutchins:build/nix/add-flake

Conversation

@brhutchins

Copy link
Copy Markdown
Contributor

Add flake for building/running/installing via Nix.

The flake also provides a development shell with all deveplopment dependencies, as well as a check running cargo fmt, cargo clippy, and cargo test.

Update docs to cover Nix path.

Add flake for building/running/installing via Nix. The flake also
provides a development shell with all deveplopment dependencies, as well
as a check running `cargo fmt`, `cargo clippy`, and `cargo test`.

Update docs to cover Nix path.
@PTFOPlayer PTFOPlayer self-requested a review June 14, 2026 13:16

@PTFOPlayer PTFOPlayer left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes to contributing.md and readme.md look good but i'm not familiar with NIX so to verify flake file ill have to do some research before merging this PR. I'll probably do it in next 24 hours or so

@PTFOPlayer PTFOPlayer merged commit 13fbcb4 into PTFOPlayer:master Jun 14, 2026
4 checks passed

@brhutchins brhutchins left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you accepted it already! I've added some PR comments to document the less self-explanatory bits of the flake. Maybe moot now, but might be useful to have in the history.

Comment thread flake.nix

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provides a set of utilities for making flakes more ergonomic – here eachDefaultSystem is used to avoid having to write explicit separate derivations for Linux x86, Linux ARM, MacOS Apple Silicon, etc.

Comment thread flake.nix
Comment on lines +7 to +9
crane = {
url = "github:ipetkov/crane";
};

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Crane provides lots of utilities for building Rust projects with Nix: https://crane.dev/index.html

Comment thread flake.nix
Comment on lines +10 to +13
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rust-overlay lets you pin specific Rust toolchain dependencies

Comment thread flake.nix
extensions = [ "rustfmt" "clippy" ];
};

craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uses the defined (latest) toolchain for building the project, instead of the default

Comment thread flake.nix
Comment on lines +32 to +37
src = lib.cleanSourceWith {
filter = path: type:
(craneLib.filterCargoSources path type) ||
(lib.hasSuffix ".md" path);
src = lib.cleanSource ./.;
};

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tells Nix which files to include when building the project. Anything not included by the filter is treated as absent at build time.

Crane provides a filter that includes all standard Cargo/Rust files. I'm combining with another filter that adds .md files, because that's what tiny-harness stores its prompts in.

Comment thread flake.nix
buildInputs = [
pkgs.openssl
] ++ lib.optionals pkgs.stdenv.isDarwin [
pkgs.apple-sdk

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

required for building on Macs

Comment thread flake.nix

tinyharness = craneLib.buildPackage (commonArgs // {
inherit cargoArtifacts;
doCheck = false;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just means we don't run the checks by default when building, since those are handled by the flake checks

Comment thread flake.nix

cargoArtifacts = craneLib.buildDepsOnly commonArgs;

tinyharness = craneLib.buildPackage (commonArgs // {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This defines the actual build for the project

Comment thread flake.nix
Comment on lines +67 to +70
packages = {
default = tinyharness;
tinyharness = tinyharness;
};

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Packages are the actual output from an end user perspective. When you do nix flake run, the default package is what gets called; same if you install via Nix.

Comment thread flake.nix
};
};

devShells.default = craneLib.devShell {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This defines all the development dependencies. You run nix develop, or use direnv to automate it when entering the directory, and you have everything you need to work on the project. No need to manually install a Rust toolchain, cargo, LSP, etc.

@PTFOPlayer

Copy link
Copy Markdown
Owner

I see you accepted it already! I've added some PR comments to document the less self-explanatory bits of the flake. Maybe moot now, but might be useful to have in the history.

Thanks, i have done quick research to merge it as fast as i can.
Ill read all your comments to learn what have been actually done and maybe do some changes (for example cargo audit on instalation or pinning rust version)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants