Help with ‘nix-shell’ uses a nested list in attribute ‘buildInputs’

Could someone please help me re-write this flake? I’m getting this message

`Dependency of package ‘nix-shell’ uses a nested list in attribute ‘buildInputs’. This is deprecated as of Nixpkgs release 26.05, and support will be removed in a future nixpkgs release.`

This is the kind of flake I’m using.

{
  description = "A basic flake with a shell";
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/25.11";
    systems.url = "github:nix-systems/default";
    flake-utils = {
      url = "github:numtide/flake-utils";
      inputs.systems.follows = "systems";
    };
  };

  outputs =
    { nixpkgs, flake-utils, ... }:
    flake-utils.lib.eachDefaultSystem (
      system:
      let
        pkgs = nixpkgs.legacyPackages.${system};
      in
      {
        devShells.default = pkgs.mkShell {
          nativeBuildInputs = [ pkgs.bashInteractive ];
          buildInputs = with pkgs; [
            R
            quarto
            chromium
            pandoc
            texlive.combined.scheme-medium
            rstudio
            (with rPackages; [
              quarto
              tidyverse
            ])
          ];
        };
      }
    );
}

I believe the error comes from the (with rPackages…) part. I thought I could do something like the following, but it doesn’t work, it doesn’t like the second with.

buildInputs = with pkgs; [
            R
            quarto
            chromium
            pandoc
            texlive.combined.scheme-full
            rstudio 
            ] ++ 
            with pkgs.rPackages; [
              quarto
              tidyverse
            ]
          ];

I tried wrapping the second section in parentheses, but then it complains about a missing ; Could someone help me please? (Also, any general comments on the flake structure are appreciated. I’ve been copying and pasting for years.)

Cheers

Your suspicion is right, and the second version should work once parenthesisized.

Though even better is to just not use with.

Also you might want to prefer packages over *Inputs. Your complete buildInputs list looks as if it is usually better tailored to the nativeBuildInputs list.

And to avoid this confusion in the first place, packages is recommended for mkShell.

If I do

buildInputs = with pkgs; [
            R
            quarto
            chromium
            pandoc
            texlive.combined.scheme-medium
            rstudio 
          ] ++
            (with pkgs.rPackages; [
              quarto
              tidyverse
            ])
          ];

I get unexpected ], expecting ;. If I put a semicolon there, it complains that it wasn’t expecting one.

I’d like to avoid the repetition, because in most flakes I have many rPackages.

Are you saying I should move everything to nativeBuildInputs? I’m sorry, but I don’t know what you mean to use packages instead of Inputs.

Thanks for your help.

Please look at your code, you will see it.

Not *Inputs! packages!

Everywhere I try to put the semicolon it complains. I’ve been using nixos for a year and a half now, but the syntax is so opaque.

I really don’t know what that means.

This message is usually telling you to remove a ], not add a ;.

An easy check is that the number of [s should always equal the number of ]s in any expression.

1 Like

Thank you very much!

-buildInputs = with pkgs; [
+packages = with pkgs; [
             R
             quarto
             chromium
             pandoc
             texlive.combined.scheme-medium
             rstudio 
           ] ++
             (with pkgs.rPackages; [
               quarto
               tidyverse
-            ])
-          ];
+            ]);

And maybe you want to take a loot at the attrValues { inherit …; } pattern to avoid the repition and with alike.

2 Likes

That’s clear, thanks. Where can I learn about the attrValues { inherit …; } stuff. Maybe an example?

2 Likes

This works nicely and seems clean. Anything else? I do appreciate your time and input, thanks.

{
  description = "A basic flake with a shell";
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    systems.url = "github:nix-systems/default";
    flake-utils = {
      url = "github:numtide/flake-utils";
      inputs.systems.follows = "systems";
    };
  };

  outputs =
    { nixpkgs, flake-utils, ... }:
    flake-utils.lib.eachDefaultSystem (
      system:
      let
        pkgs = nixpkgs.legacyPackages.${system};
      in
      {
        devShells.default = pkgs.mkShell {
          nativeBuildInputs = [ pkgs.bashInteractive ];
          packages = builtins.attrValues {
            inherit (pkgs)
              R
              quarto
              chromium
              pandoc
              rstudio
              ;
            inherit (pkgs.texlive.combined) scheme-medium;
            inherit (pkgs.rPackages)
              tidyverse
              ;
          };
        };
      }
    );
}

packages is the same as nativeBuildInputs in mkShell. And you shouldn’t need to add bashInteractive explicitly.

2 Likes

Also consider using an LSP for editing nix files, they’ll make syntax errors a little easier to see and understand:

Personally I use the former, but the latter is definitely seeing more active development. I’m considering trying out nixd again since some features I was looking for have been added.

Just since you’re calling the syntax opaque; I find it no more opaque than any other programming language, but good tooling definitely helps.

1 Like

Sorry, I know it’s just me. For some reason I just have trouble grokking the nix language. TBF, I don’t use it much, so that’s on me. My main languages now are R, Python and Haskell, all of which seemed so clear and natural from the get go. Again, it’s just personal.

I didn’t realize that nil was the lsp for nix, lol. I had looked for one in my Mason (neovim) list, and it wasn’t obvious. Anyway, I’ve installed in now, thanks!