Skip to content

feat: use numtide/devshell to improve devshell experience#1973

Merged
phanirithvij merged 1 commit intongi-nix:mainfrom
phanirithvij:devshell
Jan 28, 2026
Merged

feat: use numtide/devshell to improve devshell experience#1973
phanirithvij merged 1 commit intongi-nix:mainfrom
phanirithvij:devshell

Conversation

@phanirithvij
Copy link
Copy Markdown
Member

@phanirithvij phanirithvij commented Jan 16, 2026

image

@eljamm

This comment was marked as resolved.

@phanirithvij

This comment was marked as resolved.

@phanirithvij phanirithvij marked this pull request as draft January 16, 2026 16:12
@phanirithvij phanirithvij force-pushed the devshell branch 4 times, most recently from 2b3824f to a2e1937 Compare January 17, 2026 23:11
@phanirithvij phanirithvij linked an issue Jan 18, 2026 that may be closed by this pull request
@phanirithvij phanirithvij force-pushed the devshell branch 5 times, most recently from 5d9f35e to 1714fd3 Compare January 19, 2026 08:02
@phanirithvij
Copy link
Copy Markdown
Member Author

phanirithvij commented Jan 19, 2026

TODO

We need to decide on

  • Do we need numtide/devshell or just a welcome and menu scripts that we maintain?
    • I vote for numtide/devshell. given the upstream is reliable and it is an actively maintained project fix: support pure mode numtide/devshell#359
    • We well have to slowly recreate the numtide devshell functionality ourselves on top of pkgs.mkShell, where devshell.mkShell uses a derivation with a stripped out stdenv under the hood.
  • The welcome message
  • What categories to include
  • What commands can be made scripts which would be worth adding to the menu
    • noticed the metrics and added two mentioned in the maintainers/reporting.md
    • watchdocs livedocs or something which would be devmode for ju1m's docs pr. doc: init #1891 (comment)
  • Whether to recommend direnv, or just mention it in the contribution docs somewhere

@phanirithvij phanirithvij force-pushed the devshell branch 5 times, most recently from 36c0f41 to 57f62dd Compare January 20, 2026 03:10
@phanirithvij phanirithvij changed the title WIP numtide/devshell feat: use numtide/devshell to improve devshell experience Jan 20, 2026
@phanirithvij phanirithvij force-pushed the devshell branch 2 times, most recently from 3ba6af4 to f0e15fd Compare January 20, 2026 04:12
@phanirithvij phanirithvij requested a review from eljamm January 20, 2026 12:44
@phanirithvij
Copy link
Copy Markdown
Member Author

We can review some prs in the office hours today if you are up to it.

@eljamm
Copy link
Copy Markdown
Contributor

eljamm commented Jan 20, 2026

Key points from reviewing this in the office hours:

  • what should the welcome message be?
    • whole shell or just run this for help
    • can we add an option?
  • this modifies the terminal's PS1, which users might not be okay with
  • if you don't clear direnv's cache, the environment does not load the welcome message
  • we don't want to auto-enable the pre-commit hook anymore when entering the shell env
  • on my machine nix-shell and nix develop doesn't show me the message and I need to wrap the devshell in a pkgs.mkShell's shellHook
review.patch

diff --git a/maintainers/shells/default.nix b/maintainers/shells/default.nix
index 03d6eeb4..8dfe3dbb 100644
--- a/maintainers/shells/default.nix
+++ b/maintainers/shells/default.nix
@@ -1,17 +1,18 @@
 {
   lib,
   pkgs,
-  devshell,
-  nixdoc-to-github,
+  sources,
+
+  callPackage,
 
   # toplevel attributes
-  ngipkgs,
   formatter,
   ...
 }:
 let
-  devshellArgs = lib.makeExtensible (final: {
+  devshell = import sources.devshell { nixpkgs = pkgs; };
 
+  shellEnv = lib.makeExtensible (final: {
     generalCategory = "[general commands]";
 
     mkAliases =
@@ -35,13 +36,6 @@ let
             (value.help or value.cmd);
       }) aliases;
 
-    mapCommands =
-      category: packages:
-      builtins.map (p: {
-        inherit category;
-        package = p;
-      }) packages;
-
     # from numtide/devshell, copyright Numtide, MIT licensed
     # Returns a list of all the input derivation ... for a derivation.
     inputsOf =
@@ -68,6 +62,13 @@ let
       $(type -p menu &>/dev/null && menu)
     '';
 
+    mapCommands =
+      category: packages:
+      builtins.map (p: {
+        inherit category;
+        package = p;
+      }) packages;
+
     commands =
       (final.mapCommands "formatter" final.formatters)
       ++ final.defaultCmds
@@ -81,13 +82,12 @@ let
 
     packagesFrom = [ ]; # inputsFrom equivalent, are hidden in the menu
 
-    # End devshell.mkShell args
-
-    _devshell = devshell.mkShell (
+    finalPackage = devshell.mkShell (
       lib.filterAttrs (
         name: value:
         # filter only the valid args for devshell.mkShell
         builtins.elem name [
+          "shellHook"
           "name"
           "motd"
           "commands"
@@ -97,25 +97,6 @@ let
       ) final
     );
 
-    finalPackage =
-      if (final.shellHook != "") then
-        # allow shellHook overriding by embedding into another shell
-        # FIXME(phanirithvij): possible to fix this in numtide/devshell, a shellHook argument to mkShell
-        pkgs.mkShellNoCC {
-          inherit (final) name;
-          shellHook = ''
-            source ${final._devshell.hook}/nix-support/setup-hook
-            ${final.shellHook}
-          '';
-          packages = [ final._devshell ];
-        }
-      else
-        # use the minimal numtide shell if shellHook override is not required
-        final._devshell;
-
-    # default empty shellHook, implies no override
-    shellHook = "";
-
     # Include all formatter packages. Format with:
     # $ treefmt
     # $ nix fmt
@@ -140,9 +121,15 @@ let
             lib.fileset.fileFilter (file: file.hasExt "nix") ./commands
           )
         );
-        callPackage' = lib.callPackageWith (pkgs // { inherit nixdoc-to-github ngipkgs; });
       in
-      final.mapCommands "commands" (builtins.map (path: callPackage' path { }) files);
+      final.mapCommands "commands" (map (path: callPackage path { }) files);
   });
+
+  shell.finalPackage = pkgs.mkShell {
+    packages = [ shellEnv.finalPackage ];
+    shellHook = ''
+      menu
+    '';
+  };
 in
-devshellArgs
+shell

@phanirithvij phanirithvij force-pushed the devshell branch 3 times, most recently from 3bf8e4c to 9dd16cc Compare January 21, 2026 06:23
@phanirithvij
Copy link
Copy Markdown
Member Author

this modifies the terminal's PS1, which users might not be okay with

There is NIX_SHELL_PRESERVE_PROMPT for nix versions later than 2.4

if you don't clear direnv's cache, the environment does not load the welcome message

This can be documented, cannot be fixed by us.

we don't want to auto-enable the pre-commit hook anymore when entering the shell env

made the flake shell the same as the shells/default.nix, not extending it anymore with the pre-commit checks hooks and packages.

on my machine nix-shell and nix develop doesn't show me the message

I wasn't able to reproduce this in two other machines. I think it is something we can investigate and fix. But even with this setup menu and other tools are available in the shell, not so different from the current shell before this pr.

@phanirithvij phanirithvij force-pushed the devshell branch 2 times, most recently from 35577dc to 84dc63a Compare January 21, 2026 08:06
@imincik imincik self-requested a review January 21, 2026 11:47
@phanirithvij phanirithvij force-pushed the devshell branch 3 times, most recently from 4453bb0 to fc20dc0 Compare January 22, 2026 03:58
@eljamm
Copy link
Copy Markdown
Contributor

eljamm commented Jan 22, 2026

on my machine nix-shell and nix develop doesn't show me the message

I wasn't able to reproduce this in two other machines. I think it is something we can investigate and fix. But even with this setup menu and other tools are available in the shell, not so different from the current shell before this pr.

Just for clarity, @phanirithvij and I were able to debug this yesterday and it turned out it was caused by my fish config. Not sure what the exact culprit is, but this will probably not affect users.

@phanirithvij phanirithvij marked this pull request as ready for review January 22, 2026 09:58
@phanirithvij phanirithvij marked this pull request as draft January 22, 2026 09:59
@phanirithvij phanirithvij marked this pull request as ready for review January 22, 2026 10:08
@phanirithvij
Copy link
Copy Markdown
Member Author

I'll try to refactor this to use the module system later, but I think it is good enough, we can extend the shell too.

@phanirithvij phanirithvij force-pushed the devshell branch 5 times, most recently from adb260f to b1bcc9e Compare January 22, 2026 10:58
Comment thread maintainers/shells/default.nix Outdated
@phanirithvij phanirithvij force-pushed the devshell branch 2 times, most recently from 00a82a6 to 93dcdbc Compare January 27, 2026 05:10
Copy link
Copy Markdown
Contributor

@eljamm eljamm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me and is working as intended.

moved commands into a ./commands subdirectory with categories as parent
directories

Signed-off-by: phanirithvij <phanirithvij2000@gmail.com>
@phanirithvij phanirithvij force-pushed the devshell branch 2 times, most recently from 2927d19 to 6d9ebe7 Compare January 28, 2026 09:34
@phanirithvij phanirithvij merged commit 36c6f27 into ngi-nix:main Jan 28, 2026
12 checks passed
@github-project-automation github-project-automation Bot moved this to Done in Nix@NGI Jan 28, 2026
@phanirithvij phanirithvij deleted the devshell branch January 28, 2026 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

US: Standardize development shell and tool discovery

2 participants