Skip to content

Commit 7cc1d4b

Browse files
committed
Add Nix flake
This commit adds a Nix flake to just, to make it possible to build just locally using the Nix flake infrastructure and distribute just as a flake input.
1 parent 2b37230 commit 7cc1d4b

File tree

4 files changed

+223
-0
lines changed

4 files changed

+223
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
/test-utilities/Cargo.lock
1616
/test-utilities/target
1717
/tmp
18+
result

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,27 @@ most Windows users.)
346346
</tbody>
347347
</table>
348348

349+
350+
#### Nix flake
351+
352+
The `just` repository has a `flake.nix` file defining the repository as a [nix flake](https://nix.dev/concepts/flakes.html)
353+
354+
You can specify the `just` repository as an input to another nix flake:
355+
356+
```nix
357+
{
358+
inputs = {
359+
...
360+
just.url = "github:casey/just";
361+
}
362+
363+
outputs = {self, nixpkgs, just}: {
364+
...
365+
}
366+
}
367+
368+
```
369+
349370
![just package version table](https://repology.org/badge/vertical-allrepos/just.svg)
350371

351372
### Pre-Built Binaries

flake.lock

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

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

0 commit comments

Comments
 (0)