aboutsummaryrefslogtreecommitdiff
path: root/profiles/common.nix
blob: 0aa496e74d602928dd8204f55373d999d521c03d (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
{
  pkgs,
  lib,
  inputs,
  config,
  ...
}:
let
  inherit (lib) mkDefault;
in
{
  system.stateVersion = "24.05";

  environment.systemPackages = with pkgs; [
    vim
    curl
    dnsutils
    gitMinimal
  ];

  nixpkgs.config.allowUnfree = true;
  nix = {
    nixPath = [ ];

    gc = {
      automatic = true;
      options = "--delete-older-than 7d";
    };

    registry = {
      nixpkgs.to = {
        owner = "nixos";
        repo = "nixpkgs";
        type = "github";
        rev = inputs.nixpkgs.rev;
      };
    };

    settings = {
      # Improve nix store disk usage
      auto-optimise-store = true;

      # Prevents impurities in builds
      sandbox = true;

      experimental-features = [
        "nix-command"
        "flakes"
        "ca-derivations"
      ];
      flake-registry = "";

      connect-timeout = 20;
      log-lines = mkDefault 25;

      max-free = mkDefault (3000 * 1024 * 1024);
      min-free = mkDefault (512 * 1024 * 1024);
    };
  };

  # Quieter logs
  networking.firewall.logRefusedConnections = false;

  # Unnecessary / nonsensical
  systemd.services.NetworkManager-wait-online.enable = false;
  systemd.network.wait-online.enable = false;

  # Hardening
  users = {
    mutableUsers = false;
    users.root.hashedPassword = "$y$j9T$5aHaSd9AkFijcpHRJk07q1$hxRPTrwvo3hZqFcOvNIam.iJ7jDR2ZAeZsTmQYphKpA";
  };
  boot.tmp.cleanOnBoot = true;
  systemd.enableEmergencyMode = false;

  # Perl is a default package
  environment.defaultPackages = [ ];

  # Things that pull in perl
  programs.less.lessopen = mkDefault null;
  boot.enableContainers = mkDefault false;

  # Unnecessary programs/services
  networking.firewall.enable = false;
  system.disableInstallerTools = true;
  documentation = {
    enable = false;
    nixos.enable = false;
    man.enable = false;
  };
  environment.variables.BROWSER = "echo";
  programs.vim.defaultEditor = true;
  programs.command-not-found.enable = mkDefault false;
  environment.stub-ld.enable = mkDefault false;
  services.logrotate.enable = mkDefault false;

  xdg.autostart.enable = mkDefault false;
  xdg.icons.enable = mkDefault false;
  xdg.mime.enable = mkDefault false;
  xdg.sounds.enable = mkDefault false;
  services.udisks2.enable = mkDefault false;

  # use TCP BBR has significantly increased throughput and reduced latency for connections
  boot.kernel.sysctl = {
    "net.core.default_qdisc" = "fq";
    "net.ipv4.tcp_congestion_control" = "bbr";
  };

  # Show package version changes on switch
  system.activationScripts.diff = {
    supportsDryActivation = true;
    text = ''
      if [[ -e /run/current-system ]]; then
        echo "--- diff to current-system"
        ${pkgs.nvd}/bin/nvd --nix-bin-dir=${config.nix.package}/bin diff /run/current-system "$systemConfig"
        echo "---"
      fi
    '';
  };

  # SSH
  services.openssh = {
    enable = true;
    settings = {
      X11Forwarding = false;
      KbdInteractiveAuthentication = false;
      PasswordAuthentication = true;
      UseDns = false;
      PermitRootLogin = "yes";
      KexAlgorithms = [
        "curve25519-sha256"
        "curve25519-sha256@libssh.org"
        "diffie-hellman-group16-sha512"
        "diffie-hellman-group18-sha512"
        "sntrup761x25519-sha512@openssh.com"
      ];
    };
  };
}