26 , enableMinimal ? false
30 inherit (lib.importJSON ./deps.json) links version versionHash;
31 # Sapling sets a Cargo config containing lines like so:
32 # [target.aarch64-apple-darwin]
33 # rustflags = ["-C", "link-args=-Wl,-undefined,dynamic_lookup"]
35 # The default cargo config that's set by the build hook will set
36 # unstable.host-config and unstable.target-applies-to-host which seems to
37 # result in the link arguments above being ignored and thus link failures.
38 # All it is there to do anyway is just to do stuff with musl and cross
39 # compilation, which doesn't work on macOS anyway so we can just stub it
42 # See https://github.com/NixOS/nixpkgs/pull/198311#issuecomment-1326894295
43 myCargoSetupHook = rustPlatform.cargoSetupHook.overrideAttrs (old: {
44 cargoConfig = lib.optionalString (!stdenv.isDarwin) old.cargoConfig;
47 src = fetchFromGitHub {
51 hash = "sha256-uzev4x9jY6foop35z4dvUMIfjRtRqhNFDVFpagOosAc";
54 addonsSrc = "${src}/addons";
56 # Fetches the Yarn modules in Nix to to be used as an offline cache
57 yarnOfflineCache = fetchYarnDeps {
58 yarnLock = "${addonsSrc}/yarn.lock";
59 sha256 = "sha256-3JFrVk78EiNVLLXkCFbuRnXwYHNfVv1pBPBS1yCHtPU";
62 # Builds the NodeJS server that runs with `sl web`
63 isl = stdenv.mkDerivation {
64 pname = "sapling-isl";
77 export HOME=$(mktemp -d)
78 fixup-yarn-lock yarn.lock
79 yarn config --offline set yarn-offline-mirror ${yarnOfflineCache}
80 yarn install --offline --frozen-lockfile --ignore-engines --ignore-scripts --no-progress
81 patchShebangs node_modules
83 # TODO: build-tar.py tries to run 'yarn install'. We patched
84 # shebangs node_modules, so we don't want 'yarn install'
85 # changing files. We should disable the 'yarn install' in
86 # build-tar.py to be safe.
87 ${python3Packages.python}/bin/python3 build-tar.py \
88 --output isl-dist.tar.xz \
89 --yarn 'yarn --offline --frozen-lockfile --ignore-engines --ignore-scripts --no-progress'
98 install isl-dist.tar.xz $out/isl-dist.tar.xz
104 # Builds the main `sl` binary and its Python extensions
105 python3Packages.buildPythonApplication {
109 sourceRoot = "${src.name}/eden/scm";
111 # Upstream does not commit Cargo.lock
112 cargoDeps = rustPlatform.importCargoLock {
113 lockFile = ./Cargo.lock;
115 "abomonation-0.7.3+smallvec1" = "sha256-AxEXR6GC8gHjycIPOfoViP7KceM29p2ZISIt4iwJzvM=";
116 "cloned-0.1.0" = "sha256-mzAqjM8qovZAd4ZF0GDuD0Ns/UztAO1pAJhukuKc5a0=";
117 "fb303_core-0.0.0" = "sha256-x8I0Lty+sRclpkNMqTMc29J46z/vMsVwOUS3EX7Shes=";
118 "fbthrift-0.0.1+unstable" = "sha256-yTS1wkh8tETZ4K43V0G+TbkN5jgSlXT0endDPBHa1Ps=";
119 "serde_bser-0.3.1" = "sha256-vvMCa6mlcr+xazxZVl2bcF8/r+ufzZmiQ79KofZGWrA=";
123 cp ${./Cargo.lock} Cargo.lock
124 '' + lib.optionalString (!enableMinimal) ''
125 # If asked, we optionally patch in a hardcoded path to the
126 # 'nodejs' package, so that 'sl web' always works. Without the
127 # patch, 'sl web' will still work if 'nodejs' is in $PATH.
128 substituteInPlace lib/config/loader/src/builtin_static/core.rs \
129 --replace '"#);' $'[web]\nnode-path=${nodejs}/bin/node\n"#);'
132 # Since the derivation builder doesn't have network access to remain pure,
133 # fetch the artifacts manually and link them. Then replace the hardcoded URLs
134 # with filesystem paths for the curl calls.
136 mkdir $sourceRoot/hack_pydeps
137 ${lib.concatStrings (map (li: "ln -s ${fetchurl li} $sourceRoot/hack_pydeps/${baseNameOf li.url}\n") links)}
138 sed -i "s|https://files.pythonhosted.org/packages/[[:alnum:]]*/[[:alnum:]]*/[[:alnum:]]*/|file://$NIX_BUILD_TOP/$sourceRoot/hack_pydeps/|g" $sourceRoot/setup.py
142 install ${isl}/isl-dist.tar.xz $out/lib/isl-dist.tar.xz
145 postFixup = lib.optionalString stdenv.isLinux ''
146 wrapProgram $out/bin/sl \
147 --set LOCALE_ARCHIVE "${glibcLocales}/lib/locale/locale-archive"
150 nativeBuildInputs = [
160 ] ++ lib.optionals stdenv.isDarwin [
172 SAPLING_OSS_BUILD = "true";
173 SAPLING_VERSION_HASH = versionHash;
175 # Python setuptools version 66 and newer does not support upstream Sapling's
176 # version numbers (e.g. "0.2.20230124-180750-hf8cd450a"). Change the version
177 # number to something supported by setuptools (e.g. "0.2.20230124").
178 # https://github.com/facebook/sapling/issues/571
179 SAPLING_VERSION = builtins.elemAt (builtins.split "-" version) 0;
181 # just a simple check phase, until we have a running test suite. this should
182 # help catch issues like lack of a LOCALE_ARCHIVE setting (see GH PR #202760)
184 installCheckPhase = ''
185 echo -n "testing sapling version; should be \"$SAPLING_VERSION\"... "
186 $out/bin/sl version | grep -qw "$SAPLING_VERSION"
190 # Expose isl to nix repl as sapling.isl.
194 description = "A Scalable, User-Friendly Source Control System";
195 homepage = "https://sapling-scm.com";
196 license = licenses.gpl2Only;
197 maintainers = with maintainers; [ pbar thoughtpolice ];
198 platforms = platforms.unix;