Function found when set expected

I realize this has been covered quite a bit, but I am still having difficulty fully grasping the nix language which means I still struggle sometimes to take an example and modify it to my needs.

Can someone please explain to me why the following doesn’t work (it complains that it expects a set but it is getting a function):

  environment.etc."/containers/networks/podman1.json" = with pkgs.formats; {
    source = json.generate "podman1.json" ({
      name = "podman1";
      id = "4b65a30030d96b0e930be01ec05b749ff36e2991b7a08c2877862561e945366a";
      driver = "bridge";
      network_interface = "podman1";
      subnets = [
        {
          subnet = "10.89.0.0/24";
          gateway = "10.89.0.1";
        }
      ];
      ipv6_enabled = false;
      internal = false;
      dns_enabled = true;
      ipam_options = {
        driver = "host-local";
      };
    });
  };

Edit: I understand the bridge networking now, so I edited to clarify my question about the nix language.

When I try in the repl, the json.generate function returns a path rather than a set, which is what I thought source = wanted. I am not sure how to turn this path into a set.

repl output:

nix-repl> with <nixpkgs>.formats; json.generate "Test.json" ({ foo = "bar"; })    
error: value is a path while a set was expected

       at «string»:1:6:

            1| with <nixpkgs>.formats; json.generate "Test.json" ({ foo = "bar"; })

This seems to have worked:

  environment.etc."/containers/networks/podman1.json" = 
  let
    json = pkgs.formats.json {};
    podman1_settings = {
      name = "podman1";
      id = "4b65a30030d96b0e930be01ec05b749ff36e2991b7a08c2877862561e945366a";
      driver = "bridge";
      network_interface = "podman1";
      subnets = [
        {
          subnet = "10.89.0.0/24";
          gateway = "10.89.0.1";
        }
      ];
      ipv6_enabled = false;
      internal = false;
      dns_enabled = true;
      ipam_options = {
        driver = "host-local";
      };
    };
  in
  {
    source =  json.generate "podman1.json" podman1_settings;
  };

but I still don’t understand why it didn’t work the other way.