From bc7ef22d1f56de5cfad6166543553731e8bd30a5 Mon Sep 17 00:00:00 2001 From: nicoo Date: Fri, 10 Nov 2023 02:05:16 +0000 Subject: [PATCH] nix-your-shell: add module A wrapper for `nix develop` and `nix-shell` to run non-Bash shells. --- modules/modules.nix | 1 + modules/programs/nix-your-shell.nix | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 modules/programs/nix-your-shell.nix diff --git a/modules/modules.nix b/modules/modules.nix index 12163edc7..1d7554697 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -156,6 +156,7 @@ let ./programs/newsboat.nix ./programs/nheko.nix ./programs/nix-index.nix + ./programs/nix-your-shell.nix ./programs/nnn.nix ./programs/noti.nix ./programs/notmuch.nix diff --git a/modules/programs/nix-your-shell.nix b/modules/programs/nix-your-shell.nix new file mode 100644 index 000000000..cde057447 --- /dev/null +++ b/modules/programs/nix-your-shell.nix @@ -0,0 +1,21 @@ +{ config, lib, pkgs, ... }: +let + inherit (lib) genAttrs getExe; + cfg = config.programs.nix-your-shell; + + # In principle `bash` is supported too, but... 😹 + shells = [ "fish" "nushell" "zsh" ]; + programs = [ "nix" "nix-shell" ]; +in { + meta.maintainers = with lib.maintainers; [ nicoo ]; + + options.programs.nix-your-shell.enable = lib.mkEnableOption '' + `nix-your-shell`, a wrapper for `nix develop` or `nix-shell` + to run the same shell inside the new environment. + ''; + + config.programs = lib.mkIf cfg.enable (genAttrs shells (shell: { + shellAliases = genAttrs programs + (program: "${getExe pkgs.nix-your-shell} ${shell} ${program} --"); + })); +}