NixOS configuration for HPC cluster https://docs.hpc.informatik.hs-fulda.de/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.2 KiB

  1. { lib
  2. , callPackage
  3. , runCommandNoCCLocal
  4. , ssh-to-age
  5. , ...
  6. }:
  7. with lib;
  8. let
  9. adminKeys = [
  10. ''3237CA7A1744B4DCE96B409FB4C3BF012D9B26BE''
  11. ];
  12. machines = callPackage ./machines.nix { };
  13. sshToKey = name: path: runCommandNoCCLocal "sops-key-${name}.pub" { } ''
  14. ${ssh-to-age}/bin/ssh-to-age < ${path} > $out
  15. '';
  16. # Map machine name to its key
  17. machineKeys = listToAttrs (map
  18. (machine:
  19. let
  20. keyFile = sshToKey "machine-${machine.name}" /${machine.gather}/ssh_host_ed25519_key.pub;
  21. in
  22. {
  23. inherit (machine) name;
  24. value = removeSuffix "\n" (readFile keyFile);
  25. })
  26. machines);
  27. pattern = path: "^${escapeRegex path}/(${escapeRegex "secrets.yaml"}|secrets/.+)$";
  28. machine_rules = map
  29. (machine: {
  30. "path_regex" = pattern "/machines/${machine.type}";
  31. "key_groups" = [{
  32. "age" = singleton (getAttr machine.name machineKeys);
  33. "pgp" = adminKeys;
  34. }];
  35. })
  36. machines;
  37. in
  38. {
  39. config = {
  40. "creation_rules" = machine_rules ++ [{
  41. "relPath" = pattern "shared";
  42. "key_groups" = [{
  43. "age" = attrValues machineKeys;
  44. "pgp" = adminKeys;
  45. }];
  46. }];
  47. };
  48. }