Can't set up a flake

install nodejs mongodb and mongosh using a flake, and since mongosh is considered unfree software i added the last line

{
  description = "Installing Nodejs with a flake";

  inputs = {
    nixpkgs-stable.url = "github:nixos/nixpkgs/nixos-23.11";
  };

  outputs = { self, nixpkgs-stable, ... }: with nixpkgs-stable.legacyPackages.x86_64-linux; {
    devShells.x86_64-linux.TestingNodejsFlake = mkShell {
      buildInputs = [
        nodejs
        mongodb
        mongosh
      ];
    }
     { nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
             "mongodb"
           ];
     };
  };
}

and i ran nix develop and i got this error:

error: error: attempt to call something which is not a function but a set

       at /nix/store/q0wkasbrmwk8zyz719g4c0gb6d58v1j7-source/flake.nix:9:49:

            8|   outputs = { self, nixpkgs-stable, ... }: with nixpkgs-stable.legacyPackages.x86_64-linux; {
            9|     devShells.x86_64-linux.TestingNodejsFlake = mkShell {
             |                                                 ^
           10|       buildInputs = [

well i’m trying to develop a web app using a flake , that’s all

You can’t just randomly plop NixOS module configuration into a flake.nix. You need the NixOS module system to evaluate it. Your code calls mkShell with two arguments, but since it only takes one the first argument is treated as a function being given the second arg, which fails with that error because it’s not a function.

Either way, you’re barking up the wrong tree. Using unfree packages with flakes is currently a bit awkward because there is no way to set options on inputs. The best solution is to wrap your input with another that sets the option for you. nixpkgs-unfree exists for this purpose: GitHub - numtide/nixpkgs-unfree: nixpkgs with the unfree bits enabled

You can alternatively also import your nixpkgs input and set the configuration there, but nixpkgs-unfree is just a nicer solution.