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

tmuxPlugins.tmux-fzf: init at unstable-2020-11-12 #95275

Merged
merged 2 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions maintainers/maintainer-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4789,6 +4789,12 @@
githubId = 2422454;
name = "Kai Wohlfahrt";
};
kyleondy = {
email = "kyle@ondy.org";
github = "kyleondy";
githubId = 1640900;
name = "Kyle Ondy";
};
kylesferrazza = {
name = "Kyle Sferrazza";
email = "kyle.sferrazza@gmail.com";
Expand Down
35 changes: 35 additions & 0 deletions pkgs/misc/tmux-plugins/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,41 @@ in rec {
};
};

tmux-fzf = mkDerivation {
pluginName = "tmux-fzf";
Copy link
Contributor

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.

Copy link
Member Author

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?

Copy link
Contributor

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 😃

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'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

Copy link
Contributor

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 🤓

Copy link
Member Author

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.

Copy link
Member Author

@KyleOndy KyleOndy Nov 24, 2020

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
  '';
}

Copy link
Contributor

@timstott timstott Nov 26, 2020

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.

version = "unstable-2020-11-23";
src = fetchFromGitHub {
owner = "sainnhe";
repo = "tmux-fzf";
rev = "312685b2a7747b61f1f4a96bd807819f1450479d";
sha256 = "1z0zmsf8asxs9wbwvkiyd81h93wb2ikl8nxxc26sdpi6l333q5s9";
};
KyleOndy marked this conversation as resolved.
Show resolved Hide resolved
postInstall = ''
find $target -type f -print0 | xargs -0 sed -i -e 's|fzf |${pkgs.fzf}/bin/fzf |g'
Copy link
Contributor

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.

Copy link
Member Author

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.

find $target -type f -print0 | xargs -0 sed -i -e 's|sed |${pkgs.gnused}/bin/sed |g'
find $target -type f -print0 | xargs -0 sed -i -e 's|tput |${pkgs.ncurses}/bin/tput |g'
'';
meta = {
homepage = "https://github.com/sainnhe/tmux-fzf";
description = "Use fzf to manage your tmux work environment! ";
longDescription =
''
Features:
* Manage sessions (attach, detach*, rename, kill*).
* Manage windows (switch, link, move, swap, rename, kill*).
* Manage panes (switch, break, join*, swap, layout, kill*, resize).
* Multiple selection (support for actions marked by *).
* Search commands and append to command prompt.
* Search key bindings and execute.
* User menu.
* Popup window support.
'';
license = stdenv.lib.licenses.mit;
platforms = stdenv.lib.platforms.unix;
maintainers = with stdenv.lib.maintainers; [ kyleondy ];
KyleOndy marked this conversation as resolved.
Show resolved Hide resolved
};
};

urlview = mkDerivation {
pluginName = "urlview";
version = "unstable-2016-01-06";
Expand Down