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

Conversation

KyleOndy
Copy link
Member

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
  • 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.

@KyleOndy
Copy link
Member Author

KyleOndy commented Sep 2, 2020

@Ericson2314, just bumping this. Is there anything additional I need to do, or I can help with to get this merged? Thanks.

@KyleOndy KyleOndy force-pushed the add_tmux_plugin_fzf branch 2 times, most recently from 22041ac to 3269f7b Compare September 17, 2020 19:48
@KyleOndy
Copy link
Member Author

@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?

Copy link
Contributor

@timstott timstott left a 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.

pkgs/misc/tmux-plugins/default.nix Show resolved Hide resolved
@@ -377,6 +377,17 @@ 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.

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

 This plugin has no releases or tags yet, so pinned to the current head
 of master as of this commit.
@KyleOndy KyleOndy changed the title tmuxPlugins.tmux-fzf: init at unstable-2020-07-28 tmuxPlugins.tmux-fzf: init at unstable-2020-11-12 Nov 24, 2020
Copy link
Contributor

@timstott timstott left a 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 🎉

@timstott
Copy link
Contributor

@SuperSandro2000 Could you take another look at this 🙇

@infinisil infinisil merged commit aeadbb8 into NixOS:master Dec 2, 2020
@KyleOndy KyleOndy deleted the add_tmux_plugin_fzf branch December 3, 2020 14:54
KyleOndy added a commit to KyleOndy/nixpkgs that referenced this pull request Dec 15, 2020
This change somehow escaped me when I was iterating on  NixOS#95275.
@KyleOndy KyleOndy mentioned this pull request Dec 15, 2020
10 tasks
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

4 participants