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