Skip to content

Instantly share code, notes, and snippets.

@infinisil
Created September 10, 2023 13:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save infinisil/e29ee58a8184eeb7a2e139c2b2d3e4ff to your computer and use it in GitHub Desktop.
Save infinisil/e29ee58a8184eeb7a2e139c2b2d3e4ff to your computer and use it in GitHub Desktop.
{ pkgs, lib, config, ... }: with lib.types;
let
postgresqlInstanceType = submodule {
options.connectionString = lib.mkOption {
type = str;
};
};
in {
options.services = lib.mkOption {
type = attrsOf (submodule {
options.process = lib.mkOption {
type = str;
};
options.args = lib.mkOption {
type = listOf str;
};
});
};
options.postgresqlInstances = lib.mkOption {
type = attrsOf postgresqlInstanceType;
};
options.postgresql = lib.mkOption {
type = postgresqlInstanceType;
};
config.services = lib.mapAttrs' (name: cfg:
lib.nameValuePair "postgresql-${name}" {
process = "postgresql";
args = [ cfg.connectionString ];
}
}) config.postgresql;
# mkAliasSomething would also be nice here
config.postgresqlInstances.default = config.postgresql;
# ^ Module
# v User
#config.postgresql.instances.foo.connectionString = "bla";
config.postgresqlInstances.bar.connectionString = "baz";
config.postgresql.connectionString = "bla";
}
@adrian-gierakowski
Copy link

I believe line 37 should be

}) config. postgresqlInstances;

btw. is the formatting intentional?

@infinisil
Copy link
Author

Ah you're right :D

Not sure what formatting you mean?

@adrian-gierakowski
Copy link

Not sure what formatting you mean?

must have been a GitHub bug: it was showing no indentation whatsoever but it looks good now 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment