Skip to content

Commit ac39024

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 ac39024

File tree

4 files changed

+220
-0
lines changed

4 files changed

+220
-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: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
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 = let
71+
p = cargoToml.package;
72+
in {
73+
description = p.description;
74+
homepage = p.homepage;
75+
changelog = "${p.repository}/blob/master/CHANGELOG.md";
76+
license = pkgs.lib.licenses.cc0;
77+
mainProgram = "just";
78+
};
79+
};
80+
81+
# Development shell with additional tools
82+
devShell = pkgs.mkShell {
83+
inputsFrom = [just];
84+
85+
packages = with pkgs; [
86+
# Rust toolchain
87+
rustc
88+
cargo
89+
clippy
90+
rustfmt
91+
rust-analyzer
92+
93+
# Development tools
94+
cargo-watch
95+
cargo-fuzz
96+
cargo-outdated
97+
cargo-udeps
98+
mdbook
99+
mdbook-linkcheck
100+
shellcheck
101+
102+
# Runtime dependencies
103+
bashInteractive
104+
coreutils
105+
106+
# Additional utilities from justfile
107+
python3
108+
nodejs
109+
perl
110+
ruby
111+
];
112+
113+
shellHook = ''
114+
echo "Just development environment"
115+
echo "Version: ${version}"
116+
'';
117+
};
118+
in {
119+
packages = {
120+
default = just;
121+
just = just;
122+
};
123+
124+
apps = {
125+
default = flake-utils.lib.mkApp {
126+
drv = just;
127+
exePath = "/bin/just";
128+
};
129+
};
130+
131+
devShells.default = devShell;
132+
133+
# Formatter for `nix fmt`
134+
formatter = pkgs.nixpkgs-fmt;
135+
}
136+
);
137+
}

0 commit comments

Comments
 (0)