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.stdenv.hostPlatform.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
# When we're running in the shell, we want to use rustc with a bunch
35
# of extra junk to ensure that rust-analyzer works, clippy etc are all
36
# installed.
37
rustShellToolchain = (pkgs.rust-bin.selectLatestNightlyWith (t: t.default)).override {
38
# NOTE (aseipp): explicitly add rust-src to the rustc compiler only in
39
# devShell. this in turn causes a dependency on the rust compiler src,
40
# which bloats the closure size by several GiB. but doing this here and
41
# not by default avoids the default flake install from including that
42
# dependency, so it's worth it
43
#
44
# relevant PR: https://github.com/rust-lang/rust/pull/129687
45
extensions = ["rust-src" "rust-analyzer"];
46
};
47
48
# But, whenever we are running CI builds or checks, we want to use a
49
# smaller closure. This reduces the CI impact on fresh clones/VMs, etc.
50
rustMinimalPlatform =
51
let platform = pkgs.rust-bin.selectLatestNightlyWith (t: t.minimal);
52
in pkgs.makeRustPlatform { rustc = platform; cargo = platform; };
53
in {
54
formatter = pkgs.alejandra;
55
56
packages = {
57
jujutsu = pkgs.callPackage ./default.nix {
58
rustPlatform = rustMinimalPlatform;
59
gitRev = self.rev or self.dirtyRev or null;
60
};
61
default = self.packages.${system}.jujutsu;
62
};
63
64
checks.jujutsu = self.packages.${system}.jujutsu.overrideAttrs ({...}: {
65
# The default Rust infrastructure runs all builds in the release
66
# profile, which is significantly slower. Run this under the `test`
67
# profile instead, which matches all our other CI systems, Cargo, etc.
68
cargoBuildType = "test";
69
cargoCheckType = "test";
70
71
# By default, `flake check` will want to run the install phase, but
72
# because we override the cargoBuildType, it fails to find the proper
73
# binary. But we don't even care about the binary or even the buildPhase
74
# in this case; just remove them both.
75
buildPhase = "true";
76
installPhase = "touch $out";
77
});
78
79
devShells.default = let
80
packages = with pkgs; [
81
rustShellToolchain
82
83
# Additional tools recommended by contributing.md
84
bacon
85
cargo-deny
86
cargo-insta
87
cargo-nextest
88
89
# Miscellaneous tools
90
watchman
91
92
# In case you need to run `cargo run --bin gen-protos`
93
protobuf
94
95
# For building the documentation website
96
uv
97
# nixos does not work with uv-installed python
98
python3
99
python3Packages.numpy
100
];
101
102
# on macOS and Linux, use faster parallel linkers that are much more
103
# efficient than the defaults. these noticeably improve link time even for
104
# medium sized rust projects like jj
105
rustLinkerFlags =
106
if pkgs.stdenv.isLinux
107
then ["-fuse-ld=mold" "-Wl,--compress-debug-sections=zstd"]
108
else if pkgs.stdenv.isDarwin
109
then
110
# on darwin, /usr/bin/ld actually looks at the environment variable
111
# $DEVELOPER_DIR, which is set by the nix stdenv, and if set,
112
# automatically uses it to route the `ld` invocation to the binary
113
# within. in the devShell though, that isn't what we want; it's
114
# functional, but Xcode's linker as of ~v15 (not yet open source)
115
# is ultra-fast and very shiny; it is enabled via -ld_new, and on by
116
# default as of v16+
117
["--ld-path=$(unset DEVELOPER_DIR; /usr/bin/xcrun --find ld)" "-ld_new"]
118
else [];
119
120
rustLinkFlagsString =
121
pkgs.lib.concatStringsSep " "
122
(pkgs.lib.concatMap (x: ["-C" "link-arg=${x}"]) rustLinkerFlags);
123
124
# The `RUSTFLAGS` environment variable is set in `shellHook` instead of `env`
125
# to allow the `xcrun` command above to be interpreted by the shell.
126
shellHook = ''
127
export RUSTFLAGS="-Zthreads=0 ${rustLinkFlagsString}"
128
'';
129
130
jujutsu = self.packages.${system}.jujutsu;
131
in
132
pkgs.mkShell {
133
name = "jujutsu";
134
packages = packages ++ jujutsu.nativeBuildInputs ++ jujutsu.buildInputs;
135
inherit shellHook;
136
};
137
}));
138
}
139