{pkgs, lib, config, ...}: let cfg = config.services.loomio; package = pkgs.loomio; env = { RAILS_ENV = "production"; BUNDLE_FORCE_RUBY_PLATFORM = "true"; LOOMIO_DATABASE = "loomio"; LOOMIO_ENCRYPTED_CREDENTIALS_PATH = cfg.encyrptedCredentials; }; cfgService = { User = "loomio"; Group = "loomio"; WorkingDirectory = package; StateDirectory = "loomio"; }; in { imports = []; options = { services.loomio = { enable = lib.mkEnableOption "loomio"; encyrptedCredentials = lib.mkOption { description = "Credentials required to run loomio"; type = lib.types.path; }; credentialEncryptionKeyFile = lib.mkOption { description = "File containing encryption key for the encyptedCredentials"; type = lib.types.path; }; }; }; config = { users.groups.loomio = {}; users.users.loomio = { description = "User to run loomio"; group = "loomio"; isSystemUser = true; }; systemd.services.loomio-init-dirs = { enable = true; after = ["network.target" ]; serviceConfig = cfgService // { Type = "oneshot"; }; script = '' cat > /var/lib/loomio/.secrets_env <