jj/flake.nix
bsdinis 35440ce1bd
Some checks are pending
binaries / Build binary artifacts (push) Waiting to run
website / prerelease-docs-build-deploy (ubuntu-24.04) (push) Waiting to run
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run
git: spawn a separate git process for network operations
Reasoning:

`jj` fails to push/fetch over ssh depending on the system.
Issue #4979 lists over 20 related issues on this and proposes spawning
a `git` subprocess for tasks related to the network (in fact, just push/fetch
are enough).

This PR implements this.

Implementation Details:

This PR implements shelling out to `git` via `std::process::Command`.
There are 2 sharp edges with the patch:
 - it relies on having to parse out git errors to match the error codes
   (and parsing git2's errors in one particular instance to match the
   error behaviour). This seems mostly unavoidable

 - to ensure matching behaviour with git2, the tests are maintained across the
   two implementations. This is done using test_case, as with the rest
   of the codebase

Testing:

Run the rust tests:
```
$ cargo test
```

Build:
```
$ cargo build
```

Clone a private repo:
```
$ path/to/jj git clone --config='git.subprocess=true' <REPO_SSH_URL>
```

Create new commit and push
```
$ echo "TEST" > this_is_a_test_file.txt
$ path/to/jj describe -m 'test commit'
$ path/to/jj git push --config='git.subprocess=true' -b <branch>
```


Issues Closed

With a grain of salt, but most of these problems should be fixed (or at least checked if they are fixed). They are the ones listed in #4979 .

SSH:
- https://github.com/jj-vcs/jj/issues/63
- https://github.com/jj-vcs/jj/issues/440
- https://github.com/jj-vcs/jj/issues/1455
- https://github.com/jj-vcs/jj/issues/1507
- https://github.com/jj-vcs/jj/issues/2931
- https://github.com/jj-vcs/jj/issues/2958
- https://github.com/jj-vcs/jj/issues/3322
- https://github.com/jj-vcs/jj/issues/4101
- https://github.com/jj-vcs/jj/issues/4333
- https://github.com/jj-vcs/jj/issues/4386
- https://github.com/jj-vcs/jj/issues/4488
- https://github.com/jj-vcs/jj/issues/4591
- https://github.com/jj-vcs/jj/issues/4802
- https://github.com/jj-vcs/jj/issues/4870
- https://github.com/jj-vcs/jj/issues/4937
- https://github.com/jj-vcs/jj/issues/4978
- https://github.com/jj-vcs/jj/issues/5120
- https://github.com/jj-vcs/jj/issues/5166

Clone/fetch/push/pull:
- https://github.com/jj-vcs/jj/issues/360
- https://github.com/jj-vcs/jj/issues/1278
- https://github.com/jj-vcs/jj/issues/1957
- https://github.com/jj-vcs/jj/issues/2295
- https://github.com/jj-vcs/jj/issues/3851
- https://github.com/jj-vcs/jj/issues/4177
- https://github.com/jj-vcs/jj/issues/4682
- https://github.com/jj-vcs/jj/issues/4719
- https://github.com/jj-vcs/jj/issues/4889
- https://github.com/jj-vcs/jj/discussions/5147
- https://github.com/jj-vcs/jj/issues/5238

Notable Holdouts:
 - Interactive HTTP authentication (https://github.com/jj-vcs/jj/issues/401, https://github.com/jj-vcs/jj/issues/469)
 - libssh2-sys dependency on windows problem (can only be removed if/when we get rid of libgit2): https://github.com/jj-vcs/jj/issues/3984
2025-01-23 16:50:53 +00:00

203 lines
6.3 KiB
Nix

{
description = "Jujutsu VCS, a Git-compatible DVCS that is both simple and powerful";
inputs = {
# For listing and iterating nix systems
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
# For installing non-standard rustc versions
rust-overlay.url = "github:oxalica/rust-overlay";
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = {
self,
nixpkgs,
flake-utils,
rust-overlay,
}:
{
overlays.default = final: prev: {
jujutsu = self.packages.${final.system}.jujutsu;
};
}
// (flake-utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {
inherit system;
overlays = [
rust-overlay.overlays.default
];
};
filterSrc = src: regexes:
pkgs.lib.cleanSourceWith {
inherit src;
filter = path: type: let
relPath = pkgs.lib.removePrefix (toString src + "/") (toString path);
in
pkgs.lib.all (re: builtins.match re relPath == null) regexes;
};
ourRustVersion = pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default);
ourRustPlatform = pkgs.makeRustPlatform {
rustc = ourRustVersion;
cargo = ourRustVersion;
};
nativeBuildInputs = with pkgs;
[
gzip
pkg-config
# for libz-ng-sys (zlib-ng)
# TODO: switch to the packaged zlib-ng and drop this dependency
cmake
]
++ lib.optionals stdenv.isLinux [
mold-wrapped
];
buildInputs = with pkgs;
[
openssl
libgit2
libssh2
]
++ lib.optionals stdenv.isDarwin [
darwin.apple_sdk.frameworks.Security
darwin.apple_sdk.frameworks.SystemConfiguration
libiconv
];
nativeCheckInputs = with pkgs; [
# for signing tests
gnupg
openssh
# for git subprocess test
git
];
env = {
LIBSSH2_SYS_USE_PKG_CONFIG = "1";
RUST_BACKTRACE = 1;
};
in {
formatter = pkgs.alejandra;
checks.jujutsu = self.packages.${system}.jujutsu;
packages = {
jujutsu = ourRustPlatform.buildRustPackage {
pname = "jujutsu";
version = "unstable-${self.shortRev or "dirty"}";
buildFeatures = ["packaging"];
cargoBuildFlags = ["--bin" "jj"]; # don't build and install the fake editors
useNextest = true;
src = filterSrc ./. [
".*\\.nix$"
"^.jj/"
"^flake\\.lock$"
"^target/"
];
cargoLock.lockFile = ./Cargo.lock;
nativeBuildInputs = nativeBuildInputs ++ [pkgs.installShellFiles];
inherit buildInputs nativeCheckInputs;
env =
env
// {
RUSTFLAGS = pkgs.lib.optionalString pkgs.stdenv.isLinux "-C link-arg=-fuse-ld=mold";
NIX_JJ_GIT_HASH = self.rev or "";
CARGO_INCREMENTAL = "0";
TEST_GIT_EXECUTABLE_PATH = pkgs.lib.getExe pkgs.git;
};
postInstall = ''
$out/bin/jj util install-man-pages man
installManPage ./man/man1/*
installShellCompletion --cmd jj \
--bash <(COMPLETE=bash $out/bin/jj) \
--fish <(COMPLETE=fish $out/bin/jj) \
--zsh <(COMPLETE=zsh $out/bin/jj)
'';
meta = {
description = "Git-compatible DVCS that is both simple and powerful";
homepage = "https://github.com/jj-vcs/jj";
license = pkgs.lib.licenses.asl20;
mainProgram = "jj";
};
};
default = self.packages.${system}.jujutsu;
};
devShells.default = let
packages = with pkgs; [
# NOTE (aseipp): explicitly add rust-src to the rustc compiler only in
# devShell. this in turn causes a dependency on the rust compiler src,
# which bloats the closure size by several GiB. but doing this here
# and not by default avoids the default flake install from including
# that dependency, so it's worth it
#
# relevant PR: https://github.com/rust-lang/rust/pull/129687
(ourRustVersion.override {
extensions = ["rust-src" "rust-analyzer"];
})
# Additional tools recommended by contributing.md
bacon
cargo-deny
cargo-insta
cargo-nextest
# Miscellaneous tools
watchman
# In case you need to run `cargo run --bin gen-protos`
protobuf
# For building the documentation website
uv
];
# on macOS and Linux, use faster parallel linkers that are much more
# efficient than the defaults. these noticeably improve link time even for
# medium sized rust projects like jj
rustLinkerFlags =
if pkgs.stdenv.isLinux
then ["-fuse-ld=mold" "-Wl,--compress-debug-sections=zstd"]
else if pkgs.stdenv.isDarwin
then
# on darwin, /usr/bin/ld actually looks at the environment variable
# $DEVELOPER_DIR, which is set by the nix stdenv, and if set,
# automatically uses it to route the `ld` invocation to the binary
# within. in the devShell though, that isn't what we want; it's
# functional, but Xcode's linker as of ~v15 (not yet open source)
# is ultra-fast and very shiny; it is enabled via -ld_new, and on by
# default as of v16+
["--ld-path=$(unset DEVELOPER_DIR; /usr/bin/xcrun --find ld)" "-ld_new"]
else [];
rustLinkFlagsString =
pkgs.lib.concatStringsSep " "
(pkgs.lib.concatMap (x: ["-C" "link-arg=${x}"]) rustLinkerFlags);
# The `RUSTFLAGS` environment variable is set in `shellHook` instead of `env`
# to allow the `xcrun` command above to be interpreted by the shell.
shellHook = ''
export RUSTFLAGS="-Zthreads=0 ${rustLinkFlagsString}"
'';
in
pkgs.mkShell {
name = "jujutsu";
packages = packages ++ nativeBuildInputs ++ buildInputs ++ nativeCheckInputs;
inherit env shellHook;
};
}));
}