diff --git a/users/modules/podman/default.nix b/users/modules/podman/default.nix
index bd9c6f9..a411363 100644
--- a/users/modules/podman/default.nix
+++ b/users/modules/podman/default.nix
@@ -3,5 +3,6 @@
./podman.nix
./containers.nix
./podman-dnsname.nix
+ ./docker-compat.nix
];
}
diff --git a/users/modules/podman/docker-compat.nix b/users/modules/podman/docker-compat.nix
new file mode 100644
index 0000000..b7a0f55
--- /dev/null
+++ b/users/modules/podman/docker-compat.nix
@@ -0,0 +1,65 @@
+{ 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";
+ })
+
+ ]);
+}
diff --git a/users/modules/podman/podman.nix b/users/modules/podman/podman.nix
index ced75de..b8bc923 100644
--- a/users/modules/podman/podman.nix
+++ b/users/modules/podman/podman.nix
@@ -8,22 +8,6 @@ let
podmanPackage = (pkgs.podman.override { inherit (cfg) extraPackages; });
- # Provides a fake "docker" binary mapping to podman
- dockerCompat = 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
- '';
-
net-conflist = pkgs.runCommand "87-podman-bridge.conflist"
{
nativeBuildInputs = [ pkgs.jq ];
@@ -64,25 +48,6 @@ in
'';
};
- dockerSocket.enable = mkOption {
- type = types.bool;
- default = false;
- description = ''
- Make the Podman socket available in place of the Docker socket, so
- Docker tools can find the Podman socket.
-
- Podman implements the Docker API.
- '';
- };
-
- dockerCompat = mkOption {
- type = types.bool;
- default = false;
- description = ''
- Create an alias mapping docker to podman.
- '';
- };
-
enableNvidia = mkOption {
type = types.bool;
default = false;
@@ -123,11 +88,9 @@ in
};
- config = lib.mkIf cfg.enable (lib.mkMerge [
+ config = lib.mkIf cfg.enable
{
- home.packages = [ cfg.package ]
- ++ lib.optional cfg.dockerCompat dockerCompat;
-
+ home.packages = [ cfg.package ];
xdg.configFile."cni/net.d/87-podman-bridge.conflist".source = net-conflist;
virtualisation.containers = {
@@ -173,11 +136,6 @@ in
};
Install.WantedBy = [ "sockets.target" ];
};
-
};
- }
- (lib.mkIf cfg.dockerSocket.enable {
- home.sessionVariables."DOCKER_HOST" = "unix:///run/user/$UID/podman/podman.sock";
- })
- ]);
+ };
}
diff --git a/users/profiles/podman/default.nix b/users/profiles/podman/default.nix
index 24061fa..b9eeb4a 100644
--- a/users/profiles/podman/default.nix
+++ b/users/profiles/podman/default.nix
@@ -2,5 +2,8 @@
{
services.podman.enable = true;
services.podman.defaultNetwork.dnsname.enable = true;
- services.podman.dockerSocket.enable = true;
+ services.podman.dockerCompat = {
+ dockerSocket.enable = true;
+ dockerCompose.enable = true;
+ };
}