2024-04-05 16:09:51 +02:00
|
|
|
{ nix-config, pkgs, lib, config, ... }:
|
2024-04-03 14:05:28 +02:00
|
|
|
|
|
|
|
let
|
2024-06-20 19:18:39 +02:00
|
|
|
inherit (lib) mkOption mkEnableOption mkIf singleton optionals;
|
2024-04-06 14:11:58 +02:00
|
|
|
inherit (lib.types) nullOr str listOf;
|
2024-06-19 08:00:34 +02:00
|
|
|
inherit (cfg) username iHaveLotsOfRam hashedPassword mullvad allowSRB2Port allowDevPort noRoot postgres phone;
|
2024-04-05 16:09:51 +02:00
|
|
|
inherit (builtins) attrValues;
|
2024-04-03 15:43:02 +02:00
|
|
|
|
2024-04-04 15:41:32 +02:00
|
|
|
cfg = config.modules.system;
|
2024-04-03 14:05:28 +02:00
|
|
|
in
|
2023-06-22 17:54:12 +02:00
|
|
|
{
|
2024-04-05 16:09:51 +02:00
|
|
|
imports = attrValues {
|
|
|
|
inherit (nix-config.inputs.home-manager.nixosModules) home-manager;
|
|
|
|
};
|
|
|
|
|
2024-04-04 15:41:32 +02:00
|
|
|
options.modules.system = {
|
2024-04-04 22:36:08 +02:00
|
|
|
username = mkOption {
|
|
|
|
type = str;
|
|
|
|
default = "user";
|
|
|
|
};
|
|
|
|
|
2024-04-06 14:11:58 +02:00
|
|
|
hashedPassword = mkOption {
|
|
|
|
type = nullOr str;
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
|
2024-04-04 15:41:32 +02:00
|
|
|
timeZone = mkOption {
|
|
|
|
type = str;
|
|
|
|
default = "America/New_York";
|
|
|
|
};
|
2024-04-04 03:28:50 +02:00
|
|
|
|
2024-04-04 15:41:32 +02:00
|
|
|
defaultLocale = mkOption {
|
|
|
|
type = str;
|
|
|
|
default = "ja_JP.UTF-8";
|
2024-04-03 13:30:40 +02:00
|
|
|
};
|
|
|
|
|
2024-04-04 15:41:32 +02:00
|
|
|
supportedLocales = mkOption {
|
|
|
|
type = listOf str;
|
|
|
|
default = [ "ja_JP.UTF-8/UTF-8" "en_US.UTF-8/UTF-8" "fr_FR.UTF-8/UTF-8" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
stateVersion = mkOption {
|
|
|
|
type = str;
|
|
|
|
default = "22.11";
|
|
|
|
};
|
2024-04-05 16:59:48 +02:00
|
|
|
|
|
|
|
iHaveLotsOfRam = mkEnableOption "tmpfs on /tmp";
|
2024-06-19 08:00:34 +02:00
|
|
|
phone = mkEnableOption "Phone support";
|
2024-04-06 14:37:09 +02:00
|
|
|
|
|
|
|
hostName = mkOption {
|
|
|
|
type = str;
|
|
|
|
default = "nixos";
|
|
|
|
};
|
|
|
|
|
2024-04-07 01:28:20 +02:00
|
|
|
noRoot = mkEnableOption "disable access to root";
|
|
|
|
|
2024-04-06 14:37:09 +02:00
|
|
|
mullvad = mkEnableOption "mullvad vpn";
|
2024-04-09 15:25:30 +02:00
|
|
|
postgres = mkEnableOption "postgres database for containers";
|
2024-04-06 14:37:09 +02:00
|
|
|
|
|
|
|
allowSRB2Port = mkEnableOption "port for srb2";
|
2024-05-20 17:53:12 +02:00
|
|
|
allowDevPort = mkEnableOption "port for development server";
|
2024-04-03 14:05:28 +02:00
|
|
|
};
|
|
|
|
|
2024-04-04 15:41:32 +02:00
|
|
|
config = {
|
2024-06-19 08:00:34 +02:00
|
|
|
boot = mkIf (!phone) {
|
2024-04-05 17:26:22 +02:00
|
|
|
tmp =
|
|
|
|
if iHaveLotsOfRam
|
2024-04-05 16:59:48 +02:00
|
|
|
then { useTmpfs = true; }
|
|
|
|
else { cleanOnBoot = true; };
|
2024-04-03 14:05:28 +02:00
|
|
|
|
2024-06-16 13:43:51 +02:00
|
|
|
binfmt.emulatedSystems = [ "aarch64-linux" ];
|
|
|
|
|
2024-04-04 15:41:32 +02:00
|
|
|
loader = {
|
|
|
|
systemd-boot = {
|
|
|
|
enable = true;
|
|
|
|
editor = false;
|
|
|
|
configurationLimit = 10;
|
|
|
|
};
|
|
|
|
|
|
|
|
timeout = 0;
|
|
|
|
efi.canTouchEfiVariables = true;
|
|
|
|
};
|
2024-04-11 04:56:48 +02:00
|
|
|
|
|
|
|
blacklistedKernelModules = [
|
|
|
|
"floppy"
|
|
|
|
];
|
2024-04-03 14:05:28 +02:00
|
|
|
};
|
|
|
|
|
2024-06-19 08:00:34 +02:00
|
|
|
systemd = mkIf (!phone) {
|
2024-04-04 15:41:32 +02:00
|
|
|
extraConfig = "DefaultTimeoutStopSec=10s";
|
|
|
|
services.NetworkManager-wait-online.enable = false;
|
|
|
|
};
|
2024-04-03 15:16:18 +02:00
|
|
|
|
2024-04-04 15:41:32 +02:00
|
|
|
nix = {
|
|
|
|
settings = {
|
|
|
|
experimental-features = [ "nix-command" "flakes" "repl-flake" ];
|
|
|
|
auto-optimise-store = true;
|
|
|
|
warn-dirty = false;
|
2024-06-21 04:32:42 +02:00
|
|
|
allow-import-from-derivation = false;
|
2024-06-17 17:24:51 +02:00
|
|
|
|
|
|
|
trusted-users = [
|
|
|
|
"root"
|
|
|
|
"@wheel"
|
|
|
|
];
|
2024-04-04 15:41:32 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-06-19 08:01:48 +02:00
|
|
|
zramSwap = mkIf (!phone) {
|
2024-04-04 15:41:32 +02:00
|
|
|
enable = true;
|
|
|
|
memoryPercent = 100;
|
|
|
|
};
|
2024-04-03 13:14:47 +02:00
|
|
|
|
2024-04-04 15:41:32 +02:00
|
|
|
time = {
|
|
|
|
inherit (cfg) timeZone;
|
|
|
|
};
|
|
|
|
|
|
|
|
i18n = {
|
|
|
|
inherit (cfg) defaultLocale supportedLocales;
|
|
|
|
};
|
|
|
|
|
|
|
|
system = {
|
|
|
|
inherit (cfg) stateVersion;
|
|
|
|
};
|
2024-04-04 22:00:09 +02:00
|
|
|
|
|
|
|
users = {
|
|
|
|
mutableUsers = false;
|
2024-04-07 01:28:20 +02:00
|
|
|
allowNoPasswordLogin = mkIf noRoot true;
|
2024-04-04 22:00:09 +02:00
|
|
|
|
2024-04-04 22:36:08 +02:00
|
|
|
users.${username} = {
|
2024-04-06 14:11:58 +02:00
|
|
|
inherit hashedPassword;
|
|
|
|
|
2024-04-04 22:36:08 +02:00
|
|
|
isNormalUser = true;
|
|
|
|
uid = 1000;
|
2024-04-07 01:28:20 +02:00
|
|
|
password = mkIf (hashedPassword == null && !noRoot) username;
|
2024-06-19 08:04:46 +02:00
|
|
|
extraGroups =
|
|
|
|
if noRoot
|
|
|
|
then [ ]
|
|
|
|
else [
|
2024-06-20 19:18:39 +02:00
|
|
|
"wheel"
|
|
|
|
"networkmanager"
|
|
|
|
] ++ (optionals (phone) [
|
2024-06-19 08:04:46 +02:00
|
|
|
"dialout"
|
|
|
|
"feedbackd"
|
|
|
|
"video"
|
2024-06-20 19:18:39 +02:00
|
|
|
]);
|
2024-04-04 22:00:09 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-06-20 18:15:59 +02:00
|
|
|
documentation.man.generateCaches = mkIf (phone) false;
|
|
|
|
|
2024-04-04 22:00:09 +02:00
|
|
|
home-manager = {
|
|
|
|
useGlobalPkgs = true;
|
|
|
|
useUserPackages = true;
|
|
|
|
|
2024-04-08 10:11:19 +02:00
|
|
|
sharedModules = singleton {
|
2024-04-08 10:15:46 +02:00
|
|
|
home = {
|
|
|
|
inherit (cfg) stateVersion;
|
|
|
|
};
|
|
|
|
|
2024-06-20 18:15:59 +02:00
|
|
|
programs.man.generateCaches = mkIf (!phone) true;
|
2024-04-08 10:11:19 +02:00
|
|
|
};
|
2024-04-04 22:00:09 +02:00
|
|
|
|
2024-04-04 22:36:08 +02:00
|
|
|
users.${username}.home = {
|
|
|
|
inherit username;
|
|
|
|
|
|
|
|
homeDirectory = "/home/${username}";
|
2024-04-04 22:00:09 +02:00
|
|
|
};
|
|
|
|
};
|
2024-04-06 01:38:56 +02:00
|
|
|
|
|
|
|
virtualisation.vmVariant = {
|
|
|
|
virtualisation = {
|
|
|
|
memorySize = 4096;
|
|
|
|
cores = 4;
|
|
|
|
|
2024-04-06 14:21:27 +02:00
|
|
|
sharedDirectories = {
|
|
|
|
tmp = {
|
|
|
|
source = "/tmp";
|
|
|
|
target = "/mnt";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-04-06 01:38:56 +02:00
|
|
|
qemu.options = [
|
|
|
|
"-device virtio-vga-gl"
|
|
|
|
"-display sdl,gl=on,show-cursor=off"
|
|
|
|
"-audio pa,model=hda"
|
2024-04-06 12:44:31 +02:00
|
|
|
"-full-screen"
|
2024-04-06 01:38:56 +02:00
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.sessionVariables = {
|
|
|
|
WLR_NO_HARDWARE_CURSORS = "1";
|
|
|
|
};
|
|
|
|
|
|
|
|
services.interception-tools.enable = lib.mkForce false;
|
|
|
|
networking.resolvconf.enable = lib.mkForce true;
|
2024-04-06 04:23:20 +02:00
|
|
|
zramSwap.enable = lib.mkForce false;
|
2024-04-06 01:38:56 +02:00
|
|
|
|
|
|
|
boot.enableContainers = false;
|
|
|
|
};
|
2024-04-06 14:37:09 +02:00
|
|
|
|
|
|
|
networking = {
|
|
|
|
inherit (cfg) hostName;
|
|
|
|
|
|
|
|
networkmanager = {
|
|
|
|
enable = true;
|
|
|
|
wifi.macAddress = "random";
|
|
|
|
ethernet.macAddress = "random";
|
|
|
|
|
|
|
|
unmanaged = [ "interface-name:ve-*" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
useHostResolvConf = true;
|
|
|
|
|
|
|
|
resolvconf.enable = mkIf mullvad false;
|
|
|
|
|
|
|
|
nat = mkIf mullvad {
|
|
|
|
enable = true;
|
|
|
|
internalInterfaces = [ "ve-+" ];
|
|
|
|
externalInterface = "wg-mullvad";
|
|
|
|
};
|
|
|
|
|
|
|
|
firewall = {
|
|
|
|
allowedUDPPorts = mkIf allowSRB2Port [
|
|
|
|
5029
|
|
|
|
];
|
|
|
|
|
2024-05-20 17:53:12 +02:00
|
|
|
allowedTCPPorts = mkIf allowDevPort [
|
|
|
|
3000
|
2024-04-06 14:37:09 +02:00
|
|
|
];
|
2024-06-22 01:12:01 +02:00
|
|
|
|
|
|
|
checkReversePath = mkIf phone (lib.mkForce false);
|
2024-04-06 14:37:09 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-04-09 15:25:30 +02:00
|
|
|
services = {
|
|
|
|
resolved.llmnr = "false";
|
2024-04-06 14:37:09 +02:00
|
|
|
|
2024-04-09 15:25:30 +02:00
|
|
|
mullvad-vpn = mkIf mullvad {
|
|
|
|
enable = true;
|
|
|
|
enableExcludeWrapper = false;
|
2024-06-22 01:12:01 +02:00
|
|
|
package = pkgs.mullvad-vpn;
|
2024-04-09 15:25:30 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
postgresql = mkIf postgres {
|
|
|
|
enable = true;
|
|
|
|
|
|
|
|
ensureUsers = singleton {
|
|
|
|
name = username;
|
|
|
|
};
|
|
|
|
|
|
|
|
ensureDatabases = [ username ];
|
|
|
|
};
|
2024-04-06 14:37:09 +02:00
|
|
|
};
|
2024-04-06 16:26:02 +02:00
|
|
|
|
2024-04-06 17:35:34 +02:00
|
|
|
environment.systemPackages = with pkgs; [
|
|
|
|
(pass.withExtensions (ext: with ext; [ pass-otp ]))
|
|
|
|
];
|
|
|
|
|
2024-04-06 18:13:01 +02:00
|
|
|
programs.command-not-found.enable = false;
|
|
|
|
|
2024-04-06 17:35:34 +02:00
|
|
|
environment.defaultPackages = [ ];
|
2024-04-03 15:43:02 +02:00
|
|
|
};
|
2023-06-22 17:54:12 +02:00
|
|
|
}
|