-
-
Save usmcamp0811/37b703bd4f78836cd1cd340da300da1d to your computer and use it in GitHub Desktop.
Use podman within a nix-shell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ pkgs ? import <nixpkgs> {} }: | |
let | |
# To use this shell.nix on NixOS your user needs to be configured as such: | |
# users.extraUsers.adisbladis = { | |
# subUidRanges = [{ startUid = 100000; count = 65536; }]; | |
# subGidRanges = [{ startGid = 100000; count = 65536; }]; | |
# }; | |
# Provides a script that copies required files to ~/ | |
podmanSetupScript = let | |
registriesConf = pkgs.writeText "registries.conf" '' | |
[registries.search] | |
registries = ['docker.io'] | |
[registries.block] | |
registries = [] | |
''; | |
in pkgs.writeScript "podman-setup" '' | |
#!${pkgs.runtimeShell} | |
# Dont overwrite customised configuration | |
if ! test -f ~/.config/containers/policy.json; then | |
install -Dm555 ${pkgs.skopeo.src}/default-policy.json ~/.config/containers/policy.json | |
fi | |
if ! test -f ~/.config/containers/registries.conf; then | |
install -Dm555 ${registriesConf} ~/.config/containers/registries.conf | |
fi | |
''; | |
# Provides a fake "docker" binary mapping to podman | |
dockerCompat = pkgs.runCommandNoCC "docker-podman-compat" {} '' | |
mkdir -p $out/bin | |
ln -s ${pkgs.podman}/bin/podman $out/bin/docker | |
''; | |
in pkgs.mkShell { | |
buildInputs = [ | |
dockerCompat | |
pkgs.podman # Docker compat | |
pkgs.runc # Container runtime | |
pkgs.conmon # Container runtime monitor | |
pkgs.skopeo # Interact with container registry | |
pkgs.slirp4netns # User-mode networking for unprivileged namespaces | |
pkgs.fuse-overlayfs # CoW for images, much faster than default vfs | |
]; | |
shellHook = '' | |
# Install required configuration | |
${podmanSetupScript} | |
''; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment