Skip to content

Commit

Permalink
shell.nix: Support nix-shell -A
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
roberth committed Nov 2, 2024
1 parent 6b2e0aa commit 5407a10
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5407a10

Please sign in to comment.