Add convenient CLI wrapper to NixOS module

This commit is contained in:
Olivier 'reivilibre' 2024-05-21 21:49:39 +01:00
parent cee16de4d1
commit c032fcbfa1

View File

@ -154,12 +154,21 @@ in
}; };
}; };
config = { config = let
configPath = writeTOML "idcoop_config.toml" cfg.settings;
in {
users.users.idcoop = mkIf (cfg.enable && cfg.user == defaultUser) { users.users.idcoop = mkIf (cfg.enable && cfg.user == defaultUser) {
isSystemUser = true; isSystemUser = true;
group = cfg.group; group = cfg.group;
home = mkDefault "/var/lib/idcoop"; home = mkDefault "/var/lib/idcoop";
createHome = true; createHome = true;
packages = [
# Add a wrapper for the idcoop command so the user can use the CLI conveniently
(pkgs.writeShellScriptBin "idcoop" ''
IDCOOP_CONFIG=${pkgs.lib.escapeShellArg configPath} IDCOOP_SECRETS=${pkgs.lib.escapeShellArg cfg.secretsPath} exec ${idcoop}/bin/idcoop "$@"
'')
];
}; };
users.groups.idcoop = mkIf (cfg.enable && cfg.group == defaultUser) {}; users.groups.idcoop = mkIf (cfg.enable && cfg.group == defaultUser) {};
@ -169,11 +178,8 @@ in
after = [ "networking.target" "network-online.target" "postgresql.service" ]; after = [ "networking.target" "network-online.target" "postgresql.service" ];
serviceConfig = serviceConfig =
let
configPath = writeTOML "idcoop_config.toml" cfg.settings;
in
{ {
ExecStart = "${idcoop}/bin/idcoop --config ${configPath} --secrets ${cfg.secretsPath} serve"; ExecStart = "${idcoop}/bin/idcoop --config ${pkgs.lib.escapeShellArg configPath} --secrets ${pkgs.lib.escapeShellArg cfg.secretsPath} serve";
User = cfg.user; User = cfg.user;
Group = cfg.group; Group = cfg.group;
}; };