Files
infra/modules/nixos/services/docker_manager.nix
Thierry Pouplier b54760f62b docs: initialize NixOS infrastructure with AI assistant
Creates PROJECT.md with vision and requirements.
Creates config.json with interactive workflow mode.
2026-01-01 01:36:58 -05:00

37 lines
1.2 KiB
Nix

{ config, lib, pkgs, ... }:
with lib;
{
options.services.myDockerStacks = mkOption {
type = types.attrsOf (types.submodule {
options = {
path = mkOption { type = types.path; };
ports = mkOption { type = types.listOf types.int; default = []; };
};
});
default = {};
description = "Attribute set of docker-compose stacks to run.";
};
config = {
# Generate the systemd services based on the options provided above
systemd.services = mapAttrs' (name: value: nameValuePair "${name}_stack" {
description = "${name} via Docker Compose";
after = [ "network-online.target" "docker.service" ];
wants = [ "network-online.target" "docker.service" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
WorkingDirectory = value.path;
ExecStartPre = "${pkgs.docker-compose}/bin/docker-compose down";
ExecStart = "${pkgs.docker-compose}/bin/docker-compose up -d";
ExecStop = "${pkgs.docker-compose}/bin/docker-compose down";
RemainAfterExit = true;
};
}) config.services.myDockerStacks;
# Automatically open firewall ports
networking.firewall.allowedTCPPorts = flatten (mapAttrsToList (n: v: v.ports) config.services.myDockerStacks);
};
}