linuxmongodbnixnixosflake

mkShell is not a function


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


Solution

  • config should be passed as an argument to nixpkgs when it's being instantiated.

    {
      description = "Installing Nodejs with a flake";
    
      inputs = {
        nixpkgs-stable.url = "github:nixos/nixpkgs/nixos-23.11";
        flake-utils.url = "github:numtide/flake-utils";
      };
    
      outputs = { nixpkgs-stable, flake-utils, ... }: flake-utils.lib.eachDefaultSystem (system:
        let
          inherit (nixpkgs-stable) lib;
          pkgs = import nixpkgs-stable {
            inherit system;
            config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
              "mongodb"
            ];
          };
        in {
          devShells.TestingNodejsFlake = pkgs.mkShell {
            buildInputs = [
              pkgs.nodejs
              pkgs.mongodb
              pkgs.mongosh
            ];
          };
        });
    }