Skip to content

Figure out how to "bundle" Bash (or any other app) with its config (or if it is done already...) #3

Description

@toraritte

Like Vim:

      my_vim = # {{-
        pkgs.vim_configurable.customize {

          vimrcConfig.customRC = fetchContents ./vimrc;

          vimrcConfig.packages.myVimPackage =
            with pkgs.vimPlugins; {
              # Loaded on launch.
              start = ...
$ source <(curl https://raw.githubusercontent.com/toraritte/shell.nixes/main/run.sh) -n "23.05" -o "--run tmux"

# ... tmux starts, dropped in plain Bash
$ vim

Vim starts the same way as if the -o "--run tmux" part wasn't even there because

$ cat /nix/store/HASH-vim/bin/vim
#! /nix/store/HASH-bash-5.2-p15/bin/bash -e
exec "/nix/store/HASH-vim-full-9.0.1441/bin/vim"  -u '/nix/store/HASH-vimrc'  "$@" 

Why?

Because I think stacking run.sh calls (e.g., run.sh > vim > :term > run.sh or run.sh > tmux > run.sh in every new window) is more inefficient than simply starting a new shell.

NOTE 2023-09-07 1332
I have no proof of the above statement. After all, nix-shell will start a new Bash shell, just as I would if it was bundled with its config, and nix-shell would just re-set the same variables, paths, etc. that it did before, so there may not be much of a difference.

If there is indeed no difference between calling run.sh again or opening a new shell with the bundled Bash executable, then at least it looks nicer - and I probably spent another couple of days hacking on Nix instead of working.

NOTE 2023-09-07
After entering slate-2's dev_shell.nix, and then trying to invoke any nix-shell -p command, the shellHook of dev_shell.nix will run again. (A couple seconds later I realized that I went through this whole thing already Also, run.sh has its own shellHook so this becomes a non-issue and then I'm back to the previous note.)


... and just as I wrote it down, I realized that I may have the answer; see this snippet from nginx_shell.nix in the slate-2 repo:

  # NOTE See https://discourse.nixos.org/t/how-to-add-local-files-into-nginx-derivation-for-nix-shell/6603
  # QUESTION Why use the `*Bin` version?
  # ANSWER Because the NGINX  executable will then be
  #        added to PATH automatically.
  nginx_with_config =
    pkgs.writeShellScriptBin
      "nginx_lynx"
      ''
        exec ${pkgs.nginx}/bin/nginx -c ${nginx_conf} "$@"
      ''
  ;

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions