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/README.md b/README.md index 343315b910..2eb0a230e7 100644 --- a/README.md +++ b/README.md @@ -351,6 +351,27 @@ most Windows users.) + +#### Nix flake + +The `just` repository has a `flake.nix` file defining the repository as a [nix flake](https://nix.dev/concepts/flakes.html) + +You can specify the `just` repository as an input to another nix flake: + +```nix +{ + inputs = { + ... + just.url = "github:casey/just"; + } + + outputs = {self, nixpkgs, just}: { + ... + } +} + +``` + ![just package version table](https://repology.org/badge/vertical-allrepos/just.svg) ### Pre-Built Binaries diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000000..477c915913 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "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" + } + }, + "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..1e233a8d72 --- /dev/null +++ b/flake.nix @@ -0,0 +1,137 @@ +{ + description = "Just a command runner"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { + self, + nixpkgs, + flake-utils, + }: + flake-utils.lib.eachDefaultSystem ( + system: let + pkgs = import nixpkgs { + inherit system; + }; + + # Read version from Cargo.toml + cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml); + version = cargoToml.package.version; + + # Common build inputs + buildInputs = with pkgs; + lib.optionals stdenv.hostPlatform.isDarwin [ + libiconv + 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 = let + p = cargoToml.package; + in { + description = p.description; + homepage = p.homepage; + changelog = "${p.repository}/blob/master/CHANGELOG.md"; + license = pkgs.lib.licenses.cc0; + mainProgram = "just"; + }; + }; + + # Development shell with additional tools + devShell = pkgs.mkShell { + inputsFrom = [just]; + + packages = with pkgs; [ + # Rust toolchain + rustc + cargo + clippy + rustfmt + rust-analyzer + + # 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}" + ''; + }; + 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; + } + ); +}