nixos-config

My NixOS configuration files

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
  64. 64
  65. 65
  66. 66
  67. 67
  68. 68
  69. 69
  70. 70
  71. 71
  72. 72
  73. 73
  74. 74
  75. 75
  76. 76
  77. 77
  78. 78
  79. 79
  80. 80
  81. 81
  82. 82
  83. 83
  84. 84
  85. 85
  86. 86
  87. 87
  88. 88
  89. 89
  90. 90
  91. 91
  92. 92
  93. 93
  94. 94
  95. 95
  96. 96
  97. 97
  98. 98
  99. 99
  100. 100
  101. 101
  102. 102
  103. 103
  104. 104
  105. 105
  106. 106
  107. 107
  108. 108
  109. 109
  110. 110
  111. 111
  112. 112
  113. 113
  114. 114
  115. 115
  116. 116
  117. 117
  118. 118
  119. 119
  120. 120
  121. 121
  122. 122
  123. 123
  124. 124
  125. 125
  126. 126
  127. 127
  128. 128
  129. 129
  130. 130
  131. 131
  132. 132
{
  config,
  lib,
  pkgs,
  ...
}:

{
  # TODO: Make nix run work more reliably on Hyades
  nixpkgs.hostPlatform = "x86_64-linux";

  networking = {
    # Even though some hex string ends up in /etc/hostname, this is still used for Nix store paths
    hostName = "Unnamed-Server";
    # No need for a firewall when inside a network namespace on Hyades
    firewall.enable = false;
    # Disable dhcpcd which makes networking really slow
    dhcpcd.enable = false;
    # Hardcode the MIT nameservers
    nameservers = [
      "18.0.70.160"
      "18.0.72.3"
      "18.0.71.151"
    ];
  };

  # The best time zone
  time.timeZone = "UTC";

  users.users.a = {
    openssh.authorizedKeys.keys = [
      "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPDLPakDnAelqFTUudQB8X0T7yc/8ekV3jGqpeJb062l anthonywang"
    ];
    # krun virtiofs doesn't support ACLs so manually give myself permission to see the journal
    extraGroups = [ "systemd-journal" ];
  };

  programs.tmux.enable = true;

  # Include journal in Podman output
  services.journald.console = "/dev/console";

  services.openssh = {
    enable = true;
    ports = [ 2222 ];
    settings = {
      # https://forgejo.org/docs/latest/admin/recommendations/#git-over-ssh
      # https://docs.gitlab.com/administration/git_protocol/
      # Test using GIT_TRACE_PACKET=1 git ls-remote
      AcceptEnv = [ "GIT_PROTOCOL" ];
      # Don't hack me
      PasswordAuthentication = false;
      PermitRootLogin = "no";
    };
    # Put host keys in a volume instead
    generateHostKeys = false;
    extraConfig = ''
      HostKey /etc/ssh/keys/ssh_host_rsa_key
      HostKey /etc/ssh/keys/ssh_host_ed25519_key
    '';
  };

  # My websites
  services.caddy = {
    enable = true;
    # TLS is handled by Hyades
    globalConfig = ''
      auto_https off
    '';
    virtualHosts = {
      "http://unnamed.website".extraConfig = ''
        root * /srv/http/www
        file_server
        handle_errors {
          rewrite * /{err.status_code}.html
          file_server
        }
      '';
      "http://git.unnamed.website".extraConfig = ''
        reverse_proxy localhost:5555
      '';
      "http://*.unnamed.website".extraConfig = ''
        root * /srv/http/{labels.2}
        # Enable the file browser by default, can disable by creating an empty index.html
        file_server browse
      '';
      "http://a.exozy.me http://ta180m.exozy.me".extraConfig = ''
        redir https://unnamed.website{uri} permanent
      '';
    };
  };

  # Git server
  # It's possible to nuke Python by using fishMinimal and gitMinimal but eh it doesn't save that much space and is a hassle
  services.legit = {
    enable = true;
    config = {
      meta = {
        title = "Typeclass instance problem is stuck";
        description = "It is often due to incompetence";
        syntaxHighlight = true;
      };
      repo = {
        diff = "system";
        mainBranch = [
          "main"
          "master"
        ];
        readme = [ "README.md" ];
        scanPath = "/srv/git";
        trimDotGitSuffix = true;
      };
      server.name = "git.unnamed.website";
      ui.footer.poweredBy = true;
    };
  };
  systemd = {
    # Update Git mirrors
    services.update-mirrors = {
      path = [ pkgs.git ];
      serviceConfig = {
        User = "a";
        Group = "users";
        ExecStart = pkgs.writers.writeFish "update-mirrors" ./update-mirrors.fish;
      };
    };
    timers.update-mirrors = {
      wantedBy = [ "multi-user.target" ];
      timerConfig.OnCalendar = "weekly";
    };
  };
}