aboutsummaryrefslogtreecommitdiff
path: root/tharos.nix
blob: 6d967541ecbf5b2a26afbe2dd460584b4942e323 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
{
  self,
  inputs,
  lib,
  ...
}:
{
  flake.machines.tharos = {
    bootstrap-target = "root@${self.machines.tharos.deploy-target}";
    # Administratoren verbinden sich mit ihrem selbst festgelegten Nutzernamen
    deploy-target = "81.169.239.254";
    nixos =
      {
        config,
        pkgs,
        modulesPath,
        ...
      }:

      {
        imports = [
          inputs.disko.nixosModules.default
          "${modulesPath}/profiles/qemu-guest.nix"
        ];

        nixpkgs.hostPlatform = "x86_64-linux";
        system.stateVersion = "25.05";

        services.cloud-init = {
          enable = true;
          network.enable = true;
        };
        # `cloud-init` übernimmt Netzwerkeinstellungen
        networking.useDHCP = false;

        # Kein Login für Nutzer die nicht explizit deklariert sind
        users.mutableUsers = false;
        users.users = lib.mapAttrs (username: keyFiles: {
          isNormalUser = true;
          openssh.authorizedKeys.keyFiles = keyFiles;
          # ANMERKUNG: Der Einfachheit halber sind bis auf Weiteres alle Nutzer mit SSH-Zugang auch Administratoren
          extraGroups = [ "wheel" ];
        }) self.keys;

        /*
          `sudo` über SSH ohne Passworteingabe
          ANMERKUNG: Nutzer sollten in ihrem ` ~/.ssh/config` für die Maschine einstellen:

          ForwardAgent: yes
        */
        security.pam.sshAgentAuth.enable = true;
        security.pam.services.sudo.sshAgentAuth = true;

        # Nur Administratoren können den angemeldeten Benutzer wechseln
        security.pam.services.su.requireWheel = true;

        networking.firewall.allowPing = true;
        services.openssh = {
          enable = true;
          settings = {
            PasswordAuthentication = false;
            PermitRootLogin = "prohibit-password";
          };
        };

        nix = {
          settings.trusted-users = [
            "root"
            "@wheel"
          ];
          settings.experimental-features = [
            "nix-command"
            "flakes"
          ];
        };

        disko.devices.disk.main = {
          device = "/dev/vda";
          type = "disk";
          content = {
            type = "gpt";
            partitions = {
              # Die KVM läuft auf SeaBIOS, daher muss es hier eine MBR-Partition sein
              boot = {
                size = "1M";
                type = "EF02";
              };
              root = {
                size = "100%";
                content = {
                  type = "filesystem";
                  format = "ext4";
                  mountpoint = "/";
                };
              };
            };
          };
        };

        /*
          ANMERKUNG: Erhalten durch:

          nix run .#machines.infect-tharos -- --no-reboot --generate-hardware-config nixos-hardware-config <datei>
        */
        boot.initrd.availableKernelModules = [
          "ata_piix"
          "uhci_hcd"
          "virtio_pci"
          "virtio_blk"
        ];
        boot.kernelModules = [ "kvm-amd" ];
      };

    vm =
      {
        config,
        lib,
        pkgs,
        ...
      }:
      {
        virtualisation = {
          memorySize = 4096;
          diskSize = 4096;
          cores = 2;
          graphics = false;
        };

        services.cloud-init.enable = lib.mkForce false;
        networking.useDHCP = lib.mkForce true;
      };
  };
}