summary refs log tree commit diff
path: root/fleet/configuration.nix
blob: 527189549901f1df4d351f6d69ecd4439ba7b40b (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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# SPDX-FileCopyrightText: V <v@unfathomable.blue>
# SPDX-FileCopyrightText: edef <edef@unfathomable.blue>
# SPDX-License-Identifier: OSL-3.0

{ lib, pkgs, modulesPath, ... }:

with lib;

let
  host = fileContents /etc/hostname;
  # commit = commitIdFromGitRepo ./.git;
in {
  imports = [
    "${modulesPath}/profiles/qemu-guest.nix"
    (./hosts + "/${host}")
  ] ++ mapAttrsToList (module: _: ./modules + "/${module}") (builtins.readDir ./modules);

  nix.nixPath = [
    "nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos"
    "nixos-config=/etc/nixos/fleet/configuration.nix"
    "/nix/var/nix/profiles/per-user/root/channels"
  ];

  nixpkgs.overlays = [ (import ./pkgs/overlay.nix) ];

  system.stateVersion = "20.09";


  ### Startup

  boot.loader.grub.device = "/dev/sda";

  boot.initrd = {
    availableKernelModules = [ "ata_piix" "virtio_pci" "xhci_pci" "sd_mod" "sr_mod" ];

    luks.devices.rpool = {
      device = "/dev/sda3";
      allowDiscards = true;
    };

    network.enable = true;

    network.ssh = {
      enable = true;
      port = 798;  # Random unassigned port in the range [1, 1024]
      hostKeys = [ "/etc/initrd/ssh_host_ed25519_key" ];
    };
  };


  ### Filesystems

  # Come on, why isn't this the default?
  boot.tmpOnTmpfs = true;

  # Required by ZFS, but redundant on a single-pathed system.
  networking.hostId = "00000000";

  fileSystems = {
    "/boot" = {
      device = "/dev/sda2";
      fsType = "ext2";
    };

    "/" = {
      device = "rpool/root";
      fsType = "zfs";

      # Extracted from the strace output of `zfs mount -a`
      # NOTE: the pool is configured with `zfs set setuid=off rpool`
      # TODO(V): come up with a less ugly solution
      options = [ "defaults" "atime" "strictatime" "dev" "exec" "rw" "nosuid" "nomand" "zfsutil" ];
    };
  };


  ### Networking

  networking.useNetworkd = true;

  networking.hostName = host;
  networking.domain = "unfathomable.blue";

  # Misnomer, actually enables DHCP for all unmanaged interfaces.
  # It's also incompatible with systemd-networkd.
  networking.useDHCP = false;

  networking.interfaces.ens3.useDHCP = true;

  # This is exceedingly spammy, and not so useful for an Internet-facing machine.
  networking.firewall.logRefusedConnections = false;


  ### Security + privacy

  security.sudo.enable = false;


  ### System services

  system.autoUpgrade.enable = true;

  services.openssh = {
    enable = true;
    passwordAuthentication = false;
    kbdInteractiveAuthentication = false;
    # TODO(V): Route exclusively over WireGuard, if you dare
  };


  ### Programs + user services

  programs.fish.enable = true;
  programs.mosh.enable = true;
  programs.mtr.enable = true;


  ### Environment

  time.timeZone = "UTC";

  i18n = {
    defaultLocale = "en_US.UTF-8";
    supportedLocales = [ "en_US.UTF-8/UTF-8" ];
    extraLocaleSettings.LC_COLLATE = "C";
  };

  # TODO(V): Switch to https://github.com/NixOS/nixpkgs/pull/101127 once it's been merged and made its way into stable.
  users.defaultUserShell = pkgs.fish;
  environment.variables.EDITOR = "kak";

  environment.systemPackages = with pkgs; [
    kakoune
    tree
    htop
    ldns
  ];


  ### Users

  users.mutableUsers = false;

  # This is here so we can `git push` directly to /etc/nixos.
  # It should be removed if we stop using that workflow.
  users.users.root.packages = [ pkgs.git ];
}