Docker/Podman network create - Nix?

I am currently using this configuration to create a network for my Docker containers:

1   { config, pkgs, ... }:
  2 {
  4"docker-network-paperless" = {
  5     serviceConfig.Type = "oneshot";
  6     wantedBy = [ "docker-paperless-app.service" ];
  7     script = ''
  8       ${pkgs.docker}/bin/docker network inspect paperless > /dev/null 2>&1 || ${pkgs.docker}/bin/docker network create paperless
  9     '';
 10   };
 12   virtualisation.oci-containers = {
 13     containers = {
 14       paperless-app = import ../../modules/containers/paperless-app.nix;
 15       paperless-cache = import ../../modules/containers/paperless-cache.nix;
 16       paperless-db = import ../../modules/containers/paperless-db.nix;
 17     };
 18   };
 20 }

Is there a clean “Nix” solution for creating Docker/Podman networks?


Sadly there isn’t in nixpkgs, at least. I used to have a hacky re-implementation of the module that did that, but have since started using podman pods instead.

The problem in the docker world is that you can’t attach to networks easily (beyond the first), so any generic implementation ends up too hacky to upstream reasonably without major changes to how the module works currently. It’s easier with podman, but that is tied to the docker implementation (and pods are a much better approach to networking like this anyway).

My old implementation is using deprecated stuff now, but I’d love to see a look at a clean way of getting this sort of thing done upstream :slight_smile:


You can create a network by writing a network configuration file manually.

Here is the example that is used in nixpkgs to create the default podman network when dns is enabled.