1
{
2
description = "Jujutsu VCS, a Git-compatible DVCS that is both simple and powerful";
3
4
inputs = {
5
# For listing and iterating nix systems
6
flake-utils.url = "github:numtide/flake-utils";
7
8
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
9
10
# For installing non-standard rustc versions
11
rust-overlay.url = "github:oxalica/rust-overlay";
12
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
13
};
14
15
outputs = {
16
self,
17
nixpkgs,
18
flake-utils,
19
rust-overlay,
20
}:
21
{
22
overlays.default = final: prev: {
23
jujutsu = self.packages.${final.system}.jujutsu;
24
};
25
}
26
// (flake-utils.lib.eachSystem nixpkgs.lib.systems.flakeExposed (system: let
27
pkgs = import nixpkgs {
28
inherit system;
29
overlays = [
30
rust-overlay.overlays.default
31
];
32
};
33
34
packageVersion = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).workspace.package.version;
35
36
filterSrc = src: regexes:
37
pkgs.lib.cleanSourceWith {
38
inherit src;
39
filter = path: type: let
40
relPath = pkgs.lib.removePrefix (toString src + "/") (toString path);
41
in
42
pkgs.lib.all (re: builtins.match re relPath == null) regexes;
43
};
44
45
# When we're running in the shell, we want to use rustc with a bunch
46
# of extra junk to ensure that rust-analyzer works, clippy etc are all
47
# installed.
48
rustShellToolchain = (pkgs.rust-bin.selectLatestNightlyWith (t: t.default)).override {
49
# NOTE (aseipp): explicitly add rust-src to the rustc compiler only in
50
# devShell. this in turn causes a dependency on the rust compiler src,
51
# which bloats the closure size by several GiB. but doing this here and
52
# not by default avoids the default flake install from including that
53
# dependency, so it's worth it
54
#
55
# relevant PR: https://github.com/rust-lang/rust/pull/129687
56
extensions = ["rust-src" "rust-analyzer"];
57
};
58
59
# But, whenever we are running CI builds or checks, we want to use a
60
# smaller closure. This reduces the CI impact on fresh clones/VMs, etc.
61
rustMinimalPlatform =
62
let platform = pkgs.rust-bin.selectLatestNightlyWith (t: t.minimal);
63
in pkgs.makeRustPlatform { rustc = platform; cargo = platform; };
64
65
nativeBuildInputs = with pkgs;
66
[ ]
67
++ lib.optionals stdenv.isLinux [
68
mold-wrapped
69
];
70
71
buildInputs = [ ];
72
73
nativeCheckInputs = with pkgs; [
74
# for signing tests
75
gnupg
76
openssh
77
78
# for git subprocess test
79
git
80
];
81
82
env = {
83
RUST_BACKTRACE = 1;
84
CARGO_INCREMENTAL = "0"; # https://github.com/rust-lang/rust/issues/139110
85
};
86
in {
87
formatter = pkgs.alejandra;
88
89
packages = {
90
jujutsu = rustMinimalPlatform.buildRustPackage {
91
pname = "jujutsu";
92
version = "${packageVersion}-unstable-${self.shortRev or "dirty"}";
93
94
cargoBuildFlags = ["--bin" "jj"]; # don't build and install the fake editors
95
useNextest = true;
96
cargoTestFlags = ["--profile" "ci"];
97
src = filterSrc ./. [
98
".*\\.nix$"
99
"^.jj/"
100
"^flake\\.lock$"
101
"^target/"
102
];
103
104
cargoLock.lockFile = ./Cargo.lock;
105
nativeBuildInputs = nativeBuildInputs ++ [pkgs.installShellFiles];
106
inherit buildInputs nativeCheckInputs;
107
108
env =
109
env
110
// {
111
RUSTFLAGS = pkgs.lib.optionalString pkgs.stdenv.isLinux "-C link-arg=-fuse-ld=mold";
112
NIX_JJ_GIT_HASH = self.rev or "";
113
};
114
115
postInstall = ''
116
$out/bin/jj util install-man-pages man
117
installManPage ./man/man1/*
118
119
installShellCompletion --cmd jj \
120
--bash <(COMPLETE=bash $out/bin/jj) \
121
--fish <(COMPLETE=fish $out/bin/jj) \
122
--zsh <(COMPLETE=zsh $out/bin/jj)
123
'';
124
125
meta = {
126
description = "Git-compatible DVCS that is both simple and powerful";
127
homepage = "https://github.com/jj-vcs/jj";
128
license = pkgs.lib.licenses.asl20;
129
mainProgram = "jj";
130
};
131
};
132
default = self.packages.${system}.jujutsu;
133
};
134
135
checks.jujutsu = self.packages.${system}.jujutsu.overrideAttrs ({...}: {
136
# The default Rust infrastructure runs all builds in the release
137
# profile, which is significantly slower. Run this under the `test`
138
# profile instead, which matches all our other CI systems, Cargo, etc.
139
cargoBuildType = "test";
140
cargoCheckType = "test";
141
142
# By default, `flake check` will want to run the install phase, but
143
# because we override the cargoBuildType, it fails to find the proper
144
# binary. But we don't even care about the binary or even the buildPhase
145
# in this case; just remove them both.
146
buildPhase = "true";
147
installPhase = "touch $out";
148
});
149
150
devShells.default = let
151
packages = with pkgs; [
152
rustShellToolchain
153
154
# Additional tools recommended by contributing.md
155
bacon
156
cargo-deny
157
cargo-insta
158
cargo-nextest
159
160
# Miscellaneous tools
161
watchman
162
163
# In case you need to run `cargo run --bin gen-protos`
164
protobuf
165
166
# For building the documentation website
167
uv
168
# nixos does not work with uv-installed python
169
python3
170
python3Packages.numpy
171
];
172
173
# on macOS and Linux, use faster parallel linkers that are much more
174
# efficient than the defaults. these noticeably improve link time even for
175
# medium sized rust projects like jj
176
rustLinkerFlags =
177
if pkgs.stdenv.isLinux
178
then ["-fuse-ld=mold" "-Wl,--compress-debug-sections=zstd"]
179
else if pkgs.stdenv.isDarwin
180
then
181
# on darwin, /usr/bin/ld actually looks at the environment variable
182
# $DEVELOPER_DIR, which is set by the nix stdenv, and if set,
183
# automatically uses it to route the `ld` invocation to the binary
184
# within. in the devShell though, that isn't what we want; it's
185
# functional, but Xcode's linker as of ~v15 (not yet open source)
186
# is ultra-fast and very shiny; it is enabled via -ld_new, and on by
187
# default as of v16+
188
["--ld-path=$(unset DEVELOPER_DIR; /usr/bin/xcrun --find ld)" "-ld_new"]
189
else [];
190
191
rustLinkFlagsString =
192
pkgs.lib.concatStringsSep " "
193
(pkgs.lib.concatMap (x: ["-C" "link-arg=${x}"]) rustLinkerFlags);
194
195
# The `RUSTFLAGS` environment variable is set in `shellHook` instead of `env`
196
# to allow the `xcrun` command above to be interpreted by the shell.
197
shellHook = ''
198
export RUSTFLAGS="-Zthreads=0 ${rustLinkFlagsString}"
199
'';
200
in
201
pkgs.mkShell {
202
name = "jujutsu";
203
packages = packages ++ nativeBuildInputs ++ buildInputs ++ nativeCheckInputs;
204
inherit env shellHook;
205
};
206
}));
207
}
208