{ config, lib, pkgs, ... }: let # Provides a fake "docker" binary mapping to podman cfg = config.services.podman; podmanPackage = cfg.package; docker_host = "unix:///run/user/$UID/podman/podman.sock"; fakeDockerBinary = pkgs.runCommandNoCC "${podmanPackage.pname}-docker-compat-${podmanPackage.version}" { outputs = [ "out" "man" ]; inherit (podmanPackage) meta; } '' mkdir -p $out/bin ln -s ${podmanPackage}/bin/podman $out/bin/docker mkdir -p $man/share/man/man1 for f in ${podmanPackage.man}/share/man/man1/*; do basename=$(basename $f | sed s/podman/docker/g) ln -s $f $man/share/man/man1/$basename done ''; dockerComposeCompat = pkgs.runCommandNoCC "docker-compose-podman-compat" { buildInputs = [ pkgs.makeWrapper ]; } '' mkdir -p $out/bin makeWrapper '${pkgs.docker-compose_2}/libexec/docker/cli-plugins/docker-compose' "$out/bin/docker-compose" \ --set-default "DOCKER_HOST" 'unix:///run/user/$UID/podman/podman.sock' \ --set-default DOCKER_BUILDKIT 0 ''; in with lib; { options.services.podman = { dockerCompat = { fakeDockerBinary.enable = mkEnableOption { description = '' Create an alias mapping docker to podman. ''; }; dockerSocket.enable = mkEnableOption { description = '' Set the DOCKER_HOST environment variable to make docker tools use the podman docker ''; }; dockerCompose.enable = mkEnableOption { description = '' Install a docker-compose binary that uses the podman socket ''; }; }; }; config = lib.mkIf cfg.enable (lib.mkMerge [ (lib.mkIf cfg.dockerCompat.fakeDockerBinary.enable { home.packages = [ fakeDockerBinary ]; }) (lib.mkIf cfg.dockerCompat.dockerCompose.enable { home.packages = [ dockerComposeCompat ]; }) (lib.mkIf cfg.dockerCompat.dockerSocket.enable { home.sessionVariables."DOCKER_HOST" = "unix:///run/user/$UID/podman/podman.sock"; }) ]); }