diff --git a/.gitignore b/.gitignore index 443c5f02b3..00a3f90e40 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ /test-utilities/Cargo.lock /test-utilities/target /tmp +result diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000000..0f8299cb2c --- /dev/null +++ b/flake.lock @@ -0,0 +1,82 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1763283776, + "narHash": "sha256-Y7TDFPK4GlqrKrivOcsHG8xSGqQx3A6c+i7novT85Uk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "50a96edd8d0db6cc8db57dab6bb6d6ee1f3dc49a", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1763433504, + "narHash": "sha256-cVid5UNpk88sPYHkLAA5aZEHOFQXSB/2L1vl18Aq7IM=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "42ce16c6d8318a654d53f047c9400b7d902d6e61", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000000..26c0fe2337 --- /dev/null +++ b/flake.nix @@ -0,0 +1,147 @@ +{ + description = "Just a command runner"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { self, nixpkgs, flake-utils, rust-overlay }: + flake-utils.lib.eachDefaultSystem (system: + let + overlays = [ (import rust-overlay) ]; + pkgs = import nixpkgs { + inherit system overlays; + }; + + # Read version from Cargo.toml + cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml); + version = cargoToml.package.version; + + # Common build inputs + buildInputs = with pkgs; [ + libiconv + ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ + darwin.apple_sdk.frameworks.Security + ]; + + nativeBuildInputs = with pkgs; [ + installShellFiles + pkg-config + ]; + + # The main just package + just = pkgs.rustPlatform.buildRustPackage { + pname = "just"; + inherit version; + + src = ./.; + + cargoLock = { + lockFile = ./Cargo.lock; + }; + + inherit nativeBuildInputs buildInputs; + + # Don't check during build since we run tests separately + doCheck = false; + + # Generate shell completions and man pages + postInstall = '' + # Generate and install shell completions + for shell in bash fish zsh; do + $out/bin/just --completions $shell > just.$shell + installShellCompletion just.$shell + done + + # Generate and install man page + $out/bin/just --man > just.1 + installManPage just.1 + ''; + + # Setup hook for runtime dependencies + setupHook = pkgs.writeText "setup-hook.sh" '' + export JUST_PATH_PREFIX="${pkgs.lib.makeBinPath [ pkgs.coreutils pkgs.bashInteractive ]}''${JUST_PATH_PREFIX:+:$JUST_PATH_PREFIX}" + ''; + + meta = with pkgs.lib; { + description = "Just a command runner"; + homepage = "https://github.com/casey/just"; + changelog = "https://github.com/casey/just/blob/master/CHANGELOG.md"; + license = licenses.cc0; + mainProgram = "just"; + maintainers = with maintainers; [ ]; + }; + }; + + # Development shell with additional tools + devShell = pkgs.mkShell { + inputsFrom = [ just ]; + + packages = with pkgs; [ + # Rust toolchain with clippy and rustfmt + (rust-bin.stable.latest.default.override { + extensions = [ "rust-src" "rust-analyzer" "clippy" "rustfmt" ]; + }) + rust-bin.nightly.latest.default + + # Development tools + cargo-watch + cargo-fuzz + cargo-outdated + cargo-udeps + mdbook + mdbook-linkcheck + shellcheck + + # Runtime dependencies + bashInteractive + coreutils + + # Additional utilities from justfile + python3 + nodejs + perl + ruby + ]; + + shellHook = '' + echo "Just development environment" + echo "Version: ${version}" + echo "" + echo "Available commands:" + echo " cargo build - Build the project" + echo " cargo test - Run tests" + echo " cargo clippy - Run clippy lints" + echo " just - Run using the local justfile" + echo "" + ''; + + RUST_SRC_PATH = "${pkgs.rust-bin.stable.latest.rust-src}/lib/rustlib/src/rust/library"; + }; + + in + { + packages = { + default = just; + just = just; + }; + + apps = { + default = flake-utils.lib.mkApp { + drv = just; + exePath = "/bin/just"; + }; + }; + + devShells.default = devShell; + + # Formatter for `nix fmt` + formatter = pkgs.nixpkgs-fmt; + } + ); +}