Skip to content

Commit e4bd291

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 312bff4 commit e4bd291

File tree

4 files changed

+218
-0
lines changed

4 files changed

+218
-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: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
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

Comments
 (0)