|
| 1 | +{ |
| 2 | + description = "Dev shell with Podman"; |
| 3 | + |
| 4 | + inputs = { |
| 5 | + nixpkgs.url = "github:NixOS/nixpkgs"; |
| 6 | + flake-utils.url = "github:numtide/flake-utils"; |
| 7 | + }; |
| 8 | + |
| 9 | + outputs = { self, nixpkgs, flake-utils, ... }: flake-utils.lib.eachDefaultSystem (system: |
| 10 | + let |
| 11 | + pkgs = nixpkgs.legacyPackages.${system}; |
| 12 | + # wrapper for tsx, since it is not in nodePackages |
| 13 | + tsx = pkgs.writeShellScriptBin "tsx" |
| 14 | + '' |
| 15 | + exec npx tsx "$@" |
| 16 | + ''; |
| 17 | + # copies config files if they do not exist in home folder |
| 18 | + podmanSetupScript = let |
| 19 | + registriesConf = pkgs.writeText "registries.conf" '' |
| 20 | + [registries.search] |
| 21 | + registries = ['docker.io'] |
| 22 | + [registries.block] |
| 23 | + registries = [] |
| 24 | + ''; |
| 25 | + in pkgs.writeScript "podman-setup" '' |
| 26 | + #!${pkgs.runtimeShell} |
| 27 | + # Dont overwrite customised configuration |
| 28 | + if ! test -f ~/.config/containers/policy.json; then |
| 29 | + install -Dm555 ${pkgs.skopeo.src}/default-policy.json ~/.config/containers/policy.json |
| 30 | + fi |
| 31 | + if ! test -f ~/.config/containers/registries.conf; then |
| 32 | + install -Dm555 ${registriesConf} ~/.config/containers/registries.conf |
| 33 | + fi |
| 34 | + ''; |
| 35 | + # Provides a fake "docker" binary mapping to podman |
| 36 | + dockerCompat = pkgs.runCommandNoCC "docker-podman-compat" {} '' |
| 37 | + mkdir -p $out/bin |
| 38 | + ln -s ${pkgs.podman}/bin/podman $out/bin/docker |
| 39 | + ''; |
| 40 | + |
| 41 | + in { |
| 42 | + devShells.default = self.devShells.${system}.node-shell; |
| 43 | + devShells.node-shell = pkgs.mkShell { |
| 44 | + buildInputs = [ |
| 45 | + pkgs.nodejs |
| 46 | + pkgs.esbuild |
| 47 | + pkgs.nodePackages.typescript-language-server |
| 48 | + pkgs.nodePackages.typescript |
| 49 | + tsx |
| 50 | + ]; |
| 51 | + }; |
| 52 | + devShells.podman-shell = pkgs.mkShell { |
| 53 | + buildInputs = [ |
| 54 | + # For emulating a Nix-less setup |
| 55 | + dockerCompat |
| 56 | + pkgs.podman # Docker compat |
| 57 | + pkgs.runc # Container runtime |
| 58 | + pkgs.conmon # Container runtime monitor |
| 59 | + pkgs.skopeo # Interact with container registry |
| 60 | + pkgs.slirp4netns # User-mode networking for unprivileged namespaces |
| 61 | + pkgs.fuse-overlayfs # CoW for images, much faster than default vfs |
| 62 | + ]; |
| 63 | + # we want to use the Nix shell's provided packages, not npm's |
| 64 | + shellHook = |
| 65 | + '' |
| 66 | + ${podmanSetupScript} |
| 67 | + podman run -it \ |
| 68 | + -v $(pwd):/cdl \ |
| 69 | + -w /cdl \ |
| 70 | + --entrypoint /bin/sh \ |
| 71 | + docker.io/library/node:24-bookworm |
| 72 | + ''; |
| 73 | + }; |
| 74 | + } |
| 75 | + ); |
| 76 | +} |
| 77 | + |
0 commit comments