From b0180fa1e1dd9f3d1aff1d2453b1c6fedd969ff8 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Thu, 4 Jul 2024 16:42:17 -0400 Subject: [PATCH] feat: Allow overriding namespace Also use `${service}.${name}` as the default namespace. Do this for postgres, to begin with. --- nix/lib.nix | 21 ++++++++++++++++----- nix/postgres/default.nix | 4 ++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/nix/lib.nix b/nix/lib.nix index ebf6bf06..81c8d56c 100644 --- a/nix/lib.nix +++ b/nix/lib.nix @@ -8,25 +8,36 @@ { config, pkgs, lib, ... }: let # Derive name from filename - name = lib.pipe mod [ + service = lib.pipe mod [ builtins.baseNameOf (lib.strings.splitString ".") builtins.head ]; in { - options.services.${name} = lib.mkOption { + options.services.${service} = lib.mkOption { description = '' - ${name} service + ${service} service ''; default = { }; type = lib.types.attrsOf (lib.types.submoduleWith { specialArgs = { inherit pkgs; }; - modules = [ mod ]; + modules = [ + ({ name, ... }: { + options.namespace = lib.mkOption { + description = '' + Namespace for the ${service} service + ''; + default = "${service}.${name}"; + type = lib.types.str; + }; + }) + mod + ]; }); }; config.settings.imports = - lib.pipe config.services.${name} [ + lib.pipe config.services.${service} [ (lib.filterAttrs (_: cfg: cfg.enable)) (lib.mapAttrsToList (_: cfg: cfg.outputs.settings)) ]; diff --git a/nix/postgres/default.nix b/nix/postgres/default.nix index f9d114e7..8d0eaf7d 100644 --- a/nix/postgres/default.nix +++ b/nix/postgres/default.nix @@ -301,7 +301,7 @@ in in { command = setupScript; - namespace = name; + inherit (config) namespace; }; # DB process @@ -329,6 +329,7 @@ in ] ++ (lib.optional (config.superuser != null) "-U ${config.superuser}"); in { + inherit (config) namespace; command = startScript; # SIGINT (= 2) for faster shutdown: https://www.postgresql.org/docs/current/server-shutdown.html shutdown.signal = 2; @@ -340,7 +341,6 @@ in success_threshold = 1; failure_threshold = 5; }; - namespace = name; depends_on."${name}-init".condition = "process_completed_successfully"; # https://github.com/F1bonacc1/process-compose#-auto-restart-if-not-healthy availability.restart = "on_failure";