|
| 1 | +{ |
| 2 | + description = "Just a command runner"; |
| 3 | + |
| 4 | + inputs = { |
| 5 | + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; |
| 6 | + flake-utils.url = "github:numtide/flake-utils"; |
| 7 | + }; |
| 8 | + |
| 9 | + outputs = { |
| 10 | + self, |
| 11 | + nixpkgs, |
| 12 | + flake-utils, |
| 13 | + }: |
| 14 | + flake-utils.lib.eachDefaultSystem ( |
| 15 | + system: let |
| 16 | + pkgs = import nixpkgs { |
| 17 | + inherit system; |
| 18 | + }; |
| 19 | + |
| 20 | + # Read version from Cargo.toml |
| 21 | + cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml); |
| 22 | + version = cargoToml.package.version; |
| 23 | + |
| 24 | + # Common build inputs |
| 25 | + buildInputs = with pkgs; |
| 26 | + lib.optionals stdenv.hostPlatform.isDarwin [ |
| 27 | + libiconv |
| 28 | + darwin.apple_sdk.frameworks.Security |
| 29 | + ]; |
| 30 | + |
| 31 | + nativeBuildInputs = with pkgs; [ |
| 32 | + installShellFiles |
| 33 | + pkg-config |
| 34 | + ]; |
| 35 | + |
| 36 | + # The main just package |
| 37 | + just = pkgs.rustPlatform.buildRustPackage { |
| 38 | + pname = "just"; |
| 39 | + inherit version; |
| 40 | + |
| 41 | + src = ./.; |
| 42 | + |
| 43 | + cargoLock = { |
| 44 | + lockFile = ./Cargo.lock; |
| 45 | + }; |
| 46 | + |
| 47 | + inherit nativeBuildInputs buildInputs; |
| 48 | + |
| 49 | + # Don't check during build since we run tests separately |
| 50 | + doCheck = false; |
| 51 | + |
| 52 | + # Generate shell completions and man pages |
| 53 | + postInstall = '' |
| 54 | + # Generate and install shell completions |
| 55 | + for shell in bash fish zsh; do |
| 56 | + $out/bin/just --completions $shell > just.$shell |
| 57 | + installShellCompletion just.$shell |
| 58 | + done |
| 59 | +
|
| 60 | + # Generate and install man page |
| 61 | + $out/bin/just --man > just.1 |
| 62 | + installManPage just.1 |
| 63 | + ''; |
| 64 | + |
| 65 | + # Setup hook for runtime dependencies |
| 66 | + setupHook = pkgs.writeText "setup-hook.sh" '' |
| 67 | + export JUST_PATH_PREFIX="${pkgs.lib.makeBinPath [pkgs.coreutils pkgs.bashInteractive]}''${JUST_PATH_PREFIX:+:$JUST_PATH_PREFIX}" |
| 68 | + ''; |
| 69 | + |
| 70 | + meta = with pkgs.lib; { |
| 71 | + description = cargoToml.package.description; |
| 72 | + homepage = cargoToml.package.homepage; |
| 73 | + changelog = "${cargoToml.package.repository}/blob/master/CHANGELOG.md"; |
| 74 | + license = licenses.cc0; |
| 75 | + mainProgram = "just"; |
| 76 | + }; |
| 77 | + }; |
| 78 | + |
| 79 | + # Development shell with additional tools |
| 80 | + devShell = pkgs.mkShell { |
| 81 | + inputsFrom = [just]; |
| 82 | + |
| 83 | + packages = with pkgs; [ |
| 84 | + # Rust toolchain |
| 85 | + rustc |
| 86 | + cargo |
| 87 | + clippy |
| 88 | + rustfmt |
| 89 | + rust-analyzer |
| 90 | + |
| 91 | + # Development tools |
| 92 | + cargo-watch |
| 93 | + cargo-fuzz |
| 94 | + cargo-outdated |
| 95 | + cargo-udeps |
| 96 | + mdbook |
| 97 | + mdbook-linkcheck |
| 98 | + shellcheck |
| 99 | + |
| 100 | + # Runtime dependencies |
| 101 | + bashInteractive |
| 102 | + coreutils |
| 103 | + |
| 104 | + # Additional utilities from justfile |
| 105 | + python3 |
| 106 | + nodejs |
| 107 | + perl |
| 108 | + ruby |
| 109 | + ]; |
| 110 | + |
| 111 | + shellHook = '' |
| 112 | + echo "Just development environment" |
| 113 | + echo "Version: ${version}" |
| 114 | + ''; |
| 115 | + }; |
| 116 | + in { |
| 117 | + packages = { |
| 118 | + default = just; |
| 119 | + just = just; |
| 120 | + }; |
| 121 | + |
| 122 | + apps = { |
| 123 | + default = flake-utils.lib.mkApp { |
| 124 | + drv = just; |
| 125 | + exePath = "/bin/just"; |
| 126 | + }; |
| 127 | + }; |
| 128 | + |
| 129 | + devShells.default = devShell; |
| 130 | + |
| 131 | + # Formatter for `nix fmt` |
| 132 | + formatter = pkgs.nixpkgs-fmt; |
| 133 | + } |
| 134 | + ); |
| 135 | +} |
0 commit comments