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

96 lines
2.4 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 = [
[ "hildring" "pvv-login" "pvv" ]
"demiurgen"
"eirin"
"bekkalokk"
"ildkule"
"shark"
"buskerud"
"bicep"
{
names = [ "bob" ];
proxyJump = "hildring";
}
"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"
# "fenris"
2022-03-07 16:01:52 +01:00
"balduzius"
"joshua"
# "skrotnisse"
2022-03-07 16:01:52 +01:00
"principal"
"tom"
# "monty"
# {
# names = [ "dvask" ];
# proxyJump = "monty";
# }
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; };
# AttrSet -> AttrSet
convertAdminMachine =
convertMachineWithDefaults { user = adminUser; proxyJump = "hildring"; };
# 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 = extendedLib.attrsets.concatAttrs [
2022-03-07 16:01:52 +01:00
(convertMachinesWith convertNormalMachine normalMachines)
(convertMachinesWith convertAdminMachine rootMachines)
];
}