nix-dotfiles/home/programs/ssh/pvv.nix

105 lines
2.7 KiB
Nix
Raw Normal View History

{ pkgs, lib, ... }:
2022-03-07 16:01:52 +01:00
let
2023-12-18 14:52:34 +01:00
adminUser = "root";
normalUser = "oysteikt";
2022-03-07 16:01:52 +01:00
# http://www.pvv.ntnu.no/pvv/Maskiner
normalMachines = [
{
names = [ "hildring" "pvv-login" "pvv" ];
proxyJump = lib.mkDefault null;
addressFamily = "inet";
}
2024-09-04 10:29:31 +02:00
[ "bekkalokk" "pvv-web" "pvv-wiki" "pvv-webmail" ]
[ "bicep" "pvv-databases" ]
"bob"
[ "brzeczyszczykiewicz" "brez" "bokhylle" ]
"buskerud"
"dagali"
2022-03-07 16:01:52 +01:00
"demiurgen"
2024-09-04 10:29:31 +02:00
"drolsum"
2022-03-07 16:01:52 +01:00
"eirin"
2024-09-04 10:29:31 +02:00
"georg"
"ildkule"
2022-03-07 16:01:52 +01:00
"isvegg"
2024-09-04 10:29:31 +02:00
"knutsen"
2022-03-07 16:01:52 +01:00
[ "microbel" "pvv-users" "pvv-mail" ]
2024-09-04 10:29:31 +02:00
"orchid"
"shark"
"tallulah"
"tom"
"venture"
2022-03-07 16:01:52 +01:00
];
rootMachines = [
2024-09-04 10:29:31 +02:00
[ "ameno" "pvv-dns" ]
[ "balduzius" "pvv-krb" ]
2022-03-07 16:01:52 +01:00
[ "innovation" "pvv-minecraft" ]
2024-09-04 10:29:31 +02:00
"ludvigsen"
[ "principal" "pvv-backup" ]
[ "skrott" "dibbler" ]
[ "sleipner" "pvv-salt" ]
2022-03-07 16:01:52 +01:00
];
# Either( String [String] AttrSet{String} ) -> AttrSet{String}
coerceToSSHMatchBlock =
2022-03-07 16:01:52 +01:00
machine:
if builtins.isString machine then { names = [machine]; }
else if builtins.isList machine then { names = machine; }
2022-03-07 16:01:52 +01:00
else machine;
# ListOf(String) -> AttrSet
2022-03-07 16:01:52 +01:00
machineWithNames = let
inherit (lib.lists) head;
inherit (lib.strings) split;
in
names: { hostname = "${head names}.pvv.ntnu.no"; };
2022-03-07 16:01:52 +01:00
# AttrSet -> AttrSet -> AttrSet
convertMachineWithDefaults = defaults: normalizedMachine: let
inherit (lib.attrsets) nameValuePair;
inherit (lib.strings) concatStringsSep;
inherit (normalizedMachine) names;
name = concatStringsSep " " names;
value =
(machineWithNames names)
// defaults
// removeAttrs normalizedMachine ["names"];
in
nameValuePair name value;
# AttrSet -> AttrSet
convertNormalMachine = convertMachineWithDefaults { user = normalUser; proxyJump = "pvv"; };
2022-03-07 16:01:52 +01:00
# AttrSet -> AttrSet
convertAdminMachine =
convertMachineWithDefaults { user = adminUser; proxyJump = "pvv"; };
2022-03-07 16:01:52 +01:00
# ListOf (Either(String ListOf(String) AttrsOf(String))) -> (AttrSet -> AttrSet) -> AttrSet
2022-03-07 16:01:52 +01:00
convertMachinesWith = convertMachineFunction: let
inherit (lib.attrsets) listToAttrs;
inherit (lib.trivial) pipe;
pipeline = [
(map coerceToSSHMatchBlock)
2022-03-07 16:01:52 +01:00
(map convertMachineFunction)
listToAttrs
];
in
machines: pipe machines pipeline;
in
{
programs.ssh.matchBlocks = lib.mergeAttrsList [
2022-03-07 16:01:52 +01:00
(convertMachinesWith convertNormalMachine normalMachines)
(convertMachinesWith convertAdminMachine rootMachines)
{
"pvv-git git.pvv.ntnu.no" = {
hostname = "git.pvv.ntnu.no";
user = "gitea";
addressFamily = "inet";
port = 2222;
proxyJump = "pvv";
};
}
];
2022-03-07 16:01:52 +01:00
}