Add docker-compose podman compat
This commit is contained in:
parent
4d9aeb70ca
commit
b713a53961
4 changed files with 73 additions and 46 deletions
|
@ -3,5 +3,6 @@
|
|||
./podman.nix
|
||||
./containers.nix
|
||||
./podman-dnsname.nix
|
||||
./docker-compat.nix
|
||||
];
|
||||
}
|
||||
|
|
65
users/modules/podman/docker-compat.nix
Normal file
65
users/modules/podman/docker-compat.nix
Normal file
|
@ -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 <command>docker</command> to <command>podman</command>.
|
||||
'';
|
||||
};
|
||||
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";
|
||||
})
|
||||
|
||||
]);
|
||||
}
|
|
@ -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 <command>docker</command> to <command>podman</command>.
|
||||
'';
|
||||
};
|
||||
|
||||
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";
|
||||
})
|
||||
]);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue