### Alternative Installation Methods Source: https://github.com/aksiksi/compose2nix/blob/main/README.md Instructions for installing compose2nix using different methods. ```bash nix shell github:aksiksi/compose2nix ``` ```bash go install github.com/aksiksi/compose2nix ``` ```bash make build ``` -------------------------------- ### Install from nixpkgs Source: https://github.com/aksiksi/compose2nix/blob/main/README.md Install the compose2nix CLI by adding it to your NixOS configuration. ```nix environment.systemPackages = [ pkgs.compose2nix ]; ``` -------------------------------- ### Usage Example Source: https://github.com/aksiksi/compose2nix/blob/main/testdata/sops-example/README.md Command to run compose2nix to generate a docker-compose.nix file from a compose.yml and sops secrets. ```bash compose2nix \ --sops_file ./secrets/pinnacle.yaml \ --inputs compose.yml \ --output docker-compose.nix ``` -------------------------------- ### sops-nix Integration Example Source: https://github.com/aksiksi/compose2nix/blob/main/README.md Example of how to configure sops-nix secrets for a Compose service and the resulting NixOS configuration. ```yaml services: webapp: image: nginx:latest labels: - "compose2nix.settings.sops.secrets=example.env,some-folder/example-2.env" ``` ```bash compose2nix \ --inputs docker-compose.yml \ --sops_file ./secrets/secrets.yaml ``` ```nix virtualisation.oci-containers.containers."webapp" = { image = "nginx:latest"; # ... environmentFiles = [ "/etc/existing-file.env" # passed in via CLI # sops-nix secrets config.sops.secrets."example.env".path config.sops.secrets."folder/example-2.env".path ]; }; ``` -------------------------------- ### Compose Build spec - Example service Source: https://github.com/aksiksi/compose2nix/blob/main/README.md Example of a service with a build specification. ```yaml services: my-service: build: . ``` -------------------------------- ### Generated NixOS Configuration Source: https://github.com/aksiksi/compose2nix/blob/main/testdata/sops-example/README.md Example of how sops secrets are added as environment files to a NixOS container configuration. ```nix virtualisation.oci-containers.containers."webapp" = { image = "nginx:latest"; environmentFiles = [ config.sops.secrets."example.env".path config.sops.secrets."folder.example-2.env".path ]; }; ``` -------------------------------- ### Compose Labels for Secrets Source: https://github.com/aksiksi/compose2nix/blob/main/testdata/sops-example/README.md Example of using compose2nix.sops.secret label to reference sops secrets within a compose file. ```yaml services: webapp: image: nginx:latest labels: - "compose2nix.sops.secret=example.env,folder.example-2.env" ``` -------------------------------- ### Run using nix run Source: https://github.com/aksiksi/compose2nix/blob/main/README.md Install the compose2nix CLI by running it directly using nix run. ```bash nix run github:aksiksi/compose2nix -- -h ``` ```bash nix run github:aksiksi/compose2nix/v0.3.0 -- -h ``` ```bash nix run github:aksiksi/compose2nix/0c38d282d6662fc902fca7ef5b33e889f9e3e59a -- -h ``` -------------------------------- ### docker compose up - Start service target Source: https://github.com/aksiksi/compose2nix/blob/main/README.md Systemd command to start a compose service's root target. ```bash sudo systemctl start podman-compose-myservice-root.target ``` -------------------------------- ### Compose Build spec - Start build service Source: https://github.com/aksiksi/compose2nix/blob/main/README.md Command to start the systemd service for a container build. ```bash sudo systemctl start podman-build-my-service.service ``` -------------------------------- ### Working with Secrets using agenix Source: https://github.com/aksiksi/compose2nix/blob/main/README.md Example of how to use compose2nix with agenix for secret management. ```bash compose2nix --env_files=/run/agenix/my-env-file.env --include_env_files=true ``` -------------------------------- ### Add to flake.nix Source: https://github.com/aksiksi/compose2nix/blob/main/README.md Add the compose2nix package to your flake.nix and install it. ```nix compose2nix.url = "github:aksiksi/compose2nix"; compose2nix.inputs.nixpkgs.follows = "nixpkgs"; ``` ```nix compose2nix.url = "github:aksiksi/compose2nix/v0.3.0"; ``` ```nix environment.systemPackages = [ inputs.compose2nix.packages.x86_64-linux.default ]; ``` -------------------------------- ### Example Compose file demonstrating UpheldBy issue Source: https://github.com/aksiksi/compose2nix/blob/main/README.md Illustrates a Docker Compose file where a service ('app') depends on another ('db'), and how manually stopping 'app' can lead to 'db' restarting due to 'UpheldBy'. ```yaml services: app: image: myname/app depends_on: - db db: image: postgres ``` -------------------------------- ### Pass CDI devices via 'devices' or 'deploy' Source: https://github.com/aksiksi/compose2nix/blob/main/README.md Example of how to configure services to pass Nvidia GPU devices using either the 'devices' or 'deploy' field in a Compose file. ```yaml services: myservice: # ... other fields # Option 1 devices: - nvidia.com/gpu=all # Option 2 deploy: resources: reservations: devices: # Driver must be set to "cdi" - all others are ignored. - driver: cdi device_ids: - nvidia.com/gpu=all # Required for Podman. security_opt: - label=disable ``` -------------------------------- ### Podman network configuration workaround Source: https://github.com/aksiksi/compose2nix/blob/main/README.md Example of a Compose network configuration that removes the 'internal' setting and uses 'no_default_route=1' to enable port forwarding from the host to Podman containers in isolated networks. ```yaml networks: my-network: driver: bridge driver_opts: no_default_route: 1 # <<< This is what prevents external network access. ipam: config: - subnet: 10.8.1.0/24 gateway: 10.8.1.0 ``` -------------------------------- ### List all services in a project Source: https://github.com/aksiksi/compose2nix/blob/main/README.md Command to list systemd units for services within a specific project. ```bash sudo systemctl list-units *myservice* ``` -------------------------------- ### Run compose2nix Source: https://github.com/aksiksi/compose2nix/blob/main/README.md Run the compose2nix tool, specifying the project name. ```bash compose2nix -project=myproject ``` -------------------------------- ### List all services Source: https://github.com/aksiksi/compose2nix/blob/main/README.md Command to list all systemd units related to Podman services. ```bash sudo systemctl list-units podman-* ``` -------------------------------- ### Auto-start services on boot - Disable for single service Source: https://github.com/aksiksi/compose2nix/blob/main/README.md Compose label to disable auto-start for a specific service. ```yaml services: my-service: labels: - "compose2nix.settings.autoStart=false" ``` -------------------------------- ### Podman Auto-update Containers - Nix Configuration Source: https://github.com/aksiksi/compose2nix/blob/main/README.md Nix configuration to enable the Podman auto-update timer. ```nix systemd.timers."podman-auto-update".wantedBy = [ "timers.target" ]; ``` -------------------------------- ### compose2nix Usage Source: https://github.com/aksiksi/compose2nix/blob/main/README.md Command-line arguments and their descriptions for the compose2nix tool. ```bash $ compose2nix -h Usage of compose2nix: -auto_format if true, Nix output will be formatted using "nixfmt" (must be present in $PATH). -auto_start auto-start setting for generated service(s). this applies to all services, not just containers. (default true) -build if set, generated container build systemd services will be enabled. -check_bind_mounts if set, check that bind mount paths exist. this is useful if running the generated Nix code on the same machine. -check_systemd_mounts if set, volume paths will be checked against systemd mount paths on the current machine and marked as container dependencies. -create_root_target if set, a root systemd target will be created, which when stopped tears down all resources. (default true) -default_stop_timeout duration default stop timeout for generated container services. (default 1m30s) -enable_option generate a NixOS module option. this allows you to enable or disable the generated module from within your NixOS config. by default, the option will be named "options.[project_name]", but you can add a prefix using the "option_prefix" flag. -env_files string one or more comma-separated paths to .env file(s). -env_files_only only use env file(s) in the NixOS container definitions. -generate_unused_resources if set, unused resources (e.g., networks) will be generated even if no containers use them. -ignore_missing_env_files if set, missing env files will be ignored. -include_env_files include env files in the NixOS container definition. -inputs string one or more comma-separated path(s) to Compose file(s). (default "docker-compose.yml") -option_prefix string Prefix for the option. If empty, the project name will be used as the option name. (e.g. custom.containers) -output string path to output Nix file. (default "docker-compose.nix") -project string project name used as a prefix for generated resources. this overrides any top-level "name" set in the Compose file(s). -remove_volumes if set, volumes will be removed on systemd service stop. -root_path string absolute path to use as the root for any relative paths in the Compose file (e.g., volumes, env files). defaults to the current working directory. -runtime string one of: ["podman", "docker"]. (default "podman") -service_include string regex pattern for services to include. -sops_file string path to encrypted secrets YAML file (e.g., secrets.yaml). when set, secrets defined in compose services using "compose2nix.sops.secret=secret1,secret2" labels will be added as environmentFiles. -use_compose_log_driver if set, always use the Docker Compose log driver. -use_upheld_by if set, upheldBy will be used for service dependencies (NixOS 24.05+). -version display version and exit -warnings_as_errors if set, treat generator warnings as hard errors. -write_nix_setup if true, Nix setup code is written to output (runtime, DNS, autoprune, etc.) (default true) ``` -------------------------------- ### Enable CDI support in NixOS Source: https://github.com/aksiksi/compose2nix/blob/main/README.md Configuration to enable Nvidia GPU support via Container Device Interface (CDI). ```nix { hardware.nvidia-container-toolkit.enable = true; } ``` -------------------------------- ### Restart a service Source: https://github.com/aksiksi/compose2nix/blob/main/README.md Command to restart a specific Podman service, considering container_name. ```bash sudo systemctl restart podman-myproject-myservice.service ``` -------------------------------- ### Pin Docker version for CDI support Source: https://github.com/aksiksi/compose2nix/blob/main/README.md Ensures Docker version 25 or higher is used, which is required for CDI support. ```nix { virtualisation.docker.package = pkgs.docker_25; } ``` -------------------------------- ### Update a Container - Pull Image Source: https://github.com/aksiksi/compose2nix/blob/main/README.md Command to pull the latest image for a container using Podman and jq. ```bash sudo podman pull $(sudo podman inspect myproject-myservice | jq -r .[0].ImageName) ``` -------------------------------- ### Podman Auto-update Containers - Enable Label Source: https://github.com/aksiksi/compose2nix/blob/main/README.md Label to add to Compose services for enabling Podman auto-update. ```yaml services: my-service: labels: - "io.containers.autoupdate=registry" ``` -------------------------------- ### docker compose down - Stop service target Source: https://github.com/aksiksi/compose2nix/blob/main/README.md Systemd command to stop a compose service's root target. ```bash sudo systemctl stop podman-compose-myservice-root.target ``` -------------------------------- ### Update secrets Source: https://github.com/aksiksi/compose2nix/blob/main/nixos-test/sops/README.md Command to edit secrets.yaml using sops with a specified age key file. ```shell cd nixos-test/sops nix-shell -p sops --run "SOPS_AGE_KEY_FILE=age-key.txt sops edit secrets.yaml" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.