Add custom isTailscaleDomain lib

This commit is contained in:
SebastianStork 2025-10-12 20:36:18 +02:00
parent 589b76d745
commit f3ea2b75e6
6 changed files with 15 additions and 11 deletions

View file

@ -1,14 +1,15 @@
{ {
inputs, inputs,
self, self,
lib,
... ...
}: }:
let let
lib = inputs.nixpkgs.lib.extend (_: _: { custom = import ../lib inputs.nixpkgs.lib; });
mkHost = mkHost =
hostName: hostName:
inputs.nixpkgs.lib.nixosSystem { inputs.nixpkgs.lib.nixosSystem {
specialArgs = { inherit inputs self; }; specialArgs = { inherit inputs self lib; };
modules = [ modules = [
{ networking = { inherit hostName; }; } { networking = { inherit hostName; }; }
"${self}/hosts/common.nix" "${self}/hosts/common.nix"

View file

@ -1,10 +1,11 @@
{ self, lib, ... }: { self, lib, ... }:
let let
modulesOf = dir: dir |> lib.filesystem.listFilesRecursive |> lib.filter (lib.hasSuffix ".nix"); listNixFilesRecursive =
dir: dir |> lib.filesystem.listFilesRecursive |> lib.filter (lib.hasSuffix ".nix");
in in
{ {
flake = { flake = {
nixosModules.default.imports = modulesOf "${self}/modules/system"; nixosModules.default.imports = listNixFilesRecursive "${self}/modules/system";
homeManagerModules.default.imports = modulesOf "${self}/modules/home"; homeManagerModules.default.imports = listNixFilesRecursive "${self}/modules/home";
}; };
} }

3
lib/default.nix Normal file
View file

@ -0,0 +1,3 @@
lib: {
isTailscaleDomain = domain: domain |> lib.hasSuffix ".ts.net";
}

View file

@ -10,7 +10,7 @@ let
virtualHosts = cfg.virtualHosts |> lib.attrValues |> lib.filter (value: value.enable); virtualHosts = cfg.virtualHosts |> lib.attrValues |> lib.filter (value: value.enable);
isTailscaleDomain = domain: domain |> lib.hasSuffix config.custom.services.tailscale.domain; isTailscaleDomain = domain: lib.custom.isTailscaleDomain domain;
tailscaleHosts = virtualHosts |> lib.filter (value: isTailscaleDomain value.domain); tailscaleHosts = virtualHosts |> lib.filter (value: isTailscaleDomain value.domain);
nonTailscaleHosts = virtualHosts |> lib.filter (value: !isTailscaleDomain value.domain); nonTailscaleHosts = virtualHosts |> lib.filter (value: !isTailscaleDomain value.domain);

View file

@ -6,7 +6,6 @@
}: }:
let let
cfg = config.custom.services.syncthing; cfg = config.custom.services.syncthing;
tailscaleCfg = config.custom.services.tailscale;
inherit (config.services.syncthing) dataDir; inherit (config.services.syncthing) dataDir;
@ -40,7 +39,7 @@ in
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
assertions = [ assertions = [
{ {
assertion = tailscaleCfg.enable; assertion = config.custom.services.tailscale.enable;
message = "Syncthing requires tailscale."; message = "Syncthing requires tailscale.";
} }
{ {
@ -52,7 +51,7 @@ in
message = "Running syncthing on a server requires `gui.domain` to be set."; message = "Running syncthing on a server requires `gui.domain` to be set.";
} }
{ {
assertion = (cfg.gui.domain != null) -> (cfg.gui.domain |> lib.hasSuffix tailscaleCfg.domain); assertion = (cfg.gui.domain != null) -> (lib.custom.isTailscaleDomain cfg.gui.domain);
message = "The syncthing gui should only be exposed on a private network as it isn't yet configured with access controll."; message = "The syncthing gui should only be exposed on a private network as it isn't yet configured with access controll.";
} }
]; ];
@ -100,7 +99,7 @@ in
|> lib.mapAttrs ( |> lib.mapAttrs (
name: value: { name: value: {
id = value.config.custom.services.syncthing.deviceId; id = value.config.custom.services.syncthing.deviceId;
addresses = [ "tcp://${name}.${tailscaleCfg.domain}:${toString cfg.syncPort}" ]; addresses = [ "tcp://${name}.${config.custom.services.tailscale.domain}:${toString cfg.syncPort}" ];
} }
); );

View file

@ -29,7 +29,7 @@ in
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
assertions = [ assertions = [
{ {
assertion = cfg.domain |> lib.hasSuffix config.custom.services.tailscale.domain; assertion = lib.custom.isTailscaleDomain cfg.domain;
message = "Filebrowser isn't yet configured with access controll."; message = "Filebrowser isn't yet configured with access controll.";
} }
]; ];