-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
119 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ | |
age.sshKeyPaths = [ "/home/rs/.ssh/id_ed25519" ]; | ||
secrets = { | ||
hashed_password.neededForUsers = true; | ||
acme_credentials = { }; | ||
"wg/keys/client" = { }; | ||
"wg/keys/server" = { }; | ||
"wg/keys/preshared/lap" = { }; | ||
|
@@ -98,6 +99,11 @@ | |
}; | ||
|
||
services = { | ||
security.acme = { | ||
enable = true; | ||
email = "[email protected]"; | ||
}; | ||
|
||
media = { | ||
immich.enable = true; | ||
jellyfin.enable = true; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,6 @@ | |
./media | ||
./misc | ||
./networking | ||
./security | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,23 +2,10 @@ | |
let | ||
cfg = config.services.networking.traefik; | ||
in | ||
# Due to non external factors traefik can't be used yet with authentik-nix. | ||
# Therefore router Firewall is disabled by default. | ||
# When done | ||
# TODO: Authentik-nix | ||
# TODO: Remove most if not all "openFirewall" instances in Config | ||
# TODO: Replace SearXNG with selfhosted instance | ||
{ | ||
options = { | ||
homelab.domain = lib.mkOption { | ||
default = "nix-pi.ipv64.de"; | ||
type = lib.types.nonEmptyStr; | ||
example = "myHomeLab.de"; | ||
description = "The Domain which exposes all Services"; | ||
}; | ||
|
||
services.networking.traefik.enable = lib.mkEnableOption "Traefik"; | ||
}; | ||
options.services.networking.traefik.enable = lib.mkEnableOption "Traefik"; | ||
|
||
config = lib.mkMerge [ | ||
(lib.mkIf cfg.enable { | ||
|
@@ -27,50 +14,83 @@ in | |
443 | ||
]; | ||
|
||
services.traefik = { | ||
enable = true; | ||
services.traefik = | ||
let | ||
basePath = "/var/lib/acme/${config.networking.domain}"; | ||
in | ||
{ | ||
enable = true; | ||
|
||
dynamicConfigOptions.http.routers.dashboard = { | ||
rule = "Host(`traefik.${config.homelab.domain}`)"; | ||
service = "api@internal"; | ||
}; | ||
dynamicConfigOptions = | ||
let | ||
certs = { | ||
certFile = "${basePath}/cert.pem"; | ||
keyFile = "${basePath}/key.pem"; | ||
}; | ||
in | ||
{ | ||
tls = { | ||
stores.default.defaultCertificate = certs; | ||
certificates = [ (certs // { stores = "default"; }) ]; | ||
}; | ||
|
||
staticConfigOptions = { | ||
global = { | ||
checkNewVersion = false; | ||
sendAnonymousUsage = false; | ||
}; | ||
http.routers.dashboard = { | ||
rule = "Host(`traefik.${config.networking.domain}`)"; | ||
service = "api@internal"; | ||
}; | ||
}; | ||
|
||
api = { | ||
disableDashboardAd = true; | ||
insecure = true; # TODO: Revert when using HTTPS | ||
}; | ||
staticConfigOptions = { | ||
global = { | ||
checkNewVersion = false; | ||
sendAnonymousUsage = false; | ||
}; | ||
|
||
log = { | ||
level = "INFO"; | ||
filePath = "${config.services.traefik.dataDir}/traefik.log"; | ||
format = "json"; | ||
}; | ||
api = { | ||
dashboard = true; | ||
disableDashboardAd = true; | ||
}; | ||
|
||
entryPoints = { | ||
web = { | ||
address = ":80"; | ||
# http.redirections.entryPoint = { | ||
# to = "websecure"; | ||
# scheme = "https"; | ||
# permanent = true; | ||
# }; | ||
log = { | ||
level = "INFO"; | ||
filePath = "${config.services.traefik.dataDir}/traefik.log"; | ||
format = "json"; | ||
}; | ||
websecure = { | ||
address = ":443"; | ||
# http.tls = { | ||
# certResolver = "letsencrypt"; | ||
# domains = [ ]; | ||
# }; | ||
|
||
certificatesResolvers.letsencrypt.acme = { | ||
email = "[email protected]"; | ||
storage = "${config.services.traefik.dataDir}/cert.json"; | ||
dnsChallenge = { | ||
provider = "ipv64"; | ||
resolvers = [ "1.1.1.1:53" ]; # TODO: Change Resolver? | ||
}; | ||
}; | ||
|
||
entryPoints = { | ||
web = { | ||
address = ":80"; | ||
http.redirections.entryPoint = { | ||
to = "websecure"; | ||
scheme = "https"; | ||
permanent = true; | ||
}; | ||
}; | ||
websecure = { | ||
address = ":443"; | ||
asDefault = true; | ||
http.tls = { | ||
certResolver = "letsencrypt"; | ||
domains = [ | ||
{ | ||
main = "${config.networking.domain}"; | ||
sans = [ "*.${config.networking.domain}" ]; | ||
} | ||
]; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}) | ||
|
||
(lib.mkIf config.isImpermanenceEnabled { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ config, lib, ... }: | ||
let | ||
cfg = config.services.security.acme; | ||
in | ||
{ | ||
options.services.security.acme = { | ||
enable = lib.mkEnableOption "ACME"; | ||
|
||
email = lib.mkOption { | ||
readOnly = true; | ||
type = lib.types.nonEmptyStr; | ||
example = "[email protected]"; | ||
description = "The default Email for all Certificates"; | ||
}; | ||
}; | ||
|
||
config = lib.mkMerge [ | ||
(lib.mkIf cfg.enable { | ||
security.acme = { | ||
acceptTerms = true; | ||
defaults = { | ||
inherit (cfg) email; | ||
dnsProvider = "ipv64"; | ||
credentialFiles = { | ||
IPV64_API_KEY_FILE = config.sops.secrets.acme_credentials.path; | ||
}; | ||
}; | ||
certs."${config.networking.domain}" = { | ||
group = "traefik"; | ||
extraDomainNames = [ "*.${config.networking.domain}" ]; | ||
}; | ||
}; | ||
}) | ||
|
||
(lib.mkIf config.isImpermanenceEnabled { | ||
environment.persistence."/persist".directories = lib.optional cfg.enable "/var/lib/acme"; | ||
}) | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ imports = [ ./acme.nix ]; } |