Skip to content

InitCache should not be called for completion commands #535

@NickLarsenNZ

Description

@NickLarsenNZ

I notice that my nix build of replicated now breaks as it tries to generate the completions.

The error can be replicated like so:

HOME=/invalid replicated completion zsh
panic: failed to save cache: failed to create cache directory: mkdir /invalid: permission denied

goroutine 1 [running]:
github.com/replicatedhq/replicated/cli/cmd.init.0()
	/mnt/cli/cmd/root.go:48 +0xe5

For now, I am setting HOME=/tmp during the build.

Whole nix script
{ stdenv
, lib
, fetchurl
, installShellFiles
#, autoPatchelfHook
}:

stdenv.mkDerivation rec {
  pname = "replicated";
  version = "0.101.0";

  src = fetchurl {
    url = "https://github.com/replicatedhq/replicated/releases/download/v${version}/replicated_${version}_linux_amd64.tar.gz";
    hash = "sha256-5i4ri2pBfpbqlMd6v5JVGwsnkN0cvoa+ul04K4xCfJk=";
  };

  nativeBuildInputs = [
    # autoPatchelfHook
    installShellFiles
  ];

  buildInputs = [
  ];

  sourceRoot = ".";

  installPhase = ''
    runHook preInstall
    install -m755 -D replicated $out/bin/replicated
    # Because cache is initialized and tries to write to HOME
    export HOME=/tmp
    installShellCompletion --cmd replicated \
      --bash <($out/bin/replicated completion bash) \
      --fish <($out/bin/replicated completion fish) \
      --zsh <($out/bin/replicated completion zsh)
    runHook postInstall
  '';

  meta = with lib; {
    homepage = "https://replicated.com";
    description = "Replicated CLI";
    platforms = platforms.linux;
  };
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions