25 , enableMinimal ? false
29 inherit (lib.importJSON ./deps.json) links version versionHash;
30 # Sapling sets a Cargo config containing lines like so:
31 # [target.aarch64-apple-darwin]
32 # rustflags = ["-C", "link-args=-Wl,-undefined,dynamic_lookup"]
34 # The default cargo config that's set by the build hook will set
35 # unstable.host-config and unstable.target-applies-to-host which seems to
36 # result in the link arguments above being ignored and thus link failures.
37 # All it is there to do anyway is just to do stuff with musl and cross
38 # compilation, which doesn't work on macOS anyway so we can just stub it
41 # See https://github.com/NixOS/nixpkgs/pull/198311#issuecomment-1326894295
42 myCargoSetupHook = rustPlatform.cargoSetupHook.overrideAttrs (old: {
43 cargoConfig = lib.optionalString (!stdenv.hostPlatform.isDarwin) old.cargoConfig;
46 src = fetchFromGitHub {
50 hash = "sha256-4pOpJ91esTSH90MvvMu74CnlLULLUawqxcniUeqnLwA=";
53 addonsSrc = "${src}/addons";
55 # Fetches the Yarn modules in Nix to to be used as an offline cache
56 yarnOfflineCache = fetchYarnDeps {
57 yarnLock = "${addonsSrc}/yarn.lock";
58 sha256 = "sha256-jCtrflwDrwql6rY1ff1eXLKdwmnXhg5bCJPlCczBCIk=";
61 # Builds the NodeJS server that runs with `sl web`
62 isl = stdenv.mkDerivation {
63 pname = "sapling-isl";
76 export HOME=$(mktemp -d)
77 fixup-yarn-lock yarn.lock
78 yarn config --offline set yarn-offline-mirror ${yarnOfflineCache}
79 yarn install --offline --frozen-lockfile --ignore-engines --ignore-scripts --no-progress
80 patchShebangs node_modules
81 patchShebangs isl/node_modules
83 substituteInPlace build-tar.py \
84 --replace-fail 'run(yarn + ["--cwd", src_join(), "install", "--prefer-offline"])' 'pass'
86 ${python311Packages.python}/bin/python3 build-tar.py \
87 --output isl-dist.tar.xz \
88 --yarn 'yarn --offline --frozen-lockfile --ignore-engines --ignore-scripts --no-progress'
97 install isl-dist.tar.xz $out/isl-dist.tar.xz
103 # Builds the main `sl` binary and its Python extensions
104 python311Packages.buildPythonApplication {
108 sourceRoot = "${src.name}/eden/scm";
110 # Upstream does not commit Cargo.lock
111 cargoDeps = rustPlatform.importCargoLock {
112 lockFile = ./Cargo.lock;
114 "abomonation-0.7.3+smallvec1" = "sha256-AxEXR6GC8gHjycIPOfoViP7KceM29p2ZISIt4iwJzvM=";
115 "cloned-0.1.0" = "sha256-2BaNR/pQmR7pHtRf6VBQLcZgLHbj2JCxeX4auAB0efU=";
116 "fb303_core-0.0.0" = "sha256-PDGdKjR6KPv1uH1JSTeoG5Rs0ZkmNJLqqSXtvV3RWic=";
117 "fbthrift-0.0.1+unstable" = "sha256-J4REXGuLjHyN3SHilSWhMoqpRcn1QnEtsTsZF4Z3feU=";
118 "serde_bser-0.4.0" = "sha256-Su1IP3NzQu/87p/+uQaG8JcICL9hit3OV1O9oFiACsQ=";
122 cp ${./Cargo.lock} Cargo.lock
123 '' + lib.optionalString (!enableMinimal) ''
124 # If asked, we optionally patch in a hardcoded path to the
125 # 'nodejs' package, so that 'sl web' always works. Without the
126 # patch, 'sl web' will still work if 'nodejs' is in $PATH.
127 substituteInPlace lib/config/loader/src/builtin_static/core.rs \
128 --replace '"#);' $'[web]\nnode-path=${nodejs}/bin/node\n"#);'
131 # Since the derivation builder doesn't have network access to remain pure,
132 # fetch the artifacts manually and link them. Then replace the hardcoded URLs
133 # with filesystem paths for the curl calls.
135 mkdir $sourceRoot/hack_pydeps
136 ${lib.concatStrings (map (li: "ln -s ${fetchurl li} $sourceRoot/hack_pydeps/${baseNameOf li.url}\n") links)}
137 sed -i "s|https://files.pythonhosted.org/packages/[[:alnum:]]*/[[:alnum:]]*/[[:alnum:]]*/|file://$NIX_BUILD_TOP/$sourceRoot/hack_pydeps/|g" $sourceRoot/setup.py
141 install ${isl}/isl-dist.tar.xz $out/lib/isl-dist.tar.xz
144 postFixup = lib.optionalString stdenv.hostPlatform.isLinux ''
145 wrapProgram $out/bin/sl \
146 --set LOCALE_ARCHIVE "${glibcLocales}/lib/locale/locale-archive"
149 nativeBuildInputs = [
159 ] ++ lib.optionals stdenv.hostPlatform.isDarwin [
171 SAPLING_OSS_BUILD = "true";
172 SAPLING_VERSION_HASH = versionHash;
174 # Python setuptools version 66 and newer does not support upstream Sapling's
175 # version numbers (e.g. "0.2.20230124-180750-hf8cd450a"). Change the version
176 # number to something supported by setuptools (e.g. "0.2.20230124").
177 # https://github.com/facebook/sapling/issues/571
178 SAPLING_VERSION = builtins.elemAt (builtins.split "-" version) 0;
180 # just a simple check phase, until we have a running test suite. this should
181 # help catch issues like lack of a LOCALE_ARCHIVE setting (see GH PR #202760)
183 installCheckPhase = ''
184 echo -n "testing sapling version; should be \"$SAPLING_VERSION\"... "
185 $out/bin/sl version | grep -qw "$SAPLING_VERSION"
189 # Expose isl to nix repl as sapling.isl.
193 description = "Scalable, User-Friendly Source Control System";
194 homepage = "https://sapling-scm.com";
195 license = licenses.gpl2Only;
196 maintainers = with maintainers; [ pbar thoughtpolice ];
197 platforms = platforms.unix;