Skip to content

Commit

Permalink
refactor profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
esselius committed Jul 13, 2024
1 parent 86f87e8 commit e425721
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 43 deletions.
17 changes: 8 additions & 9 deletions nixos-configurations/adama.nix
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,14 @@
}];
profiles.monitoring = {
enable = true;
grafana = {
domain = "adama";
oauth = {
client_id_file = builtins.toFile "grafana-client-id" "grafana";
client_secret_file = builtins.toFile "grafana-client-secret" "secret";
auth_url = "http://adama:9000/application/o/authorize/";
token_url = "http://adama:9000/application/o/token/";
api_url = "http://adama:9000/application/o/userinfo/";
};
domain = "adama";
oauth = {
name = "Authentik";
client_id_file = builtins.toFile "grafana-client-id" "grafana";
client_secret_file = builtins.toFile "grafana-client-secret" "secret";
auth_url = "http://adama:9000/application/o/authorize/";
token_url = "http://adama:9000/application/o/token/";
api_url = "http://adama:9000/application/o/userinfo/";
};
};
}
3 changes: 3 additions & 0 deletions nixos-modules/profiles/auth.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ in
options = {
profiles.auth = {
enable = mkEnableOption "auth";
domain = mkOption {
type = types.str;
};
listen_http = mkOption {
type = types.str;
default = "0.0.0.0:9000";
Expand Down
55 changes: 30 additions & 25 deletions nixos-modules/profiles/monitoring.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,31 @@ in
{
options.profiles.monitoring = {
enable = mkEnableOption "Enable Grafana";
grafana = {
domain = mkOption {
domain = mkOption {
type = types.str;
};
root_url = mkOption {
type = types.str;
default = "%(protocol)s://%(domain)s:%(http_port)s/";
};
oauth = {
name = mkOption {
type = types.str;
};
oauth = {
auth_url = mkOption {
type = types.str;
};
token_url = mkOption {
type = types.str;
};
api_url = mkOption {
type = types.str;
};
client_id_file = mkOption {
type = types.path;
};
client_secret_file = mkOption {
type = types.path;
};
auth_url = mkOption {
type = types.str;
};
token_url = mkOption {
type = types.str;
};
api_url = mkOption {
type = types.str;
};
client_id_file = mkOption {
type = types.path;
};
client_secret_file = mkOption {
type = types.path;
};
};
};
Expand All @@ -35,19 +40,19 @@ in
enable = true;
settings = {
server = {
domain = cfg.grafana.domain;
inherit (cfg) domain root_url;
http_port = 3000;
http_addr = "0.0.0.0";
};
"auth.generic_oauth" = {
enabled = true;
name = "Authentik";
client_id = "$__file{${cfg.grafana.oauth.client_id_file}}";
client_secret = "$__file{${cfg.grafana.oauth.client_secret_file}}";
name = cfg.oauth.name;
client_id = "$__file{${cfg.oauth.client_id_file}}";
client_secret = "$__file{${cfg.oauth.client_secret_file}}";
scopes = "openid email profile offline_access";
auth_url = cfg.grafana.oauth.auth_url;
token_url = cfg.grafana.oauth.token_url;
api_url = cfg.grafana.oauth.api_url;
auth_url = cfg.oauth.auth_url;
token_url = cfg.oauth.token_url;
api_url = cfg.oauth.api_url;
tls_skip_verify_insecure = true;
allow_assign_grafana_admin = true;
role_attribute_path = "contains(groups[*], 'Grafana Admin') && 'GrafanaAdmin' || 'Viewer'";
Expand Down
17 changes: 8 additions & 9 deletions tests/monitoring-auth.nix
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,14 @@
}];
profiles.monitoring = {
enable = true;
grafana = {
domain = "localhost";
oauth = {
client_id_file = builtins.toFile "grafana-client-id" "grafana";
client_secret_file = builtins.toFile "grafana-client-secret" "secret";
auth_url = "http://127.0.0.1:9000/application/o/authorize/";
token_url = "http://127.0.0.1:9000/application/o/token/";
api_url = "http://127.0.0.1:9000/application/o/userinfo/";
};
domain = "localhost";
oauth = {
name = "Authentik";
client_id_file = builtins.toFile "grafana-client-id" "grafana";
client_secret_file = builtins.toFile "grafana-client-secret" "secret";
auth_url = "http://127.0.0.1:9000/application/o/authorize/";
token_url = "http://127.0.0.1:9000/application/o/token/";
api_url = "http://127.0.0.1:9000/application/o/userinfo/";
};
};
};
Expand Down

0 comments on commit e425721

Please sign in to comment.