这是indexloc提供的服务,不要输入任何密码
Skip to content

wrap with FHS for subcommands that run embedded executable #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 5 additions & 39 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 38 additions & 37 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,48 @@
description = "Hasura DDN CLI";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};

outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachSystem [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" ]
(system:
let
pkgs = import nixpkgs {
inherit system;
config.allowUnfree = true;
};

binary-url-pattern = "https://graphql-engine-cdn.hasura.io/ddn/cli/v4/VERSION/cli-ddn-PLATFORM-ARCH";
in
{
packages = rec {
ddn = pkgs.callPackage ./packages/ddn.nix { inherit binary-url-pattern; };
default = ddn;
outputs = { self, nixpkgs }:
let
systems = [
"x86_64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
mkPkgs = system: import nixpkgs {
inherit system;
config.allowUnfree = true;
};
eachSystem = callback: nixpkgs.lib.genAttrs systems (system: callback (mkPkgs system));
binary-url-pattern = "https://graphql-engine-cdn.hasura.io/ddn/cli/v4/VERSION/cli-ddn-PLATFORM-ARCH";
in
{
packages = eachSystem (pkgs: rec {
default = ddn;
ddn = pkgs.callPackage ./packages/ddn.nix { inherit binary-url-pattern; };

update = pkgs.writeShellApplication {
name = "update";
runtimeInputs = with pkgs; [
coreutils
curl
gnugrep
jq
];
text = ''
BINARY_URL_PATTERN='${binary-url-pattern}'
${builtins.readFile ./scripts/update.sh}
'';
};
};
update = pkgs.writeShellApplication {
name = "update";
runtimeInputs = with pkgs; [
coreutils
curl
gnugrep
jq
];
text = ''
BINARY_URL_PATTERN='${binary-url-pattern}'
${builtins.readFile ./scripts/update.sh}
'';
};
});

checks = {
default = pkgs.callPackage ./packages/check.nix {
ddn = self.packages.${system}.ddn;
};
};
}) // {
checks = eachSystem (pkgs: {
default = pkgs.callPackage ./packages/check.nix {
ddn = self.packages.${pkgs.system}.ddn;
};
});

overlays.default = final: prev: {
ddn = self.packages.${final.system}.default;
Expand Down
60 changes: 35 additions & 25 deletions packages/ddn.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{ hostPlatform
{ binary-url-pattern
, buildFHSEnv
, fetchurl
, stdenvNoCC
, lib
, binary-url-pattern
}:
let
version = "v2.29.0";
Expand All @@ -25,27 +23,39 @@ let
url = src-url version system;
hash = hash (go-system system);
};
in
stdenvNoCC.mkDerivation {
name = "ddn";
inherit version;
src = src hostPlatform.system;
phases = [ "installPhase" "patchPhase" ];
installPhase = ''
mkdir -p "$out/bin"
cp $src "$out/bin/ddn"
chmod +x "$out/bin/ddn"
'';

meta = {
description = "CLI for managing Hasura DDN data graphs";
homepage = "https://hasura.io/docs/3.0/cli/overview/";
license = lib.licenses.unfreeRedistributable;
mainProgram = "ddn";
platforms = [
"x86_64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
# This function defines a package containing the DDN CLI binary, and nothing
# else.
ddn-unwrapped = { lib, hostPlatform, stdenvNoCC }: stdenvNoCC.mkDerivation {
name = "ddn-unwrapped";
inherit version;
src = src hostPlatform.system;
phases = [ "installPhase" "patchPhase" ];
installPhase = ''
mkdir -p "$out/bin"
cp "$src" "$out/bin/ddn"
chmod +x "$out/bin/ddn"
'';

meta = {
description = "CLI for managing Hasura DDN data graphs";
homepage = "https://hasura.io/docs/3.0/cli/overview/";
license = lib.licenses.unfreeRedistributable;
mainProgram = "ddn";
platforms = [
"x86_64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
};
};
in
# The CLI binary is statically-linked, but it contains an embedded executable
# that is dynamically-linked, and requires /lib64/ld-linux-x86-64.so.2. So we
# need to build an FHS wrapper to provide the necessary interpreter at the
# expected path.
buildFHSEnv {
name = "ddn";
targetPkgs = pkgs: [ (pkgs.callPackage ddn-unwrapped { }) ];
runScript = "ddn";
}
Loading