mirror of
https://github.com/SebastianStork/nixos-config.git
synced 2026-01-21 14:01:34 +01:00
Refactor
This commit is contained in:
parent
0d7164fe0a
commit
49c918f747
13 changed files with 53 additions and 53 deletions
|
|
@ -8,10 +8,10 @@ let
|
|||
cfg = config.custom.services.caddy;
|
||||
netCfg = config.custom.networking;
|
||||
|
||||
virtualHosts = cfg.virtualHosts |> lib.attrValues |> lib.filter (value: value.enable);
|
||||
virtualHosts = cfg.virtualHosts |> lib.attrValues |> lib.filter (vHost: vHost.enable);
|
||||
|
||||
publicHostsExist = virtualHosts |> lib.any (value: (!self.lib.isPrivateDomain value.domain));
|
||||
privateHostsExist = virtualHosts |> lib.any (value: self.lib.isPrivateDomain value.domain);
|
||||
publicHostsExist = virtualHosts |> lib.any (vHost: (!self.lib.isPrivateDomain vHost.domain));
|
||||
privateHostsExist = virtualHosts |> lib.any (vHost: self.lib.isPrivateDomain vHost.domain);
|
||||
|
||||
webPorts = [
|
||||
80
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ in
|
|||
let
|
||||
nodeRecords =
|
||||
netCfg.nodes
|
||||
|> lib.map (node: "\"${node.hostname}.${node.overlay.domain}. A ${node.overlay.address}\"");
|
||||
|> lib.map (node: "\"${node.hostName}.${node.overlay.domain}. A ${node.overlay.address}\"");
|
||||
serviceRecords =
|
||||
self.nixosConfigurations
|
||||
|> lib.attrValues
|
||||
|
|
|
|||
|
|
@ -16,18 +16,18 @@ in
|
|||
|
||||
publicKeyPath = lib.mkOption {
|
||||
type = lib.types.path;
|
||||
default = "${self}/hosts/${netCfg.hostname}/keys/nebula.pub";
|
||||
default = "${self}/hosts/${netCfg.hostName}/keys/nebula.pub";
|
||||
};
|
||||
certificatePath = lib.mkOption {
|
||||
type = lib.types.path;
|
||||
default = "${self}/hosts/${netCfg.hostname}/keys/nebula.crt";
|
||||
default = "${self}/hosts/${netCfg.hostName}/keys/nebula.crt";
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
assertions = lib.singleton {
|
||||
assertion = netCfg.isLighthouse -> netCfg.underlay.isPublic;
|
||||
message = "'${netCfg.hostname}' is a Nebula lighthouse, but underlay.isPublic is not set. Lighthouses must be publicly reachable.";
|
||||
message = "'${netCfg.hostName}' is a Nebula lighthouse, but underlay.isPublic is not set. Lighthouses must be publicly reachable.";
|
||||
};
|
||||
|
||||
custom.networking.overlay = {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{ config, lib, ... }:
|
||||
let
|
||||
backups = config.custom.services.restic.backups |> lib.filterAttrs (_: value: value.enable);
|
||||
backups = config.custom.services.restic.backups |> lib.filterAttrs (_: backup: backup.enable);
|
||||
in
|
||||
{
|
||||
options.custom.services.restic.backups = lib.mkOption {
|
||||
|
|
@ -48,10 +48,10 @@ in
|
|||
services.restic.backups =
|
||||
backups
|
||||
|> lib.mapAttrs (
|
||||
name: value:
|
||||
name: backup:
|
||||
lib.mkMerge [
|
||||
{
|
||||
inherit (value) paths;
|
||||
inherit (backup) paths;
|
||||
initialize = true;
|
||||
repository = "s3:https://s3.eu-central-003.backblazeb2.com/stork-atlas/${name}";
|
||||
environmentFile = config.sops.templates."restic/environment".path;
|
||||
|
|
@ -66,20 +66,20 @@ in
|
|||
RandomizedDelaySec = "1h";
|
||||
};
|
||||
}
|
||||
value.extraConfig
|
||||
backup.extraConfig
|
||||
]
|
||||
);
|
||||
|
||||
systemd.services =
|
||||
backups
|
||||
|> lib.mapAttrs' (
|
||||
name: value:
|
||||
name: backup:
|
||||
lib.nameValuePair "restic-backups-${name}" (
|
||||
lib.mkIf (value.conflictingService != null) {
|
||||
unitConfig.Conflicts = [ value.conflictingService ];
|
||||
after = [ value.conflictingService ];
|
||||
onSuccess = [ value.conflictingService ];
|
||||
onFailure = [ value.conflictingService ];
|
||||
lib.mkIf (backup.conflictingService != null) {
|
||||
unitConfig.Conflicts = [ backup.conflictingService ];
|
||||
after = [ backup.conflictingService ];
|
||||
onSuccess = [ backup.conflictingService ];
|
||||
onFailure = [ backup.conflictingService ];
|
||||
}
|
||||
)
|
||||
);
|
||||
|
|
|
|||
|
|
@ -7,8 +7,7 @@
|
|||
let
|
||||
backupsWithHealthchecks =
|
||||
config.custom.services.restic.backups
|
||||
|> lib.filterAttrs (_: value: value.enable)
|
||||
|> lib.filterAttrs (_: value: value.doHealthchecks);
|
||||
|> lib.filterAttrs (_: backup: backup.enable && backup.doHealthchecks);
|
||||
in
|
||||
{
|
||||
options.custom.services.restic.backups = lib.mkOption {
|
||||
|
|
|
|||
|
|
@ -7,8 +7,7 @@
|
|||
let
|
||||
backupsWithRestoreCommand =
|
||||
config.custom.services.restic.backups
|
||||
|> lib.filterAttrs (_: value: value.enable)
|
||||
|> lib.filterAttrs (_: value: value.restoreCommand.enable);
|
||||
|> lib.filterAttrs (_: backup: backup.enable && backup.restoreCommand.enable);
|
||||
in
|
||||
{
|
||||
options.custom.services.restic.backups = lib.mkOption {
|
||||
|
|
@ -35,13 +34,13 @@ in
|
|||
environment.systemPackages =
|
||||
backupsWithRestoreCommand
|
||||
|> lib.mapAttrsToList (
|
||||
name: value:
|
||||
name: backup:
|
||||
pkgs.writeShellApplication {
|
||||
name = "restic-restore-${name}";
|
||||
text =
|
||||
let
|
||||
inherit (value) conflictingService;
|
||||
inherit (value.restoreCommand) preRestore postRestore;
|
||||
inherit (backup) conflictingService;
|
||||
inherit (backup.restoreCommand) preRestore postRestore;
|
||||
hasConflictingService = conflictingService != null;
|
||||
in
|
||||
''
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ in
|
|||
|> lib.map (client: {
|
||||
port = 22;
|
||||
proto = "tcp";
|
||||
host = client.hostname;
|
||||
host = client.hostName;
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -48,7 +48,7 @@ in
|
|||
users.users.seb.openssh.authorizedKeys.keyFiles =
|
||||
self.nixosConfigurations
|
||||
|> lib.attrValues
|
||||
|> lib.filter (host: host.config.custom.networking.hostname != netCfg.hostname)
|
||||
|> lib.filter (host: host.config.custom.networking.hostName != netCfg.hostName)
|
||||
|> lib.filter (host: host.config |> lib.hasAttr "home-manager")
|
||||
|> lib.map (host: host.config.home-manager.users.seb.custom.programs.ssh)
|
||||
|> lib.filter (ssh: ssh.enable)
|
||||
|
|
|
|||
|
|
@ -96,16 +96,15 @@ in
|
|||
key = lib.mkIf useSopsSecrets config.sops.secrets."syncthing/key".path;
|
||||
|
||||
settings = {
|
||||
# Get the devices and their ids from the configs of the other hosts
|
||||
devices =
|
||||
self.nixosConfigurations
|
||||
|> lib.filterAttrs (name: _: name != config.networking.hostName)
|
||||
|> lib.filterAttrs (_: value: value.config.custom.services.syncthing.enable)
|
||||
|> lib.filterAttrs (_: host: host.config.networking.hostName != config.networking.hostName)
|
||||
|> lib.filterAttrs (_: host: host.config.custom.services.syncthing.enable)
|
||||
|> lib.mapAttrs (
|
||||
_: value: {
|
||||
id = value.config.custom.services.syncthing.deviceId;
|
||||
_: host: {
|
||||
id = host.config.custom.services.syncthing.deviceId;
|
||||
addresses = [
|
||||
"tcp://${value.config.custom.networking.overlay.address}:${toString cfg.syncPort}"
|
||||
"tcp://${host.config.custom.networking.overlay.address}:${toString host.config.custom.services.syncthing.syncPort}"
|
||||
];
|
||||
}
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue