Skip to content

Commit f02ea59

Browse files
committed
Build Databricks CLI from source following nixpkgs pattern
Rework the derivation to use buildGoModule + fetchFromGitHub instead of downloading a pre-built binary tarball. This follows the upstream nixpkgs package.nix pattern with version bumped to 0.286.0. Changes: - Build from source with buildGoModule for reproducibility - Add meta.license = lib.licenses.databricks - Add databricks-cli to allowUnfreePredicate in flake.nix - Exclude tools/testmask (new in v0.286.0, not a distributable package) - Skip TestCacheDirEnvVar (fails in nix sandbox, no home directory)
1 parent 695737a commit f02ea59

2 files changed

Lines changed: 71 additions & 15 deletions

File tree

flake.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@
3131
fenix.overlays.default
3232
replit-rtld-loader.overlays.default
3333
];
34-
# replbox has an unfree license
34+
# replbox and databricks-cli have unfree licenses
3535
config.allowUnfreePredicate = pkg: builtins.elem (nixpkgs.lib.getName pkg) [
3636
"@replit/replbox"
37+
"databricks-cli"
3738
];
3839
};
3940

pkgs/modules/databricks-cli/default.nix

Lines changed: 69 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,85 @@
22

33
let
44
version = "0.286.0";
5-
databricks-cli = pkgs.stdenvNoCC.mkDerivation {
5+
databricks-cli = pkgs.buildGoModule {
66
pname = "databricks-cli";
77
inherit version;
88

9-
src = pkgs.fetchurl {
10-
url = "https://github.com/databricks/cli/releases/download/v${version}/databricks_cli_${version}_linux_amd64.tar.gz";
11-
hash = "sha256-lf6q0c9iZVNvIzLVrptTe0YudpFDVDdZXMWR8lOObw8=";
9+
src = pkgs.fetchFromGitHub {
10+
owner = "databricks";
11+
repo = "cli";
12+
rev = "v${version}";
13+
hash = "sha256-iCmxHjIYznqed6BMQKtuYHJNFPy+3XrNzSXfhtyzPJk=";
1214
};
1315

14-
sourceRoot = ".";
16+
vendorHash = "sha256-TNUI2VQVKnxTiKQg9Bj3qDK2w3oOjO0rdrtTlFIhTzA=";
1517

16-
dontConfigure = true;
17-
dontBuild = true;
18+
excludedPackages = [
19+
"bundle/internal"
20+
"acceptance"
21+
"integration"
22+
"tools/testrunner"
23+
"tools/testmask"
24+
];
1825

19-
unpackPhase = ''
20-
tar -xzf $src
26+
postPatch = ''
27+
substituteInPlace bundle/deploy/terraform/init_test.go \
28+
--replace-fail "cli/0.0.0-dev" "cli/${version}"
2129
'';
2230

23-
installPhase = ''
24-
runHook preInstall
25-
mkdir -p $out/bin
26-
install -m755 databricks $out/bin/databricks
27-
runHook postInstall
31+
ldflags = [
32+
"-X github.com/databricks/cli/internal/build.buildVersion=${version}"
33+
];
34+
35+
postBuild = ''
36+
mv "$GOPATH/bin/cli" "$GOPATH/bin/databricks"
2837
'';
38+
39+
checkFlags =
40+
"-skip="
41+
+ (lib.concatStringsSep "|" [
42+
# Need network
43+
"TestConsistentDatabricksSdkVersion"
44+
"TestTerraformArchiveChecksums"
45+
"TestExpandPipelineGlobPaths"
46+
"TestRelativePathTranslationDefault"
47+
"TestRelativePathTranslationOverride"
48+
"TestWorkspaceVerifyProfileForHost"
49+
"TestWorkspaceVerifyProfileForHost/default_config_file_with_match"
50+
"TestWorkspaceResolveProfileFromHost"
51+
"TestWorkspaceResolveProfileFromHost/no_config_file"
52+
"TestBundleConfigureDefault"
53+
# Use uv venv which doesn't work with nix
54+
# https://github.com/astral-sh/uv/issues/4450
55+
"TestVenvSuccess"
56+
"TestPatchWheel"
57+
# Fails in nix sandbox due to missing home/cache directory
58+
"TestCacheDirEnvVar"
59+
]);
60+
61+
nativeCheckInputs = [
62+
pkgs.gitMinimal
63+
(pkgs.python3.withPackages (
64+
ps: with ps; [
65+
setuptools
66+
wheel
67+
]
68+
))
69+
];
70+
71+
preCheck = ''
72+
# Some tests depend on git and remote url
73+
git init
74+
git remote add origin https://github.com/databricks/cli.git
75+
'';
76+
77+
meta = {
78+
description = "Databricks CLI";
79+
mainProgram = "databricks";
80+
homepage = "https://github.com/databricks/cli";
81+
changelog = "https://github.com/databricks/cli/releases/tag/v${version}";
82+
license = lib.licenses.databricks;
83+
};
2984
};
3085
in
3186
{

0 commit comments

Comments
 (0)