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;
|
|
|
|
}
|
|
|
|
"dagali"
|
2022-03-07 16:01:52 +01:00
|
|
|
"demiurgen"
|
|
|
|
"eirin"
|
2023-12-11 13:34:14 +01:00
|
|
|
"bekkalokk"
|
|
|
|
"ildkule"
|
|
|
|
"shark"
|
|
|
|
"buskerud"
|
|
|
|
"bicep"
|
2024-07-09 11:01:39 +02:00
|
|
|
"bob"
|
2023-12-11 13:34:14 +01:00
|
|
|
"knutsen"
|
2022-03-07 16:01:52 +01:00
|
|
|
"isvegg"
|
|
|
|
[ "microbel" "pvv-users" "pvv-mail" ]
|
|
|
|
];
|
|
|
|
|
|
|
|
rootMachines = [
|
|
|
|
[ "knakelibrak" "pvv-databases" ]
|
|
|
|
[ "spikkjeposche" "pvv-web" "pvv-wiki" "pvv-webmail" ]
|
|
|
|
"sleipner"
|
2023-12-11 13:34:14 +01:00
|
|
|
# "fenris"
|
2022-03-07 16:01:52 +01:00
|
|
|
"balduzius"
|
|
|
|
"joshua"
|
2023-12-11 13:34:14 +01:00
|
|
|
# "skrotnisse"
|
2022-03-07 16:01:52 +01:00
|
|
|
"principal"
|
|
|
|
"tom"
|
2023-12-11 13:34:14 +01:00
|
|
|
# "monty"
|
|
|
|
# {
|
|
|
|
# names = [ "dvask" ];
|
|
|
|
# proxyJump = "monty";
|
|
|
|
# }
|
2022-03-07 16:01:52 +01:00
|
|
|
|
|
|
|
[ "innovation" "pvv-minecraft" ]
|
|
|
|
];
|
|
|
|
|
|
|
|
# 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";
|
|
|
|
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
|
|
|
}
|