-
Notifications
You must be signed in to change notification settings - Fork 4
build(nix): add flake #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| /target | ||
| /result | ||
|
|
||
| /.tinyharness | ||
| /todo | ||
| /todo | ||
|
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| { | ||
| description = "TinyHarness - AI Coding Harness"; | ||
|
|
||
| inputs = { | ||
| nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; | ||
| flake-utils.url = "github:numtide/flake-utils"; | ||
| crane = { | ||
| url = "github:ipetkov/crane"; | ||
| }; | ||
|
Comment on lines
+7
to
+9
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| rust-overlay = { | ||
| url = "github:oxalica/rust-overlay"; | ||
| inputs.nixpkgs.follows = "nixpkgs"; | ||
| }; | ||
|
Comment on lines
+10
to
+13
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| }; | ||
|
|
||
| outputs = { self, nixpkgs, flake-utils, crane, rust-overlay, ... }: | ||
| flake-utils.lib.eachDefaultSystem (system: | ||
| let | ||
| pkgs = import nixpkgs { | ||
| inherit system; | ||
| overlays = [ (import rust-overlay) ]; | ||
| }; | ||
|
|
||
| inherit (pkgs) lib; | ||
|
|
||
| rustToolchain = pkgs.rust-bin.stable.latest.default.override { | ||
| extensions = [ "rustfmt" "clippy" ]; | ||
| }; | ||
|
|
||
| craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
|
||
| src = lib.cleanSourceWith { | ||
| filter = path: type: | ||
| (craneLib.filterCargoSources path type) || | ||
| (lib.hasSuffix ".md" path); | ||
| src = lib.cleanSource ./.; | ||
| }; | ||
|
Comment on lines
+32
to
+37
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
|
||
| commonArgs = { | ||
| inherit src; | ||
| strictDeps = true; | ||
| buildInputs = [ | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| pkgs.openssl | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| ] ++ lib.optionals pkgs.stdenv.isDarwin [ | ||
| pkgs.apple-sdk | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. required for building on Macs |
||
| ]; | ||
| nativeBuildInputs = [ | ||
| pkgs.pkg-config | ||
|
Comment on lines
+47
to
+48
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| ]; | ||
| }; | ||
|
|
||
| cargoArtifacts = craneLib.buildDepsOnly commonArgs; | ||
|
|
||
| tinyharness = craneLib.buildPackage (commonArgs // { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This defines the actual build for the project |
||
| inherit cargoArtifacts; | ||
| doCheck = false; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| meta = { | ||
| mainProgram = "tinyharness"; | ||
| }; | ||
| }); | ||
|
|
||
| tests = craneLib.cargoTest (commonArgs // { | ||
| inherit cargoArtifacts; | ||
| }); | ||
|
|
||
| in { | ||
| packages = { | ||
| default = tinyharness; | ||
| tinyharness = tinyharness; | ||
| }; | ||
|
Comment on lines
+67
to
+70
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
|
||
| checks = { | ||
| inherit tinyharness; | ||
| inherit tests; | ||
| clippy = craneLib.cargoClippy (commonArgs // { | ||
| inherit cargoArtifacts; | ||
| cargoClippyExtraArgs = "-- --deny warnings"; | ||
| }); | ||
| fmt = craneLib.cargoFmt { | ||
| inherit src; | ||
| }; | ||
| }; | ||
|
|
||
| devShells.default = craneLib.devShell { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This defines all the development dependencies. You run |
||
| checks = self.checks.${system}; | ||
| packages = with pkgs; [ | ||
| cargo | ||
| clippy | ||
| rust-analyzer | ||
| rustfmt | ||
| ]; | ||
| }; | ||
| }); | ||
| } | ||
There was a problem hiding this comment.
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
eachDefaultSystemis used to avoid having to write explicit separate derivations for Linux x86, Linux ARM, MacOS Apple Silicon, etc.