2023-12-18 14:52:34 +01:00
|
|
|
{ pkgs, lib, extendedLib, ... }:
|
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 = [
|
2024-07-09 11:01:39 +02:00
|
|
|
{
|
|
|
|
names = [ "hildring" "pvv-login" "pvv" ];
|
|
|
|
proxyJump = lib.mkDefault null;
|
2024-08-13 10:19:48 +02:00
|
|
|
addressFamily = "inet";
|
2024-07-09 11:01:39 +02:00
|
|
|
}
|
2024-09-04 10:29:31 +02:00
|
|
|
[ "bekkalokk" "pvv-web" "pvv-wiki" "pvv-webmail" ]
|
|
|
|
[ "bicep" "pvv-databases" ]
|
|
|
|
"bob"
|
|
|
|
[ "brzeczyszczykiewicz" "brez" "bokhylle" ]
|
|
|
|
"buskerud"
|
2024-07-09 11:01:39 +02:00
|
|
|
"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"
|
2023-12-11 13:34:14 +01:00
|
|
|
"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" ]
|
2024-08-02 18:35:55 +02:00
|
|
|
[ "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}
|
2022-11-19 16:35:36 +01:00
|
|
|
coerceToSSHMatchBlock =
|
2022-03-07 16:01:52 +01:00
|
|
|
machine:
|
2022-11-19 16:35:36 +01:00
|
|
|
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;
|
|
|
|
|
2022-11-19 16:35:36 +01:00
|
|
|
# ListOf(String) -> AttrSet
|
2022-03-07 16:01:52 +01:00
|
|
|
machineWithNames = let
|
|
|
|
inherit (lib.lists) head;
|
|
|
|
inherit (lib.strings) split;
|
|
|
|
in
|
2023-12-11 13:34:14 +01:00
|
|
|
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
|
2024-07-09 11:01:39 +02:00
|
|
|
convertNormalMachine = convertMachineWithDefaults { user = normalUser; proxyJump = "pvv"; };
|
2022-03-07 16:01:52 +01:00
|
|
|
# AttrSet -> AttrSet
|
|
|
|
convertAdminMachine =
|
2024-07-09 11:01:39 +02:00
|
|
|
convertMachineWithDefaults { user = adminUser; proxyJump = "pvv"; };
|
2022-03-07 16:01:52 +01:00
|
|
|
|
2022-11-19 16:35:36 +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 = [
|
2022-11-19 16:35:36 +01:00
|
|
|
(map coerceToSSHMatchBlock)
|
2022-03-07 16:01:52 +01:00
|
|
|
(map convertMachineFunction)
|
|
|
|
listToAttrs
|
|
|
|
];
|
|
|
|
in
|
|
|
|
machines: pipe machines pipeline;
|
|
|
|
in
|
|
|
|
{
|
2024-07-03 23:10:51 +02:00
|
|
|
programs.ssh.matchBlocks = (extendedLib.attrsets.concatAttrs [
|
2022-03-07 16:01:52 +01:00
|
|
|
(convertMachinesWith convertNormalMachine normalMachines)
|
|
|
|
(convertMachinesWith convertAdminMachine rootMachines)
|
2024-07-03 23:10:51 +02:00
|
|
|
]) // {
|
|
|
|
"pvv-git git.pvv.ntnu.no" = {
|
|
|
|
hostname = "git.pvv.ntnu.no";
|
|
|
|
user = "gitea";
|
2024-08-13 10:19:48 +02:00
|
|
|
addressFamily = "inet";
|
2024-07-03 23:10:51 +02:00
|
|
|
port = 2222;
|
2024-07-09 11:01:39 +02:00
|
|
|
proxyJump = "pvv";
|
2024-07-03 23:10:51 +02:00
|
|
|
};
|
|
|
|
};
|
2022-03-07 16:01:52 +01:00
|
|
|
}
|