From 5407a105c84268382dbdf76f020ca9be1d4f9b6a Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Sat, 2 Nov 2024 23:51:41 +0100 Subject: [PATCH] shell.nix: Support nix-shell -A It used to be that `nix-shell -A hello` would launch the build shell for the `hello` package. By adding `/shell.nix`, that stopped working, as all versions of `nix-shell` resolve the unspecified file to `$PWD/shell.nix` if it exists, and now it does. I have to admit that this use of `//` is not pretty, but the UX/DX hard to match. --- shell.nix | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/shell.nix b/shell.nix index b8a9fe7df19f..ecb444e75ec0 100644 --- a/shell.nix +++ b/shell.nix @@ -17,8 +17,17 @@ }: let inherit (import ./ci { inherit nixpkgs system; }) pkgs; + + # For `nix-shell -A hello` + curPkgs = builtins.removeAttrs (import ./. { inherit system; }) [ + # Although this is what anyone may expect from a `_type = "pkgs"`, + # this file is intended to produce a shell in the first place, + # and a `_type` tag could confuse some code. + "_type" + ]; in -pkgs.mkShellNoCC { +curPkgs +// pkgs.mkShellNoCC { packages = with pkgs; [ # The default formatter for Nix code # See https://github.com/NixOS/nixfmt