dotfiles
My PC Dotfiles & Websitegit clone https://github.com/maydayv7/dotfiles
modules/system/base.nix (4461B)
1## Base Configuration ##
2{
3 config,
4 inputs,
5 ...
6}: let
7 inherit (config.flake) files modules;
8in {
9 flake.modules = {
10 nixos.base-cli = {
11 lib,
12 pkgs,
13 ...
14 }: {
15 system.stateVersion = lib.mkDefault lib.trivial.release;
16
17 imports = [
18 inputs.impermanence.nixosModule
19 (lib.mkAliasOptionModule ["environment" "persist"] ["environment" "persistence" files.path.persist])
20 ];
21 environment.persist.enable = lib.mkDefault false;
22
23 environment.systemPackages = with pkgs; [
24 custom.os
25 curl
26 file
27 killall
28 man-pages
29 mkpasswd
30 net-tools
31 rsync
32 unrar
33 unzip
34 wget
35 ];
36 };
37
38 nixos.base = {
39 config,
40 options,
41 pkgs,
42 lib,
43 ...
44 }: let
45 cfg = config.system;
46 in {
47 imports = [modules.nixos.base-cli];
48
49 options.system = {
50 kernel = lib.mkOption {
51 description = "Linux Kernel Variant to be used";
52 default = "lts";
53 type = lib.types.enum (
54 ["lts"]
55 ++ (map (name: lib.removePrefix "linux_" name)
56 (builtins.attrNames pkgs.linuxKernel.kernels))
57 );
58 };
59
60 kernelModules = lib.mkOption {
61 description = "Linux Kernel Modules to load";
62 type = with lib.types; listOf str;
63 default = [];
64 };
65 };
66
67 config = {
68 # Kernel Configuration
69 boot = {
70 kernelPackages =
71 if (cfg.kernel == "lts")
72 then options.boot.kernelPackages.default
73 else pkgs.linuxKernel.packages."${"linux_" + cfg.kernel}";
74
75 initrd.availableKernelModules = lib.optionals (cfg.kernelModules != []) (
76 cfg.kernelModules
77 ++ [
78 "ahci"
79 "sd_mod"
80 "usbhid"
81 "usb_storage"
82 "xhci_pci"
83 ]
84 );
85 };
86
87 environment = {
88 etc."specialisation" =
89 lib.mkIf (lib.hasPrefix "special." cfg.nixos.label)
90 {text = lib.removePrefix "special." cfg.nixos.label;};
91
92 # Essential Utilities
93 systemPackages = with pkgs; [
94 cryptsetup
95 inxi
96 ntfsprogs
97 parted
98 pciutils
99 sdparm
100 smartmontools
101 usbutils
102 alsa-utils
103 ];
104 };
105
106 # Console
107 console = {
108 earlySetup = true;
109 packages = [pkgs.terminus_font];
110 font = "${pkgs.terminus_font}/share/consolefonts/ter-132n.psf.gz";
111 };
112
113 # Drivers
114 security.rtkit.enable = true;
115 hardware = {
116 graphics.enable = true;
117 enableRedistributableFirmware = true;
118 };
119
120 services.pulseaudio.enable = lib.mkForce false;
121 services.pipewire = {
122 enable = true;
123 alsa.enable = true;
124 alsa.support32Bit = true;
125 pulse.enable = true;
126 };
127
128 # Wireless
129 networking = {
130 networkmanager.enable = true;
131 firewall.enable = true;
132 };
133 systemd.network.wait-online.enable = false;
134
135 hardware.bluetooth = {
136 enable = true;
137 powerOnBoot = true;
138 settings.General.Experimental = true;
139 };
140
141 # Memory
142 systemd.oomd.enable = false;
143 services.earlyoom = {
144 enable = true;
145 enableNotifications = true;
146 freeMemThreshold = 5;
147 freeSwapThreshold = 15;
148 };
149
150 environment.persist.directories = [
151 "/etc/NetworkManager"
152 "/var/lib/alsa"
153 "/var/lib/bluetooth"
154 ];
155
156 # Recovery Account
157 specialisation.recovery.configuration = {
158 home-manager.verbose = true;
159 security.sudo.extraConfig = lib.mkAfter "recovery ALL=(ALL:ALL) NOPASSWD:ALL";
160 users.extraUsers.recovery = {
161 name = "recovery";
162 description = "Recovery Account";
163 isNormalUser = true;
164 uid = 1100;
165 group = "users";
166 extraGroups = ["wheel"];
167 useDefaultShell = true;
168 initialHashedPassword = lib.mkDefault (lib.fileContents ../../secrets/passwords/default);
169 };
170 };
171 };
172 };
173
174 homeManager.base = {lib, ...}: {
175 home.stateVersion = lib.mkDefault lib.trivial.release;
176 };
177 };
178}