mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-31 16:33:10 +00:00
nix: clean up flake
The build inputs were duplicated, once in packages.jujutsu and again in devShells.default. This removes the duplication.
This commit is contained in:
parent
f755e8f683
commit
b714592952
1 changed files with 95 additions and 110 deletions
205
flake.nix
205
flake.nix
|
@ -12,13 +12,18 @@
|
||||||
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
|
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = { self, nixpkgs, flake-utils, rust-overlay }: {
|
outputs = {
|
||||||
overlays.default = (final: prev: {
|
self,
|
||||||
jujutsu = self.packages.${final.system}.jujutsu;
|
nixpkgs,
|
||||||
});
|
flake-utils,
|
||||||
} //
|
rust-overlay,
|
||||||
(flake-utils.lib.eachDefaultSystem (system:
|
}:
|
||||||
let
|
{
|
||||||
|
overlays.default = final: prev: {
|
||||||
|
jujutsu = self.packages.${final.system}.jujutsu;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// (flake-utils.lib.eachDefaultSystem (system: let
|
||||||
pkgs = import nixpkgs {
|
pkgs = import nixpkgs {
|
||||||
inherit system;
|
inherit system;
|
||||||
overlays = [
|
overlays = [
|
||||||
|
@ -29,10 +34,9 @@
|
||||||
filterSrc = src: regexes:
|
filterSrc = src: regexes:
|
||||||
pkgs.lib.cleanSourceWith {
|
pkgs.lib.cleanSourceWith {
|
||||||
inherit src;
|
inherit src;
|
||||||
filter = path: type:
|
filter = path: type: let
|
||||||
let
|
relPath = pkgs.lib.removePrefix (toString src + "/") (toString path);
|
||||||
relPath = pkgs.lib.removePrefix (toString src + "/") (toString path);
|
in
|
||||||
in
|
|
||||||
pkgs.lib.all (re: builtins.match re relPath == null) regexes;
|
pkgs.lib.all (re: builtins.match re relPath == null) regexes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -43,48 +47,52 @@
|
||||||
cargo = ourRustVersion;
|
cargo = ourRustVersion;
|
||||||
};
|
};
|
||||||
|
|
||||||
# these are needed in both devShell and buildInputs
|
nativeBuildInputs = with pkgs;
|
||||||
darwinDeps = with pkgs; lib.optionals stdenv.isDarwin [
|
[
|
||||||
darwin.apple_sdk.frameworks.Security
|
gzip
|
||||||
darwin.apple_sdk.frameworks.SystemConfiguration
|
pkg-config
|
||||||
libiconv
|
|
||||||
|
# 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
|
||||||
];
|
];
|
||||||
|
|
||||||
# these are needed in both devShell and buildInputs
|
env = {
|
||||||
linuxNativeDeps = with pkgs; lib.optionals stdenv.isLinux [
|
LIBSSH2_SYS_USE_PKG_CONFIG = "1";
|
||||||
mold-wrapped
|
RUST_BACKTRACE = 1;
|
||||||
];
|
};
|
||||||
|
in {
|
||||||
|
formatter = pkgs.alejandra;
|
||||||
|
checks.jujutsu = self.packages.${system}.jujutsu;
|
||||||
|
|
||||||
# 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);
|
|
||||||
in
|
|
||||||
{
|
|
||||||
packages = {
|
packages = {
|
||||||
jujutsu = ourRustPlatform.buildRustPackage {
|
jujutsu = ourRustPlatform.buildRustPackage {
|
||||||
pname = "jujutsu";
|
pname = "jujutsu";
|
||||||
version = "unstable-${self.shortRev or "dirty"}";
|
version = "unstable-${self.shortRev or "dirty"}";
|
||||||
|
|
||||||
buildFeatures = [ "packaging" ];
|
buildFeatures = ["packaging"];
|
||||||
cargoBuildFlags = [ "--bin" "jj" ]; # don't build and install the fake editors
|
cargoBuildFlags = ["--bin" "jj"]; # don't build and install the fake editors
|
||||||
useNextest = true;
|
useNextest = true;
|
||||||
src = filterSrc ./. [
|
src = filterSrc ./. [
|
||||||
".*\\.nix$"
|
".*\\.nix$"
|
||||||
|
@ -94,32 +102,16 @@
|
||||||
];
|
];
|
||||||
|
|
||||||
cargoLock.lockFile = ./Cargo.lock;
|
cargoLock.lockFile = ./Cargo.lock;
|
||||||
nativeBuildInputs = with pkgs; [
|
nativeBuildInputs = nativeBuildInputs ++ [pkgs.installShellFiles];
|
||||||
gzip
|
inherit buildInputs nativeCheckInputs;
|
||||||
installShellFiles
|
|
||||||
makeWrapper
|
|
||||||
pkg-config
|
|
||||||
|
|
||||||
# for libz-ng-sys (zlib-ng)
|
env =
|
||||||
# TODO: switch to the packaged zlib-ng and drop this dependency
|
env
|
||||||
cmake
|
// {
|
||||||
|
RUSTFLAGS = pkgs.lib.optionalString pkgs.stdenv.isLinux "-C link-arg=-fuse-ld=mold";
|
||||||
# for signing tests
|
NIX_JJ_GIT_HASH = self.rev or "";
|
||||||
gnupg
|
CARGO_INCREMENTAL = "0";
|
||||||
openssh
|
};
|
||||||
] ++ linuxNativeDeps;
|
|
||||||
buildInputs = with pkgs; [
|
|
||||||
openssl libgit2 libssh2
|
|
||||||
] ++ darwinDeps;
|
|
||||||
|
|
||||||
LIBSSH2_SYS_USE_PKG_CONFIG = "1";
|
|
||||||
RUSTFLAGS = pkgs.lib.optionalString pkgs.stdenv.isLinux "-C link-arg=-fuse-ld=mold";
|
|
||||||
NIX_JJ_GIT_HASH = self.rev or "";
|
|
||||||
CARGO_INCREMENTAL = "0";
|
|
||||||
|
|
||||||
preCheck = ''
|
|
||||||
export RUST_BACKTRACE=1
|
|
||||||
'';
|
|
||||||
|
|
||||||
postInstall = ''
|
postInstall = ''
|
||||||
$out/bin/jj util mangen > ./jj.1
|
$out/bin/jj util mangen > ./jj.1
|
||||||
|
@ -141,26 +133,7 @@
|
||||||
default = self.packages.${system}.jujutsu;
|
default = self.packages.${system}.jujutsu;
|
||||||
};
|
};
|
||||||
|
|
||||||
formatter = pkgs.nixpkgs-fmt;
|
devShells.default = let
|
||||||
|
|
||||||
checks.jujutsu = self.packages.${system}.jujutsu.overrideAttrs ({ ... }: {
|
|
||||||
# FIXME (aseipp): when running `nix flake check`, this will override the
|
|
||||||
# main package, and nerf the build and installation phases. this is
|
|
||||||
# because for some inexplicable reason, the cargo cache gets invalidated
|
|
||||||
# in between buildPhase and checkPhase, causing every nix CI build to be
|
|
||||||
# 2x as long.
|
|
||||||
#
|
|
||||||
# upstream issue: https://github.com/NixOS/nixpkgs/issues/291222
|
|
||||||
buildPhase = "true";
|
|
||||||
installPhase = "touch $out";
|
|
||||||
# NOTE (aseipp): buildRustPackage also, by default, runs `cargo check`
|
|
||||||
# in `--release` mode, which is far slower; the existing CI builds all
|
|
||||||
# use the default `test` profile, so we should too.
|
|
||||||
cargoCheckType = "test";
|
|
||||||
});
|
|
||||||
|
|
||||||
devShells.default = pkgs.mkShell {
|
|
||||||
name = "jujutsu";
|
|
||||||
packages = with pkgs; [
|
packages = with pkgs; [
|
||||||
# NOTE (aseipp): explicitly add rust-src to the rustc compiler only in
|
# NOTE (aseipp): explicitly add rust-src to the rustc compiler only in
|
||||||
# devShell. this in turn causes a dependency on the rust compiler src,
|
# devShell. this in turn causes a dependency on the rust compiler src,
|
||||||
|
@ -170,13 +143,9 @@
|
||||||
#
|
#
|
||||||
# relevant PR: https://github.com/rust-lang/rust/pull/129687
|
# relevant PR: https://github.com/rust-lang/rust/pull/129687
|
||||||
(ourRustVersion.override {
|
(ourRustVersion.override {
|
||||||
extensions = [ "rust-src" "rust-analyzer" ];
|
extensions = ["rust-src" "rust-analyzer"];
|
||||||
})
|
})
|
||||||
|
|
||||||
# Foreign dependencies
|
|
||||||
openssl libgit2 libssh2
|
|
||||||
pkg-config
|
|
||||||
|
|
||||||
# Additional tools recommended by contributing.md
|
# Additional tools recommended by contributing.md
|
||||||
bacon
|
bacon
|
||||||
cargo-deny
|
cargo-deny
|
||||||
|
@ -189,24 +158,40 @@
|
||||||
# In case you need to run `cargo run --bin gen-protos`
|
# In case you need to run `cargo run --bin gen-protos`
|
||||||
protobuf
|
protobuf
|
||||||
|
|
||||||
# for libz-ng-sys (zlib-ng)
|
|
||||||
# TODO: switch to the packaged zlib-ng and drop this dependency
|
|
||||||
cmake
|
|
||||||
|
|
||||||
# To run the signing tests
|
|
||||||
gnupg
|
|
||||||
openssh
|
|
||||||
|
|
||||||
# For building the documentation website
|
# For building the documentation website
|
||||||
uv
|
uv
|
||||||
] ++ darwinDeps ++ linuxNativeDeps;
|
];
|
||||||
|
|
||||||
shellHook = ''
|
# on macOS and Linux, use faster parallel linkers that are much more
|
||||||
export RUST_BACKTRACE=1
|
# efficient than the defaults. these noticeably improve link time even for
|
||||||
export LIBSSH2_SYS_USE_PKG_CONFIG=1
|
# 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 [];
|
||||||
|
|
||||||
export RUSTFLAGS="-Zthreads=0 ${rustLinkFlagsString}"
|
rustLinkFlagsString =
|
||||||
'';
|
pkgs.lib.concatStringsSep " "
|
||||||
};
|
(pkgs.lib.concatMap (x: ["-C" "link-arg=${x}"]) rustLinkerFlags);
|
||||||
|
|
||||||
|
devShellEnv = {
|
||||||
|
RUSTFLAGS = "-Zthreads=0 ${rustLinkFlagsString}";
|
||||||
|
};
|
||||||
|
in
|
||||||
|
pkgs.mkShell {
|
||||||
|
name = "jujutsu";
|
||||||
|
packages = packages ++ nativeBuildInputs ++ buildInputs ++ nativeCheckInputs;
|
||||||
|
env = env // devShellEnv;
|
||||||
|
};
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue