Skip to content

Commit

Permalink
avoid some impossible states in authelia and nginx
Browse files Browse the repository at this point in the history
  • Loading branch information
ibizaman committed Dec 1, 2023
1 parent 76e27ae commit 05ce1a3
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 13 deletions.
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
mergeTests (importFiles [
./test/modules/arr.nix
./test/modules/davfs.nix
./test/modules/nginx.nix
./test/modules/postgresql.nix
]);
};
Expand Down
16 changes: 4 additions & 12 deletions modules/blocks/authelia.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,9 @@ in
};

autheliaUser = lib.mkOption {
type = lib.types.nullOr lib.types.str;
description = ''System user for this Authelia instance.
If set to null, defaults to:
<programlisting language="nix">
"authelia_" +
(builtins.replaceStrings ["-" "."] ["_" "_"]
''${shb.authelia.subdomain}.''${shb.authelia.domain}")
</programlisting>
'';
default = null;
type = lib.types.str;
description = "System user for this Authelia instance.";
default = "authelia";
};

secrets = lib.mkOption {
Expand Down Expand Up @@ -120,7 +112,7 @@ If set to null, defaults to:

services.authelia.instances.${fqdn} = {
enable = true;
user = cfg.autheliaUser or "authelia_" + builtins.replaceStrings ["-" "."] ["_" "_"] fqdn;
user = cfg.autheliaUser;

secrets = {
inherit (cfg.secrets) jwtSecretFile storageEncryptionKeyFile;
Expand Down
2 changes: 1 addition & 1 deletion modules/blocks/nginx.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let
};

authEndpoint = lib.mkOption {
type = lib.types.nullOr lib.types.str;
type = lib.types.str;
description = "Auth endpoint for SSO.";
default = null;
example = "https://authelia.example.com";
Expand Down
81 changes: 81 additions & 0 deletions test/modules/nginx.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{ pkgs, lib, ... }:
let
anyOpt = default: lib.mkOption {
type = lib.types.anything;
inherit default;
};

testConfig = m:
let
cfg = (lib.evalModules {
specialArgs = { inherit pkgs; };
modules = [
{
options = {
assertions = anyOpt [];
networking = anyOpt {};
security = anyOpt {};
services = anyOpt {};
shb.authelia = anyOpt {};
shb.backup = anyOpt {};
shb.ssl = anyOpt {};
};
}
../../modules/blocks/nginx.nix
m
];
}).config;
in lib.attrsets.filterAttrsRecursive (n: v: n != "extraConfig") {
inherit (cfg) services;
shb = { inherit (cfg.shb) backup nginx; };
};
in
{
testNoOptions = {
expected = {
shb.backup = {};
shb.nginx = {
accessLog = false;
autheliaProtect = [];
debugLog = false;
};
services.nginx.enable = true;
};
expr = testConfig {};
};

testAuth = {
expected = {
shb.backup = {};
shb.nginx = {
accessLog = false;
autheliaProtect = [{
authEndpoint = "hello";
autheliaRules = [{}];
subdomain = "my";
domain = "example.com";
upstream = "http://127.0.0.1:1234";
}];
debugLog = false;
};
services.nginx.enable = true;
services.nginx.virtualHosts."my.example.com" = {
forceSSL = true;
locations."/" = {};
locations."/authelia" = {};
sslCertificate = "/var/lib/acme/example.com/cert.pem";
sslCertificateKey = "/var/lib/acme/example.com/key.pem";
};
};
expr = testConfig {
shb.ssl.enable = true;
shb.nginx.autheliaProtect = [{
subdomain = "my";
domain = "example.com";
upstream = "http://127.0.0.1:1234";
authEndpoint = "hello";
autheliaRules = [{}];
}];
};
};
}

0 comments on commit 05ce1a3

Please sign in to comment.