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

95 lines
2.5 KiB
Nix
Raw Normal View History

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 = [
{
names = [ "hildring" "pvv-login" "pvv" ];
proxyJump = lib.mkDefault null;
addressFamily = "inet";
}
"dagali"
"drolsum"
2022-03-07 16:01:52 +01:00
"demiurgen"
"eirin"
[ "bekkalokk" "pvv-web" "pvv-wiki" "pvv-webmail" ]
"ildkule"
"shark"
"buskerud"
[ "bicep" "pvv-databases" ]
"bob"
"knutsen"
2022-03-07 16:01:52 +01:00
"isvegg"
"tom"
2022-03-07 16:01:52 +01:00
[ "microbel" "pvv-users" "pvv-mail" ]
];
rootMachines = [
[ "sleipner" "pvv-salt" ]
[ "balduzius" "pvv-krb" ]
2022-03-07 16:01:52 +01:00
[ "innovation" "pvv-minecraft" ]
];
# 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
{
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";
addressFamily = "inet";
2024-07-03 23:10:51 +02:00
port = 2222;
proxyJump = "pvv";
2024-07-03 23:10:51 +02:00
};
};
2022-03-07 16:01:52 +01:00
}