Skip to content
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

rclone: install completions #79062

Merged
merged 1 commit into from Mar 5, 2020
Merged

rclone: install completions #79062

merged 1 commit into from Mar 5, 2020

Conversation

marsam
Copy link
Contributor

@marsam marsam commented Feb 2, 2020

Motivation for this change

Release notes: https://forum.rclone.org/t/rclone-1-51-release/14114

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

Copy link
Contributor

@danielfullmer danielfullmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing $bin/bin/rclone in postInstall would break cross compilation. Consider these changes:
I've tested these changes by building rclone and also pkgsCross.aarch64-multiplatform.rclone

--- a/pkgs/applications/networking/sync/rclone/default.nix
+++ b/pkgs/applications/networking/sync/rclone/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, buildGoPackage, fetchFromGitHub }:
+{ stdenv, buildGoPackage, fetchFromGitHub, buildPackages }:
 
 buildGoPackage rec {
   pname = "rclone";
@@ -17,11 +17,15 @@ buildGoPackage rec {
 
   outputs = [ "bin" "out" "man" ];
 
-  postInstall = ''
+  postInstall = let
+    rcloneBin = if (stdenv.buildPlatform == stdenv.hostPlatform)
+                then "$bin"
+                else (stdenv.lib.getBin buildPackages.rclone);
+  in ''
     install -D -m644 $src/rclone.1 $man/share/man/man1/rclone.1
     mkdir -p $bin/share/zsh/site-functions $bin/share/bash-completion/completions/
-    $bin/bin/rclone genautocomplete zsh $bin/share/zsh/site-functions/_rclone
-    $bin/bin/rclone genautocomplete bash $bin/share/bash-completion/completions/rclone.bash
+    ${rcloneBin}/bin/rclone genautocomplete zsh $bin/share/zsh/site-functions/_rclone
+    ${rcloneBin}/bin/rclone genautocomplete bash $bin/share/bash-completion/completions/rclone.bash
   '';
 
   meta = with stdenv.lib; {

Other than that, LGTM

Comment on lines 22 to 24
mkdir -p $bin/share/zsh/site-functions $bin/share/bash-completion/completions/
$bin/bin/rclone genautocomplete zsh $bin/share/zsh/site-functions/_rclone
$bin/bin/rclone genautocomplete bash $bin/share/bash-completion/completions/rclone.bash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you want to use installShellCompletion:

nativeBuildIinputs = [ installShellCompletion ];
$bin/bin/rclone genautocomplete zsh > _rclone
$bin/bin/rclone genautocomplete bash > rclone.bash
installShellCompletion _rclone rclone.bash

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately it does not work with buildGoPackage

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:(

@@ -19,6 +19,9 @@ buildGoPackage rec {

postInstall = ''
install -D -m644 $src/rclone.1 $man/share/man/man1/rclone.1
mkdir -p $bin/share/zsh/site-functions/ $bin/share/bash-completion/completions/
$NIX_BUILD_TOP/go/bin/rclone genautocomplete zsh $bin/share/zsh/site-functions/_rclone
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has the same issue with cross-compilation. $NIX_BUILD_TOP/go/bin/rclone is compiled for the host platform and wouldn't run on the build platform. Building pkgsCross.aarch64-multiplatform.rclone produces this error:

/nix/store/7hqfwijjqda0p0ppdhm0b6i3xg5blgnr-stdenv-linux/setup: line 83: /build/go/bin/rclone: cannot execute binary file: Exec format error

I think you should conditionally use buildPackages.rclone if stdenv.buildPlatform != stdenv.hostPlatform like in the earlier suggested changes. For reference, note the similar code in pkgs/shells/zsh/default.nix for generating autocomplete files in a cross-compatible way.

You can test with nix-build . -A pkgsCross.aarch64-multiplatform.rclone--which doesn't take too long since most dependencies are already in the cache.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late response, I've applied your original suggestion

@marsam marsam changed the title rclone: 1.50.2 -> 1.51.0 rclone: install completions Mar 5, 2020
Copy link
Contributor

@danielfullmer danielfullmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@marsam marsam merged commit 93fd4b7 into NixOS:master Mar 5, 2020
@marsam marsam deleted the update-rclone branch March 5, 2020 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants