From 5205e606c1dea0a851f40a4d15775789bfc3b7a9 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 5 Jul 2024 18:58:03 +0100 Subject: [PATCH] Docker and postgres config --- hosts/common/optional/docker/default.nix | 20 ++++++++++++++++ hosts/common/optional/docker/postgres.nix | 29 +++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 hosts/common/optional/docker/default.nix create mode 100644 hosts/common/optional/docker/postgres.nix diff --git a/hosts/common/optional/docker/default.nix b/hosts/common/optional/docker/default.nix new file mode 100644 index 0000000..05426f8 --- /dev/null +++ b/hosts/common/optional/docker/default.nix @@ -0,0 +1,20 @@ +{ inputs, ... }: { + + imports = [ inputs.arion.nixosModules.arion ]; + # Arion works with Docker, but for NixOS-based containers, you need Podman + # since NixOS 21.05. + virtualisation = { + podman = { + enable = true; + defaultNetwork.settings.dns_enabled = true; + }; + docker = { + storageDriver = "btrfs"; + rootless = { + enable = true; + setSocketVariable = true; + }; + }; + }; + +} diff --git a/hosts/common/optional/docker/postgres.nix b/hosts/common/optional/docker/postgres.nix new file mode 100644 index 0000000..8138b22 --- /dev/null +++ b/hosts/common/optional/docker/postgres.nix @@ -0,0 +1,29 @@ +{ pkgs, ... }: +{ + virtualisation.arion = { + backend = "docker"; + projects = { + "db".settings.services."db".service = { + image = "postgres:16"; + restart = "unless-stopped"; + environment = { + POSTGRES_PASSWORD = "balls1234"; + POSTGRES_USER = "admin"; + POSTGRES_DATABASE = "test_db"; + }; + ports = [ "5432:5432" ]; + volumes = [ + "/mnt/postgres/data:/var/lib/postgres/data" + "${pkgs.writeScript "load_extensions" '' + psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <