2022-11-25 00:14:43 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
2023-01-14 23:48:31 +00:00
|
|
|
, python3Packages
|
2022-11-25 00:14:43 +00:00
|
|
|
, fetchFromGitHub
|
|
|
|
, fetchurl
|
|
|
|
, sd
|
|
|
|
, curl
|
|
|
|
, pkg-config
|
|
|
|
, openssl
|
|
|
|
, rustPlatform
|
|
|
|
, fetchYarnDeps
|
|
|
|
, yarn
|
|
|
|
, nodejs
|
|
|
|
, fixup_yarn_lock
|
|
|
|
, glibcLocales
|
|
|
|
, libiconv
|
|
|
|
, CoreFoundation
|
|
|
|
, CoreServices
|
|
|
|
, Security
|
2022-12-09 15:22:19 +00:00
|
|
|
|
|
|
|
, enableMinimal ? false
|
2022-11-25 00:14:43 +00:00
|
|
|
}:
|
2022-11-24 06:58:03 +00:00
|
|
|
|
|
|
|
let
|
2022-11-24 12:00:00 +00:00
|
|
|
inherit (lib.importJSON ./deps.json) links version versionHash;
|
2022-11-25 00:14:43 +00:00
|
|
|
# Sapling sets a Cargo config containing lines like so:
|
|
|
|
# [target.aarch64-apple-darwin]
|
|
|
|
# rustflags = ["-C", "link-args=-Wl,-undefined,dynamic_lookup"]
|
|
|
|
#
|
|
|
|
# The default cargo config that's set by the build hook will set
|
|
|
|
# unstable.host-config and unstable.target-applies-to-host which seems to
|
|
|
|
# result in the link arguments above being ignored and thus link failures.
|
|
|
|
# All it is there to do anyway is just to do stuff with musl and cross
|
|
|
|
# compilation, which doesn't work on macOS anyway so we can just stub it
|
|
|
|
# on macOS.
|
|
|
|
#
|
|
|
|
# See https://github.com/NixOS/nixpkgs/pull/198311#issuecomment-1326894295
|
|
|
|
myCargoSetupHook = rustPlatform.cargoSetupHook.overrideAttrs (old: {
|
|
|
|
cargoConfig = if stdenv.isDarwin then "" else old.cargoConfig;
|
|
|
|
});
|
2022-11-24 06:58:03 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "facebook";
|
|
|
|
repo = "sapling";
|
|
|
|
rev = version;
|
2023-03-05 10:06:17 +00:00
|
|
|
hash = "sha256-e+S5gyyJF3bu6Yo+KjG2lLfjToYzzFj10GTcrPfzxDE=";
|
2022-11-24 06:58:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
addonsSrc = "${src}/addons";
|
|
|
|
|
|
|
|
# Fetches the Yarn modules in Nix to to be used as an offline cache
|
|
|
|
yarnOfflineCache = fetchYarnDeps {
|
|
|
|
yarnLock = "${addonsSrc}/yarn.lock";
|
2023-03-05 10:06:17 +00:00
|
|
|
sha256 = "sha256-bJpfa1i3G5Ym5CLVpCt+7q5FNv34CoJBefXaf4qlxNA=";
|
2022-11-24 06:58:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
# Builds the NodeJS server that runs with `sl web`
|
|
|
|
isl = stdenv.mkDerivation {
|
|
|
|
pname = "sapling-isl";
|
|
|
|
src = addonsSrc;
|
|
|
|
inherit version;
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
|
|
|
fixup_yarn_lock
|
|
|
|
nodejs
|
|
|
|
yarn
|
|
|
|
];
|
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
|
|
|
|
|
|
|
export HOME=$(mktemp -d)
|
|
|
|
fixup_yarn_lock yarn.lock
|
|
|
|
yarn config --offline set yarn-offline-mirror ${yarnOfflineCache}
|
|
|
|
yarn install --offline --frozen-lockfile --ignore-engines --ignore-scripts --no-progress
|
|
|
|
patchShebangs node_modules
|
|
|
|
|
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
|
|
|
|
|
|
|
mkdir -p $out
|
|
|
|
cd isl
|
|
|
|
node release.js $out
|
|
|
|
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
in
|
2023-01-15 01:20:58 +00:00
|
|
|
# Builds the main `sl` binary and its Python extensions
|
|
|
|
python3Packages.buildPythonApplication {
|
2022-11-24 06:58:03 +00:00
|
|
|
pname = "sapling";
|
2023-01-15 01:20:58 +00:00
|
|
|
inherit src version;
|
|
|
|
|
|
|
|
sourceRoot = "source/eden/scm";
|
|
|
|
|
|
|
|
# Upstream does not commit Cargo.lock
|
|
|
|
cargoDeps = rustPlatform.importCargoLock {
|
|
|
|
lockFile = ./Cargo.lock;
|
|
|
|
outputHashes = {
|
2023-02-07 09:16:43 +00:00
|
|
|
"abomonation-0.7.3+smallvec1" = "sha256-AxEXR6GC8gHjycIPOfoViP7KceM29p2ZISIt4iwJzvM=";
|
2023-03-05 10:06:17 +00:00
|
|
|
"cloned-0.1.0" = "sha256-WHsvgnbAYrFx22p3rbMzlCIaZ8+BTsMswiTv4h+A/ZI=";
|
|
|
|
"fb303_core-0.0.0" = "sha256-bg4+4kdHfgaEbLzkCftdLH++QKherIAfM7IzlWeOWKI=";
|
|
|
|
"fbthrift-0.0.1+unstable" = "sha256-0qvab0a3PdvlOq2teXKjYrB9UbWLKzMbHgv/3LSsT+4=";
|
2023-01-15 01:20:58 +00:00
|
|
|
"reqwest-0.11.11" = "sha256-uhc8XhkGW22XDNo0qreWdXeFF2cslOOZHfTRQ30IBcE=";
|
2023-03-05 10:06:17 +00:00
|
|
|
"serde_bser-0.3.1" = "sha256-Sk3prRcLr2ExXvq7Px4+NRXbY8ZaRWOYexnaUAqQ4ao=";
|
2023-01-15 01:20:58 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
postPatch = ''
|
|
|
|
cp ${./Cargo.lock} Cargo.lock
|
|
|
|
'';
|
2022-11-24 06:58:03 +00:00
|
|
|
|
2023-01-15 01:20:58 +00:00
|
|
|
# Since the derivation builder doesn't have network access to remain pure,
|
|
|
|
# fetch the artifacts manually and link them. Then replace the hardcoded URLs
|
|
|
|
# with filesystem paths for the curl calls.
|
|
|
|
postUnpack = ''
|
|
|
|
mkdir $sourceRoot/hack_pydeps
|
|
|
|
${lib.concatStrings (map (li: "ln -s ${fetchurl li} $sourceRoot/hack_pydeps/${baseNameOf li.url}\n") links)}
|
|
|
|
sed -i "s|https://files.pythonhosted.org/packages/[[:alnum:]]*/[[:alnum:]]*/[[:alnum:]]*/|file://$NIX_BUILD_TOP/$sourceRoot/hack_pydeps/|g" $sourceRoot/setup.py
|
|
|
|
'';
|
2022-11-24 06:58:03 +00:00
|
|
|
|
2023-01-15 01:20:58 +00:00
|
|
|
# Now, copy the "sl web" (aka edenscm-isl) results into the output of this
|
|
|
|
# package, so that the command can actually work. NOTES:
|
|
|
|
#
|
|
|
|
# 1) This applies on all systems (so no conditional a la postFixup)
|
|
|
|
# 2) This doesn't require any kind of fixup itself, so we leave it out
|
|
|
|
# of postFixup for that reason, too
|
|
|
|
# 3) If asked, we optionally patch in a hardcoded path to the 'nodejs' package,
|
|
|
|
# so that 'sl web' always works
|
|
|
|
# 4) 'sl web' will still work if 'nodejs' is in $PATH, just not OOTB
|
|
|
|
preFixup = ''
|
|
|
|
sitepackages=$out/lib/${python3Packages.python.libPrefix}/site-packages
|
|
|
|
chmod +w $sitepackages
|
|
|
|
cp -r ${isl} $sitepackages/edenscm-isl
|
|
|
|
'' + lib.optionalString (!enableMinimal) ''
|
|
|
|
chmod +w $sitepackages/edenscm-isl/run-isl
|
|
|
|
substituteInPlace $sitepackages/edenscm-isl/run-isl \
|
|
|
|
--replace 'NODE=node' 'NODE=${nodejs}/bin/node'
|
|
|
|
'';
|
2022-11-24 06:58:03 +00:00
|
|
|
|
2023-01-15 01:20:58 +00:00
|
|
|
postFixup = lib.optionalString stdenv.isLinux ''
|
|
|
|
wrapProgram $out/bin/sl \
|
|
|
|
--set LOCALE_ARCHIVE "${glibcLocales}/lib/locale/locale-archive"
|
2022-11-24 06:58:03 +00:00
|
|
|
'';
|
|
|
|
|
2023-01-15 01:20:58 +00:00
|
|
|
nativeBuildInputs = [
|
|
|
|
curl
|
|
|
|
pkg-config
|
|
|
|
] ++ (with rustPlatform; [
|
|
|
|
myCargoSetupHook
|
|
|
|
rust.cargo
|
|
|
|
rust.rustc
|
|
|
|
]);
|
|
|
|
|
|
|
|
buildInputs = [
|
|
|
|
openssl
|
|
|
|
] ++ lib.optionals stdenv.isDarwin [
|
|
|
|
curl
|
|
|
|
libiconv
|
|
|
|
CoreFoundation
|
|
|
|
CoreServices
|
|
|
|
Security
|
|
|
|
];
|
|
|
|
|
|
|
|
HGNAME = "sl";
|
|
|
|
SAPLING_OSS_BUILD = "true";
|
|
|
|
SAPLING_VERSION_HASH = versionHash;
|
|
|
|
|
2023-03-18 07:53:44 +00:00
|
|
|
# Python setuptools version 66 and newer does not support upstream Sapling's
|
|
|
|
# version numbers (e.g. "0.2.20230124-180750-hf8cd450a"). Change the version
|
|
|
|
# number to something supported by setuptools (e.g. "0.2.20230124").
|
|
|
|
# https://github.com/facebook/sapling/issues/571
|
|
|
|
SAPLING_VERSION = builtins.elemAt (builtins.split "-" version) 0;
|
|
|
|
|
2022-11-25 02:40:37 +00:00
|
|
|
# just a simple check phase, until we have a running test suite. this should
|
|
|
|
# help catch issues like lack of a LOCALE_ARCHIVE setting (see GH PR #202760)
|
|
|
|
doCheck = true;
|
2023-01-15 01:20:58 +00:00
|
|
|
installCheckPhase = ''
|
2023-03-18 07:53:44 +00:00
|
|
|
echo -n "testing sapling version; should be \"$SAPLING_VERSION\"... "
|
|
|
|
$out/bin/sl version | grep -qw "$SAPLING_VERSION"
|
2022-11-25 02:40:37 +00:00
|
|
|
echo "OK!"
|
|
|
|
'';
|
|
|
|
|
2022-11-24 06:58:03 +00:00
|
|
|
meta = with lib; {
|
|
|
|
description = "A Scalable, User-Friendly Source Control System";
|
|
|
|
homepage = "https://sapling-scm.com";
|
|
|
|
license = licenses.gpl2Only;
|
2022-11-25 02:01:33 +00:00
|
|
|
maintainers = with maintainers; [ pbar thoughtpolice ];
|
2022-11-25 00:14:43 +00:00
|
|
|
platforms = platforms.unix;
|
2022-11-24 06:58:03 +00:00
|
|
|
mainProgram = "sl";
|
|
|
|
};
|
|
|
|
}
|