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.
This commit is contained in:
Robert Hensing 2024-11-02 23:51:41 +01:00
parent 6b2e0aae78
commit 5407a105c8

View file

@ -17,8 +17,17 @@
}: }:
let let
inherit (import ./ci { inherit nixpkgs system; }) pkgs; 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 in
pkgs.mkShellNoCC { curPkgs
// pkgs.mkShellNoCC {
packages = with pkgs; [ packages = with pkgs; [
# The default formatter for Nix code # The default formatter for Nix code
# See https://github.com/NixOS/nixfmt # See https://github.com/NixOS/nixfmt