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

slack-cli: init at 0.18.0 #45055

Merged
merged 9 commits into from Aug 15, 2018
Merged

slack-cli: init at 0.18.0 #45055

merged 9 commits into from Aug 15, 2018

Conversation

alyssais
Copy link
Member

  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • 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 nox --run "nox-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)
  • Fits CONTRIBUTING.md.

slack-cli must be configured using the SLACK_CLI_TOKEN environment variable. Using slack init will not work because it tries to write to the Nix store.

slack-cli must be configured using the SLACK_CLI_TOKEN environment
variable. Using `slack init` will not work because it tries to write to
the Nix store.
version = "0.18.0";

src = fetchurl {
url = "https://github.com/rockymadden/slack-cli/archive/v${version}.tar.gz";
Copy link
Contributor

Choose a reason for hiding this comment

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

Using fetchFromGitHub is preferred I think.

@mpickering
Copy link
Contributor

@GrahamcOfBorg build slack-cli

@GrahamcOfBorg
Copy link

Success on x86_64-darwin (full log)

Attempted: slack-cli

Partial log (click to expand)

patching sources
configuring
no configure script, doing nothing
installing
post-installation fixup
strip is /nix/store/251fvx4mx9q4zarbca5cciasmn66p668-cctools-binutils-darwin/bin/strip
stripping (with command strip and flags -S) in /nix/store/mcf8lgxc2qayz5n60n65cfwv0gd5ryxl-slack-cli/bin
patching script interpreter paths in /nix/store/mcf8lgxc2qayz5n60n65cfwv0gd5ryxl-slack-cli
/nix/store/mcf8lgxc2qayz5n60n65cfwv0gd5ryxl-slack-cli/bin/.slack-wrapped: interpreter directive changed from "/usr/bin/env bash" to "/nix/store/hp9yq2m1i066irvasv20zr2lmj54fk9h-bash-4.4-p23/bin/bash"
/nix/store/mcf8lgxc2qayz5n60n65cfwv0gd5ryxl-slack-cli

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: slack-cli

Partial log (click to expand)

no configure script, doing nothing
installing
post-installation fixup
shrinking RPATHs of ELF executables and libraries in /nix/store/2kzb4cak58krzmp9c55mr7l4m88v09ds-slack-cli
strip is /nix/store/ah0va6j4cnwj9nx4j6rwcfc8nh785jwm-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/2kzb4cak58krzmp9c55mr7l4m88v09ds-slack-cli/bin
patching script interpreter paths in /nix/store/2kzb4cak58krzmp9c55mr7l4m88v09ds-slack-cli
/nix/store/2kzb4cak58krzmp9c55mr7l4m88v09ds-slack-cli/bin/.slack-wrapped: interpreter directive changed from "/usr/bin/env bash" to "/nix/store/7q3ayirslrcva28wava6zpjcflcz1h3b-bash-4.4-p23/bin/bash"
checking for references to /build in /nix/store/2kzb4cak58krzmp9c55mr7l4m88v09ds-slack-cli...
/nix/store/2kzb4cak58krzmp9c55mr7l4m88v09ds-slack-cli

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: slack-cli

Partial log (click to expand)

no configure script, doing nothing
installing
post-installation fixup
shrinking RPATHs of ELF executables and libraries in /nix/store/hh1mgxj8cslswrx7rd3q212v86xwl27v-slack-cli
strip is /nix/store/gpc2wld1s0c6qzx9326cwn1wcx29xzsj-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/hh1mgxj8cslswrx7rd3q212v86xwl27v-slack-cli/bin
patching script interpreter paths in /nix/store/hh1mgxj8cslswrx7rd3q212v86xwl27v-slack-cli
/nix/store/hh1mgxj8cslswrx7rd3q212v86xwl27v-slack-cli/bin/.slack-wrapped: interpreter directive changed from "/usr/bin/env bash" to "/nix/store/56nrxy58wbhvs2sy3rir1jqa68p0kkm5-bash-4.4-p23/bin/bash"
checking for references to /build in /nix/store/hh1mgxj8cslswrx7rd3q212v86xwl27v-slack-cli...
/nix/store/hh1mgxj8cslswrx7rd3q212v86xwl27v-slack-cli

@mpickering
Copy link
Contributor

Thanks, looks fine to me.

@@ -0,0 +1,27 @@
# slack-cli must be configured using the SLACK_CLI_TOKEN environment
# variable. Using `slack init` will not work because it tries to write
# to the Nix store.
Copy link
Member

Choose a reason for hiding this comment

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

Is there a way to work around this? Otherwise we should provide a wrapper script that gives the user instructions. A comment in the .nix file is not easily discoverable by end users.

Copy link
Member Author

Choose a reason for hiding this comment

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

It could be worked around by changing the location it saves to, but then a decision would have to be made where that should be. A wrapper script that warns if the environment variable is not set is a good idea though.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds like that should be in the home directory. Where does it regularly save it?

But either way, your call. I don't use the application. Just silently failing without giving the user a hint for the reason is sub-optimal.

Copy link
Member Author

Choose a reason for hiding this comment

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

It looks like it wants to save it to etc, which seems very odd to me, because then it can't be used by multiple users. I think that changing it only for nixpkgs would be confusing, so I'm going to leave it as-is, since I'm happy using the environment variable. That way if somebody else wants to use the file approach they can change it to be what they think makes sense.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that seems reasonable (unlike the upstream approach of saving user configuration to /etc). But then please add a wrapper that notifies the user and maybe add a comment explaining the alternative solution (in case somebody wants to improve it in the future).

Copy link
Member Author

Choose a reason for hiding this comment

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

Will do.

{ stdenv, lib, fetchFromGitHub, makeWrapper, curl, jq }:

stdenv.mkDerivation rec {
name = "slack-cli";
Copy link
Member

Choose a reason for hiding this comment

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

It is customary to add the version to the name: name = "slack-cli-${version}".

sha256 = "022yr3cpfg0v7cxi62zzk08vp0l3w851qpfh6amyfgjiynnfyddl";
};

buildInputs = [ makeWrapper ];
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't be necessary. The standard build phase uses make, it does not need to be specified as a dependency.


buildInputs = [ makeWrapper ];

dontBuild = true;
Copy link
Member

Choose a reason for hiding this comment

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

Where do you actually use make?

Copy link
Contributor

Choose a reason for hiding this comment

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

The makeWrapper dependency is for the installPhase where wrapProgram is called.

Copy link
Member

Choose a reason for hiding this comment

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

Ooh that is a confusing name. I assumed it was a wrapper for make 😀

It should be a nativeBuildInput then. The difference is that nativeBuildInputs are used exclusively during packaging. The distinction is important for cross-compilation.

Alternatively you could leave it out of any buildInputs and just use ${makeWrapper}/bin/wrapProgram in installPhase.

Copy link
Member Author

Choose a reason for hiding this comment

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

fwiw:

$ git grep -w 'nativeBuildInputs = .*makeWrapper' | wc -l
     444
$ git grep -w 'buildInputs = .*makeWrapper' | wc -l
     474

Copy link
Member Author

@alyssais alyssais Aug 15, 2018

Choose a reason for hiding this comment

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

Alternatively you could leave it out of any buildInputs and just use ${makeWrapper}/bin/wrapProgram in installPhase.

This wouldn't work.

$ nix-shell -p makeWrapper --run 'type -t wrapProgram'
function

Copy link
Member

Choose a reason for hiding this comment

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

fwiw

Yes that is because the distinction is relatively recent, many contributors aren't aware of it and it is not enforced in regular compilation (yet). But the right way to do it is to always put makeWrapper in nativeBuildInputs. Maybe some point in the future we will enforce the distinction for regular compilation.

For example when you want to compile for a raspberry pi on your regular x86 desktop, you will need a x86 version of makeWrapper but aarch versions of all the runtime dependencies.

This wouldn't work.

Huh, I wonder how it works when it is in buildInputs. Anyways, that was a misunderstanding on my side. The way you do it currently is fine (except native vs. regular build inputs).

Copy link
Member Author

Choose a reason for hiding this comment

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

Cool, thanks for the explanation :)

dontBuild = true;

installPhase = ''
mkdir -p $out/bin
Copy link
Member

Choose a reason for hiding this comment

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

Please quote shell variables, including $out.

slack-cli = callPackage ../tools/networking/slack-cli { };
wrapSlackCli = callPackage ../tools/networking/slack-cli/wrapper.nix { };
slack-cli-unwrapped = callPackage ../tools/networking/slack-cli { };
slack-cli = wrapSlackCli slack-cli-unwrapped;
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason to add all 3 of these to all-packages.nix?

wrapSlackCli = callPackage ../tools/networking/slack-cli/wrapper.nix { };
slack-cli-unwrapped = callPackage ../tools/networking/slack-cli { };
slack-cli = wrapSlackCli slack-cli-unwrapped;

Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason to add all three of these to all-packages.nix?

Copy link
Member

@infinisil infinisil Aug 15, 2018

Choose a reason for hiding this comment

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

A reason one might prefer a wrapper derivation is when the unwrapped one takes a long time to rebuild but the wrapper should have a quick turnaround time. Changing something in the wrapper doesn't affect the unwrapped one at all and can therefore be very quick.

It's not really needed here, because the unwrapped one is pretty much just a source, the code to wrap it can be put into it directly. So I think this should be changed.

Copy link
Member Author

Choose a reason for hiding this comment

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

@infinisil what do you think of #45055 (comment)?

@@ -12,4 +12,10 @@ writeShellScriptBin "slack" ''

export PATH=${lib.makeBinPath [ curl jq ]}:"$PATH"
exec ${slack-cli}/bin/slack "$@"
''
'') // {
Copy link
Member

Choose a reason for hiding this comment

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

Personally I'd just inline the wrapper into the main package. Any reason you chose this approach?

Copy link
Member Author

Choose a reason for hiding this comment

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

There is indeed! See #44102, but the tl;dr is that inlining the wrapper into the main package breaks overrideAttrs, so as a user of the package you can't eg add patches.

Copy link
Member

Choose a reason for hiding this comment

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

It doesn't need to be 2 packages at all: Just "insert" the wrapper into the original derivation like this: ln -s ${wrapper}/bin/slack-cli $out/bin/slack-cli, while moving the original slack-cli binary to $out/bin/.slack-cli-wrapped_

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, I see what you're saying! I'll do that.


export PATH=${lib.makeBinPath [ curl jq ]}:"$PATH"
exec "$(dirname "$0")/.slack-wrapped" "$@"
'';
Copy link
Member

Choose a reason for hiding this comment

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

You can use

let
  wrapper = writeShellScriptBin "slack" ''
    ...
    exec "${slack-cli}/bin/.slack-wrapped"
  '';

  slack-cli = stdenv.mkDerivation rec {
    ...
  };

in slack-cli

(or similar) to not have to use this dirname hack

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried this! (Or something very similar.) It was infinitely recursive though. Was I doing something wrong? It makes sense to me I think – wrapper takes slack-cli's output path as an input, and slack-cli's output path depends on all of its inputs, one of which is wrapper.

Copy link
Member

Choose a reason for hiding this comment

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

Oh.. never mind then, I thought at some point that this should work (through some magic I don't understand myself), but apparently not

Copy link
Member

Choose a reason for hiding this comment

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

I guess what would work, and what a lot of packages do, is to use cat <<-EOF to write the script to $out/bin/foo in installPhase, such that you have access to the $out variable.

Copy link
Member Author

Choose a reason for hiding this comment

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

@infinisil that does work (just pushed), although it puts me in shell-escape hell…

Copy link
Member

Choose a reason for hiding this comment

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

Yeah that is a bit of a disadvantage..

Copy link
Member Author

Choose a reason for hiding this comment

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

What do you think then? I think that, having seen it, I actually prefer this version. Even if it was a bit annoying to write, it’s less hacky.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed!

@timokau
Copy link
Member

timokau commented Aug 15, 2018

LGTM, merge pending ofBorg's approval.
@GrahamcOfBorg build slack-cli

Thank you for packaging this and responding to the many nitpicks. Always happy to see a new entry in maintainers.nix :)

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: slack-cli

Partial log (click to expand)

no configure script, doing nothing
installing
post-installation fixup
shrinking RPATHs of ELF executables and libraries in /nix/store/rbv0mlpq1a9769vyjkj8lygyg7mdbjlf-slack-cli-0.18.0
strip is /nix/store/gpc2wld1s0c6qzx9326cwn1wcx29xzsj-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/rbv0mlpq1a9769vyjkj8lygyg7mdbjlf-slack-cli-0.18.0/bin
patching script interpreter paths in /nix/store/rbv0mlpq1a9769vyjkj8lygyg7mdbjlf-slack-cli-0.18.0
/nix/store/rbv0mlpq1a9769vyjkj8lygyg7mdbjlf-slack-cli-0.18.0/bin/.slack-wrapped: interpreter directive changed from "/usr/bin/env bash" to "/nix/store/56nrxy58wbhvs2sy3rir1jqa68p0kkm5-bash-4.4-p23/bin/bash"
checking for references to /build in /nix/store/rbv0mlpq1a9769vyjkj8lygyg7mdbjlf-slack-cli-0.18.0...
/nix/store/rbv0mlpq1a9769vyjkj8lygyg7mdbjlf-slack-cli-0.18.0

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: slack-cli

Partial log (click to expand)

no configure script, doing nothing
installing
post-installation fixup
shrinking RPATHs of ELF executables and libraries in /nix/store/bsb84b0i65n004y1xgmark7bg5cmsv0c-slack-cli-0.18.0
strip is /nix/store/ah0va6j4cnwj9nx4j6rwcfc8nh785jwm-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/bsb84b0i65n004y1xgmark7bg5cmsv0c-slack-cli-0.18.0/bin
patching script interpreter paths in /nix/store/bsb84b0i65n004y1xgmark7bg5cmsv0c-slack-cli-0.18.0
/nix/store/bsb84b0i65n004y1xgmark7bg5cmsv0c-slack-cli-0.18.0/bin/.slack-wrapped: interpreter directive changed from "/usr/bin/env bash" to "/nix/store/7q3ayirslrcva28wava6zpjcflcz1h3b-bash-4.4-p23/bin/bash"
checking for references to /build in /nix/store/bsb84b0i65n004y1xgmark7bg5cmsv0c-slack-cli-0.18.0...
/nix/store/bsb84b0i65n004y1xgmark7bg5cmsv0c-slack-cli-0.18.0

@timokau
Copy link
Member

timokau commented Aug 15, 2018

By the way we'll need to squash this for merge. I can just use githubs squash-and-merge feature, but in case you prefer to squash it yourself now's the time.

@GrahamcOfBorg
Copy link

Success on x86_64-darwin (full log)

Attempted: slack-cli

Partial log (click to expand)

patching sources
configuring
no configure script, doing nothing
installing
post-installation fixup
strip is /nix/store/251fvx4mx9q4zarbca5cciasmn66p668-cctools-binutils-darwin/bin/strip
stripping (with command strip and flags -S) in /nix/store/l2774l1i1xcqp5gy6b931rg8k5kindj3-slack-cli-0.18.0/bin
patching script interpreter paths in /nix/store/l2774l1i1xcqp5gy6b931rg8k5kindj3-slack-cli-0.18.0
/nix/store/l2774l1i1xcqp5gy6b931rg8k5kindj3-slack-cli-0.18.0/bin/.slack-wrapped: interpreter directive changed from "/usr/bin/env bash" to "/nix/store/hp9yq2m1i066irvasv20zr2lmj54fk9h-bash-4.4-p23/bin/bash"
/nix/store/l2774l1i1xcqp5gy6b931rg8k5kindj3-slack-cli-0.18.0

@timokau
Copy link
Member

timokau commented Aug 15, 2018

Since ofBorg approves, I don't think githubs squash-and-merge has any disadvantages and I want to merge this before going to sleep and potentially forgetting about this tomorrow, I'll just merge now :)

@timokau timokau merged commit d202daf into NixOS:master Aug 15, 2018
@alyssais alyssais deleted the slack-cli branch August 16, 2018 08:07
@alyssais
Copy link
Member Author

Thanks for all the reviewing! I learned a lot :)

@infinisil
Copy link
Member

@timokau I prefer not to use squash-and-merge when the change should be in multiple commits, which would've been the case here: The maintainers update and the package init.

@timokau
Copy link
Member

timokau commented Aug 16, 2018

@infinisil yes, but in this case it was a lot of "fixup/small change" commits and I think the maintainers upgrade was not actually in a separate commit. For what its worth, I pressed the wrong button anyways and did a regular merge 😅

But all the commits here can reasonable stand by themselves, so I think it is fine either way. I would just have preferred not to have multiple very small commits that don't add much value clutter the history.

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

5 participants