aboutsummaryrefslogtreecommitdiff
path: root/nixos/modules/generic.nix
blob: 97391b898665e0967afb148468afd5eca81b8913 (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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
{
  config,
  lib,
  pkgs,
  ...
}: let
  inherit (lib) mkOverride mkDefault optionals;
  isNative = config.nixpkgs.hostPlatform == config.nixpkgs.buildPlatform;
  isArm = config.nixpkgs.hostPlatform.isAarch;
in {
  config = {
    system.stateVersion = "24.05";

    nix = {
      extraOptions = "experimental-features = nix-command flakes repl-flake";
      settings = {
        auto-optimise-store = true;
        substituters = [
          "https://thefloweringash-armv7.cachix.org"
          "https://arm.cachix.org"
        ];
        trusted-public-keys = [
          "thefloweringash-armv7.cachix.org-1:v+5yzBD2odFKeXbmC+OPWVqx4WVoIVO6UXgnSAWFtso="
          "arm.cachix.org-1:K3XjAeWPgWkFtSS9ge5LJSLw3xgnNqyOaG7MDecmTQ8="
        ];
        trusted-users = ["@wheel"];
      };
      registry = {
        personal.to = {
          type = "git";
          url = "https://git.cynerd.cz/nixos-personal";
        };
      };
    };

    boot = {
      loader.systemd-boot.enable = mkOverride 1100 true;
      loader.efi.canTouchEfiVariables = mkDefault true;
      kernelPackages = mkOverride 1100 pkgs.linuxPackages_latest;
      kernelParams = ["boot.shell_on_fail"];
    };
    hardware.enableAllFirmware = true;
    services.fwupd.enable = mkDefault (pkgs.system == "x86_64-linux");
    systemd.oomd.enable = false;

    nixpkgs = {
      config.allowUnfree = true;
      flake = {
        setNixPath = false;
        setFlakeRegistry = false;
      };
    };
    environment.systemPackages = with pkgs;
      [
        git # We need git for this repository to even work
        # Administration tools
        coreutils
        binutils
        psmisc
        progress
        lshw
        file
        vde2
        ldns
        wget
        gnumake
        exfat
        exfatprogs
        ntfs3g
        usbutils
        pciutils
        smartmontools
        parted

        # NCurses tools
        htop
        btop
        iotop
        mc
        screen
        tmux
        pv

        # ls tools
        tree
        lsof
        strace

        sourceHighlight # Colors for less
        unrar
        p7zip
        zip
        unzip

        # Network
        netcat
        traceroute
        iftop
        nethogs
        sshfs
        wakeonlan
        speedtest-cli
        librespeed-cli
        termshark

        lm_sensors
      ]
      ++ optionals (system == "x86_64-linux") [
        nmap
        ltrace
      ]
      ++ optionals (!isNative) [
        ncdu_1
      ]
      ++ optionals isNative [
        moreutils
        glances
        ncdu
        mlocate
      ];

    users = {
      mutableUsers = false;
      groups.cynerd.gid = 1000;
      users = {
        root = {
          hashedPasswordFile = "/run/secrets/root.pass";
        };
        cynerd = {
          group = "cynerd";
          extraGroups = ["users" "wheel" "dialout" "kvm" "uucp" "wireshark"];
          uid = 1000;
          subUidRanges = [
            {
              count = 65534;
              startUid = 10000;
            }
          ];
          subGidRanges = [
            {
              count = 65534;
              startGid = 10000;
            }
          ];
          isNormalUser = true;
          createHome = true;
          shell =
            if isNative
            then pkgs.zsh.out
            else pkgs.bash.out;
          hashedPasswordFile = "/run/secrets/cynerd.pass";
          openssh.authorizedKeys.keyFiles = [
            (config.personal-secrets + "/unencrypted/git-private.pub")
          ];
        };
      };
    };
    programs = {
      zsh = {
        enable = isNative;
        syntaxHighlighting.enable = isNative;
      };
      shellrc = true;
      vim.defaultEditor = isArm;
      neovim = {
        enable = !isArm;
        defaultEditor = true;
        withNodeJs = true;
      };

      wireshark.enable = true;
    };

    security.sudo.extraRules = [
      {
        groups = ["wheel"];
        commands = ["ALL"];
      }
    ];
    networking = {
      nftables.enable = true;
      dhcpcd.extraConfig = "controlgroup wheel";
    };

    services.openssh = {
      enable = true;
      settings = {
        PasswordAuthentication = false;
        PermitRootLogin = "no";
      };
    };

    time.timeZone = "Europe/Prague";
    i18n.defaultLocale = "en_US.UTF-8";

    services.udev.packages = [
      (pkgs.writeTextFile rec {
        name = "bfq-drives.rules";
        destination = "/etc/udev/rules.d/60-${name}";
        text = ''
          ACTION=="add|change", KERNEL=="sd*[!0-9]", ATTR{queue/scheduler}="bfq"
          ACTION=="add|change", KERNEL=="nvme*n[0-9]", ATTR{queue/scheduler}="bfq"
        '';
      })
    ];

    system.extraSystemBuilderCmds = ''
      substituteAll ${./nixos-system.sh} $out/bin/nixos-system
      chmod +x $out/bin/nixos-system
    '';

    programs.fuse.userAllowOther = true;

    documentation = {
      enable = mkDefault false;
      doc.enable = mkDefault false;
      nixos.enable = mkDefault false;
    };
  };
}