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
slack-cli: init at 0.18.0 #45055
Conversation
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"; |
There was a problem hiding this comment.
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.
@GrahamcOfBorg build slack-cli |
Success on x86_64-darwin (full log) Attempted: slack-cli Partial log (click to expand)
|
Success on aarch64-linux (full log) Attempted: slack-cli Partial log (click to expand)
|
Success on x86_64-linux (full log) Attempted: slack-cli Partial log (click to expand)
|
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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 ]; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 buildInput
s and just use ${makeWrapper}/bin/wrapProgram
in installPhase
.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
buildInput
s and just use${makeWrapper}/bin/wrapProgram
ininstallPhase
.
This wouldn't work.
$ nix-shell -p makeWrapper --run 'type -t wrapProgram'
function
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
.
pkgs/top-level/all-packages.nix
Outdated
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; |
There was a problem hiding this comment.
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
?
pkgs/top-level/all-packages.nix
Outdated
wrapSlackCli = callPackage ../tools/networking/slack-cli/wrapper.nix { }; | ||
slack-cli-unwrapped = callPackage ../tools/networking/slack-cli { }; | ||
slack-cli = wrapSlackCli slack-cli-unwrapped; | ||
|
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 "$@" | |||
'' | |||
'') // { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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_
There was a problem hiding this comment.
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" "$@" | ||
''; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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…
There was a problem hiding this comment.
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..
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed!
LGTM, merge pending ofBorg's approval. Thank you for packaging this and responding to the many nitpicks. Always happy to see a new entry in |
Success on x86_64-linux (full log) Attempted: slack-cli Partial log (click to expand)
|
Success on aarch64-linux (full log) Attempted: slack-cli Partial log (click to expand)
|
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. |
Success on x86_64-darwin (full log) Attempted: slack-cli Partial log (click to expand)
|
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 :) |
Thanks for all the reviewing! I learned a lot :) |
@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. |
@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. |
sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)nix path-info -S
before and after)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.