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
tmuxPlugins.tmux-fzf: init at unstable-2020-11-12 #95275
Conversation
@Ericson2314, just bumping this. Is there anything additional I need to do, or I can help with to get this merged? Thanks. |
22041ac
to
3269f7b
Compare
3269f7b
to
f2a27cc
Compare
@timstott, sorry if you are not the right person, I just see you had some recent commits to this repo. I've updated this PR, anything else I can do to help getting this merged? |
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.
Thank you for your contribution @KyleOndy. I have left some comments I hope we can address.
💅 You may also want to update the PR title to reflect the latest version.
@@ -377,6 +377,17 @@ in rec { | |||
}; | |||
}; | |||
|
|||
tmux-fzf = mkDerivation { | |||
pluginName = "tmux-fzf"; |
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.
🙋 Since tmux-fzf
expects fzf
to be available at runtime, we need to patch scripts/.fzf-tmux to look for the executable in the nix store. You can find examples of this in postInstall
hooks inside this file.
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.
Should I also patch sed
?
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.
@KyleOndy excellent suggestion, we should indeed 😃
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'm happy to do that work; I am just curious how complete this should be? Feel free to reroute me to a more general forum for this if appropriate.
Should I patch all instances on binary calls to use the executable in the nix store? grep
? xargs
? The calls to tmux
itself?
This is where my lack of deeper knowledge of nix come in, and I admit I have not finished RTFM, so if that is the right move, let me know.
If the system is going to resolve the binary to the nix store eventually, what is the reason or patching the script directly? If the purpose is to ensure the binary is available, shouldn't that be resolved with a dependeny?
> which fzf
/home/kyle/.nix-profile/bin/fzf
> ls -l /home/kyle/.nix-profile/bin/fzf
lrwxrwxrwx 1 root root 69 Dec 31 1969 /home/kyle/.nix-profile/bin/fzf -> /nix/store/8ppzzf9lnnpdccmm9bdk8miadpvxfwi3-home-manager-path/bin/fzf
> ls -l /nix/store/8ppzzf9lnnpdccmm9bdk8miadpvxfwi3-home-manager-path/bin/fzf
lrwxrwxrwx 1 root root 62 Dec 31 1969 /nix/store/8ppzzf9lnnpdccmm9bdk8miadpvxfwi3-home-manager-path/bin/fzf -> /nix/store/gklqlnxfhx5rrphdx1mjvxmmi597khc8-fzf-0.24.3/bin/fzf
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 aim to is create a derivation that captures all dependencies (at the exception of tmux
perhaps) to use the package. This can be verified in a hermetic environment provided by nix-shell --pure
.
I recommend to first checkout the PR with nixpkgs-review
. This will checkout the PR in a temporary directory, build the derivation and spawn an interactive shell.
# run the command at the root of `nixpkgs` repo
nixpkgs-review pr 95275
Inside the temporary directory find shell.nix
and replace its content with the snippet below. This will provide a shell with tmux, the plugin and a tmux config file.
{ pkgs ? import ./nixpkgs {} }:
with pkgs;
let
tmuxConfig = ''
set -g @plugin 'sainnhe/tmux-fzf'
run '${tmuxPlugins.tmux-fzf}/share/tmux-plugins/tmux-fzf/main.tmux'
'';
in stdenv.mkDerivation {
name = "env";
buildInputs = [
tmuxPlugins."tmux-fzf"
tmux
];
unpackPhase = ":";
installPhase = "touch $out";
shellHook = ''
echo "${tmuxConfig}" > $PWD/tmux.config
'';
}
Then run nix-shell --pure
(by default will use shell.nix
in the current directory). Once the shell started, run tmux -f tmux.config
to test the plugin. There we can observe the plugin is not yet functional.
I know of two options to specify dependencies, 1) patch the source files to reference nix store location 2) prefix the entry point's PATH
with wrapProgram
(example).
Based on how the plugin is built, wrapProgram
could be a neat solution.
Now, onto the existing dependencies
attribute, it appears to do nothing. I would be looking at deprecating its use.
On this output. It shows fzf
is installed in your profile, but the plugin should work irrespective of whether it is in your profile.
> which fzf
/home/kyle/.nix-profile/bin/fzf
Let me know if it does not make sense or you have further questions. I am learning too 🤓
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.
Thank you so much for this write up. I appreciate the time it took. This connected a lot of dots for me, and made things much clearer.
On this output. It shows fzf is installed in your profile, but the plugin should work irrespective of whether it is in your profile.
I don't know why it wasn't obvious to me, but this comment cleared it all up.
I'll give this some time tonight and hope to have it all working.
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 was able to get the plugin working using the following as my shell.nix
. Notably I dropped the set -g @plugin 'sainnhe/tmux-fzf'
line as the run
command takes care of loading the plugin. The plugin also requires ncurses
.
I was able to get the plugin working using the following as my shell.nix
. I am still unclear on how to declare the fzf
and ncurses
dependencies.
{ pkgs ? import ./nixpkgs {} }:
with pkgs;
let
tmuxConfig = ''
run '${tmuxPlugins.tmux-fzf}/share/tmux-plugins/tmux-fzf/main.tmux'
'';
in stdenv.mkDerivation {
name = "env";
buildInputs = [
tmuxPlugins."tmux-fzf"
tmux
ncurses
];
unpackPhase = ":";
installPhase = "touch $out";
shellHook = ''
echo "${tmuxConfig}" > $PWD/tmux.config
'';
}
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 is looking good @KyleOndy, good spot on the ncurses
dependency.
When it comes to declaring dependencies, you have effectively done so when referring to pkgs.<package>
in the substitution steps. This can be observed by looking at derivation's inputs.
# compute derivation path needed for nix show-derivation
nix-instantiate '<nixpkgs>' -A tmuxPlugins.tmux-fzf # see Note 1 on <nixpkgs>
outputs <path to drv>
nix show-derivation <path to drv>
In the output find inputDrvs
(the derivation's direct dependencies)
"inputDrvs": {
"/nix/store/10xi5iv5svzxfdxdjzbq0hyxwkyxg8dr-bash-4.4-p23.drv": [
"out"
],
"/nix/store/7bk8andhhffxcb34nhgrgghillmil8xr-stdenv-linux.drv": [
"out"
],
"/nix/store/jhnqycphsrkcllwwvb31mgbgdw2br3ij-source.drv": [
"out"
],
"/nix/store/sx2ns26na7yxmm3lwnm6lrnin6b9axi6-ncurses-6.2.drv": [
"out"
],
"/nix/store/ww9by1sif2l0c1608ry4n86scjrgy6vy-fzf-0.24.3.drv": [
"out"
],
"/nix/store/yq5r43jzh1nl74xs4x9rcxgvd3xqhnck-gnused-4.8.drv": [
"out"
]
},
Note 1
<nixpkgs>
This is a reference to the location of nixpkgs repository. When in a nix-review pr xxx shell, the <nixpkgs>
references a locally checked out version of nixpkgs with the PR diff.
f2a27cc
to
79b9b71
Compare
@@ -387,8 +387,8 @@ in rec { | |||
sha256 = "0vavbmwhpqxk26avzbnjjswsv6cd7s0sdilwppxqjdif2zm6jg9k"; | |||
}; | |||
postInstall = '' | |||
sed -i -e 's|fzf |${pkgs.fzf}/bin/fzf |g' $target/main.sh | |||
sed -i -e 's|sed |${pkgs.gnused}/bin/sed |g' $target/main.sh | |||
find $target -type f -print0 | xargs -0 sed -i -e 's|fzf |${pkgs.fzf}/bin/fzf |g' |
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 would recommend you take a look at existing substitute functions nixpkgs
offers https://nixos.org/manual/nixpkgs/stable/#ssec-stdenv-functions. Perhaps substituteInPlace
could be a good fit here.
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.
Very cool. Thanks for that link. That seems like a much better way to go.
7e1db8d
to
45274ef
Compare
This plugin has no releases or tags yet, so pinned to the current head of master as of this commit.
800a140
to
242fa79
Compare
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 package builds and was tested in isolation in a nix-shell with
{ pkgs ? import ./nixpkgs {} }:
with pkgs;
let
tmuxConfig = ''
run '${tmuxPlugins.tmux-fzf}/share/tmux-plugins/tmux-fzf/main.tmux'
'';
in stdenv.mkDerivation {
name = "env";
buildInputs = [
tmuxPlugins."tmux-fzf"
tmux
ncurses
];
unpackPhase = ":";
installPhase = "touch $out";
shellHook = ''
echo "${tmuxConfig}" > $PWD/tmux.config
'';
}
Excellent work 🎉
@SuperSandro2000 Could you take another look at this 🙇 |
This change somehow escaped me when I was iterating on NixOS#95275.
This plugin has no releases or tags yet, so pinned to the current head
of master as of this commit.
Motivation for this change
I want to use this tmux plugin
Things done
sandbox
innix.conf
on non-NixOS linux)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
./result/bin/
)nix path-info -S
before and after)