mirror of
https://github.com/gensokyo-zone/infrastructure.git
synced 2026-02-09 12:29:19 -08:00
feat(exports): sshd service
This commit is contained in:
parent
1fed0eb15f
commit
45d41414e6
14 changed files with 78 additions and 0 deletions
41
modules/system/exports/sshd.nix
Normal file
41
modules/system/exports/sshd.nix
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
{lib, gensokyo-zone, ...}: let
|
||||
inherit (gensokyo-zone.lib) mapAlmostOptionDefaults mkAlmostOptionDefault;
|
||||
inherit (lib.modules) mkIf;
|
||||
inherit (lib.attrsets) mapAttrs filterAttrs mapAttrsToList;
|
||||
inherit (lib.lists) sort;
|
||||
in {
|
||||
config.exports.services.sshd = { config, ... }: let
|
||||
mkAssertion = f: nixosConfig: let
|
||||
cfg = nixosConfig.services.openssh;
|
||||
in f nixosConfig cfg;
|
||||
sorted = sort (a: b: a > b);
|
||||
assertPorts = nixosConfig: cfg: let
|
||||
nixosPorts = cfg.ports;
|
||||
enabledPorts = filterAttrs (_: port: port.enable) config.ports;
|
||||
servicePorts = mapAttrsToList (_: port: port.port) enabledPorts;
|
||||
in {
|
||||
assertion = sorted nixosPorts == sorted servicePorts;
|
||||
message = "port mismatch: ${toString nixosPorts} != ${toString servicePorts}";
|
||||
};
|
||||
in {
|
||||
id = mkAlmostOptionDefault "ssh";
|
||||
nixos = {
|
||||
serviceAttr = "openssh";
|
||||
assertions = mkIf config.enable [
|
||||
(mkAssertion assertPorts)
|
||||
];
|
||||
};
|
||||
defaults.port.listen = mkAlmostOptionDefault "wan";
|
||||
ports = mapAttrs (_: mapAlmostOptionDefaults) {
|
||||
public = {
|
||||
port = 62954;
|
||||
transport = "tcp";
|
||||
};
|
||||
standard = {
|
||||
port = 22;
|
||||
transport = "tcp";
|
||||
listen = "lan";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue