Skip to content

Instantly share code, notes, and snippets.

@adisbladis
Last active April 29, 2024 14:50
Show Gist options
  • Star 50 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save adisbladis/187204cb772800489ee3dac4acdd9947 to your computer and use it in GitHub Desktop.
Save adisbladis/187204cb772800489ee3dac4acdd9947 to your computer and use it in GitHub Desktop.
Use podman within a nix-shell
{ 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}
'';
}
@Tsubajashi
Copy link

would that also effectively fix nvidia in podman? ive recently saw that podman containers relying on nvidia (like Distrobox or AI workloads) failed to properly run in rootless podman.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment