Skip to content

Commit

Permalink
feat: Allow overriding namespace
Browse files Browse the repository at this point in the history
Also use `${service}.${name}` as the default namespace.

Do this for postgres, to begin with.
  • Loading branch information
srid committed Jul 4, 2024
1 parent 4eee29c commit b0180fa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
21 changes: 16 additions & 5 deletions nix/lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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))
];
Expand Down
4 changes: 2 additions & 2 deletions nix/postgres/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ in
in
{
command = setupScript;
namespace = name;
inherit (config) namespace;
};

# DB process
Expand Down Expand Up @@ -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;
Expand All @@ -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";
Expand Down

0 comments on commit b0180fa

Please sign in to comment.