2024-10-06 15:15:20 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
inputs,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
with lib; let
|
|
|
|
cfg = config.custom.containers.netbox;
|
|
|
|
in {
|
|
|
|
options.custom.containers.netbox.enable = mkOption {default = false;};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
age.secrets = let
|
|
|
|
secret = filename: {
|
|
|
|
file = "${inputs.self}/secrets/${filename}";
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
"${config.custom.profile}/netbox/.env" = secret "${config.custom.profile}/netbox/.env";
|
|
|
|
"${config.custom.profile}/netbox/cache.env" = secret "${config.custom.profile}/netbox/cache.env";
|
|
|
|
"${config.custom.profile}/netbox/db.env" = secret "${config.custom.profile}/netbox/db.env";
|
|
|
|
};
|
|
|
|
|
|
|
|
#?? arion-netbox pull
|
|
|
|
environment.shellAliases.arion-netbox = "sudo arion --prebuilt-file ${config.virtualisation.arion.projects.netbox.settings.out.dockerComposeYaml}";
|
|
|
|
|
|
|
|
# https://github.com/netbox-community/netbox-docker
|
|
|
|
virtualisation.arion.projects.netbox = {
|
|
|
|
serviceName = "netbox";
|
|
|
|
|
|
|
|
# https://github.com/netbox-community/netbox-docker/blob/release/docker-compose.yml
|
|
|
|
settings.services = let
|
|
|
|
netbox = {
|
|
|
|
container_name = "netbox";
|
|
|
|
depends_on = ["cache" "db"];
|
|
|
|
env_file = [config.age.secrets."${config.custom.profile}/netbox/.env".path];
|
2024-10-06 23:52:28 +00:00
|
|
|
image = "localhost/netbox"; # Built image
|
2024-10-06 15:15:20 +00:00
|
|
|
restart = "unless-stopped";
|
2024-10-06 23:52:28 +00:00
|
|
|
user = "unit:root";
|
|
|
|
volumes = ["${config.custom.containers.directory}/netbox/media:/opt/netbox/netbox/media"];
|
2024-10-06 15:15:20 +00:00
|
|
|
};
|
|
|
|
in {
|
|
|
|
netbox.service =
|
|
|
|
netbox
|
|
|
|
// {
|
|
|
|
ports = ["8585:8080"];
|
2024-10-06 23:52:28 +00:00
|
|
|
|
|
|
|
# https://github.com/netbox-community/netbox-docker/wiki/Using-Netbox-Plugins
|
|
|
|
#!! Context modifications require a rebuild
|
|
|
|
#?? arion-netbox build --no-cache
|
|
|
|
build.context = "${./.}";
|
2024-10-06 15:15:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
housekeeping.service =
|
|
|
|
netbox
|
|
|
|
// {
|
|
|
|
container_name = "netbox-housekeeping";
|
|
|
|
command = ["/opt/netbox/housekeeping.sh"];
|
|
|
|
depends_on = ["netbox"];
|
|
|
|
};
|
|
|
|
|
|
|
|
worker.service =
|
|
|
|
netbox
|
|
|
|
// {
|
|
|
|
container_name = "netbox-worker";
|
|
|
|
command = ["/opt/netbox/venv/bin/python" "/opt/netbox/netbox/manage.py" "rqworker"];
|
|
|
|
depends_on = ["netbox"];
|
|
|
|
};
|
|
|
|
|
|
|
|
cache.service = {
|
|
|
|
container_name = "netbox-cache";
|
|
|
|
command = ["sh" "-c" "valkey-server --requirepass $$REDIS_PASSWORD"];
|
|
|
|
env_file = [config.age.secrets."${config.custom.profile}/netbox/cache.env".path];
|
|
|
|
image = "docker.io/valkey/valkey:8.0";
|
|
|
|
restart = "unless-stopped";
|
|
|
|
};
|
|
|
|
|
|
|
|
db.service = {
|
|
|
|
container_name = "netbox-db";
|
|
|
|
env_file = [config.age.secrets."${config.custom.profile}/netbox/db.env".path];
|
|
|
|
image = "docker.io/postgres:16";
|
|
|
|
restart = "unless-stopped";
|
2024-10-06 23:52:28 +00:00
|
|
|
volumes = ["${config.custom.containers.directory}/netbox/db:/var/lib/postgresql/data"];
|
2024-10-06 15:15:20 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2024-10-06 23:52:28 +00:00
|
|
|
|
|
|
|
#!! Required for correct volume permissions
|
|
|
|
systemd.tmpfiles.rules = ["z ${config.custom.containers.directory}/netbox/media 0770 999 root"]; # unit:root
|
2024-10-06 15:15:20 +00:00
|
|
|
};
|
|
|
|
}
|