nixos/modules/system/default.nix

186 lines
6.0 KiB
Nix
Raw Normal View History

2023-07-22 00:01:56 +08:00
inputs:
{
options.nixos.system = let inherit (inputs.lib) mkOption types; in
{
hostname = mkOption { type = types.nonEmptyStr; };
2023-07-25 20:24:03 +08:00
march = mkOption { type = types.nullOr types.nonEmptyStr; default = null; };
2023-07-23 15:49:00 +08:00
gui.enable = mkOption { type = types.bool; default = false; };
2023-07-31 21:55:15 +08:00
keepOutputs = mkOption { type = types.bool; default = false; };
2023-07-22 00:01:56 +08:00
};
2023-07-22 00:37:12 +08:00
config = let inherit (inputs.lib) mkMerge mkIf; inherit (inputs.localLib) mkConditional stripeTabs; in mkMerge
2023-07-22 00:01:56 +08:00
[
2023-07-23 00:09:54 +08:00
# generic
{
nix =
{
settings =
{
system-features = [ "big-parallel" "nixos-test" "benchmark" ];
experimental-features = [ "nix-command" "flakes" ];
2023-07-31 21:55:15 +08:00
keep-outputs = inputs.config.nixos.system.keepOutputs;
2023-07-23 00:09:54 +08:00
keep-failed = true;
auto-optimise-store = true;
};
daemonIOSchedClass = "idle";
daemonCPUSchedPolicy = "idle";
registry =
{
nixpkgs.flake = inputs.topInputs.nixpkgs;
nixos-config.flake = inputs.topInputs.self;
};
};
services =
{
udev.extraRules = stripeTabs
''
ACTION=="add|change", KERNEL=="[sv]d[a-z]", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="bfq"
ACTION=="add|change", KERNEL=="nvme[0-9]n[0-9]", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="bfq"
'';
dbus.implementation = "broker";
};
networking.networkmanager.enable = true;
programs = { dconf.enable = true; nix-ld.enable = true; };
2023-07-26 23:36:12 +08:00
nixpkgs =
{
config.allowUnfree = true;
overlays = [(final: prev: { genericPackages = (inputs.topInputs.nixpkgs.lib.nixosSystem
{
system = "x86_64-linux";
modules = [{ config.nixpkgs.config.allowUnfree = true; }];
}).pkgs;})];
};
2023-07-23 00:09:54 +08:00
time.timeZone = "Asia/Shanghai";
system =
{
stateVersion = "22.11";
configurationRevision = inputs.topInputs.self.rev or "dirty";
};
boot =
{
kernel.sysctl =
{
"net.core.rmem_max" = 67108864;
"net.core.wmem_max" = 67108864;
"net.ipv4.tcp_rmem" = "4096 87380 67108864";
"net.ipv4.tcp_wmem" = "4096 65536 67108864";
"net.ipv4.tcp_mtu_probing" = true;
"net.ipv4.tcp_tw_reuse" = true;
"vm.swappiness" = 10;
"net.ipv4.tcp_max_syn_backlog" = 8388608;
"net.core.netdev_max_backlog" = 8388608;
"net.core.somaxconn" = 8388608;
"vm.oom_kill_allocating_task" = true;
"vm.oom_dump_tasks" = false;
"vm.overcommit_memory" = 1;
"dev.i915.perf_stream_paranoid" = false;
2023-07-27 19:01:58 +08:00
"net.ipv4.conf.all.route_localnet" = true;
"net.ipv4.conf.default.route_localnet" = true;
"net.ipv4.conf.all.accept_local" = true;
"net.ipv4.conf.default.accept_local" = true;
"net.ipv4.ip_forward" = true;
"net.ipv4.ip_nonlocal_bind" = true;
"net.bridge.bridge-nf-call-iptables" = false;
"net.bridge.bridge-nf-call-ip6tables" = false;
"net.bridge.bridge-nf-call-arptables" = false;
2023-07-23 00:09:54 +08:00
};
supportedFilesystems = [ "ntfs" ];
consoleLogLevel = 7;
};
hardware.enableAllFirmware = true;
systemd =
{
extraConfig = stripeTabs
"
DefaultTimeoutStopSec=10s
DefaultLimitNOFILE=1048576:1048576
";
user.extraConfig = "DefaultTimeoutStopSec=10s";
services =
{
nix-daemon =
{
serviceConfig = { CacheDirectory = "nix"; Slice = "-.slice"; Nice = "19"; };
environment = { TMPDIR = "/var/cache/nix"; };
};
systemd-tmpfiles-setup = { environment = { SYSTEMD_TMPFILES_FORCE_SUBVOL = "0"; }; };
};
timers.systemd-tmpfiles-clean.enable = false;
};
2023-07-26 17:08:32 +08:00
environment =
2023-07-23 21:00:09 +08:00
{
2023-07-26 17:08:32 +08:00
etc."channels/nixpkgs".source = inputs.topInputs.nixpkgs.outPath;
etc."nixos".source = inputs.topInputs.self.outPath;
sessionVariables =
{
XDG_CACHE_HOME = "$HOME/.cache";
XDG_CONFIG_HOME = "$HOME/.config";
XDG_DATA_HOME = "$HOME/.local/share";
XDG_STATE_HOME = "$HOME/.local/state";
2023-07-28 13:59:07 +08:00
# ANDROID_HOME = "$XDG_DATA_HOME/android";
2023-07-27 23:25:27 +08:00
HISTFILE= "$XDG_STATE_HOME/bash/history";
CUDA_CACHE_PATH = "$XDG_CACHE_HOME/nv";
DOCKER_CONFIG = "$XDG_CONFIG_HOME/docker";
GNUPGHOME = "$XDG_DATA_HOME/gnupg";
GTK2_RC_FILES = "$XDG_CONFIG_HOME/gtk-2.0/gtkrc";
2023-07-28 00:02:51 +08:00
XCOMPOSECACHE = "$XDG_CACHE_HOME/X11/xcompose";
MATHEMATICA_USERBASE = "$XDG_CONFIG_HOME/mathematica";
_JAVA_OPTIONS = "-Djava.util.prefs.userRoot=$XDG_CONFIG_HOME/java";
2023-07-26 17:08:32 +08:00
};
2023-07-23 21:00:09 +08:00
};
2023-07-24 12:52:00 +08:00
i18n =
{
defaultLocale = "zh_CN.UTF-8";
supportedLocales = ["zh_CN.UTF-8/UTF-8" "en_US.UTF-8/UTF-8" "C.UTF-8/UTF-8"];
};
2023-07-26 17:08:32 +08:00
# environment.pathsToLink = [ "/include" ];
# environment.variables.CPATH = "/run/current-system/sw/include";
# environment.variables.LIBRARY_PATH = "/run/current-system/sw/lib";
2023-07-23 00:09:54 +08:00
}
# hostname
{ networking.hostName = inputs.config.nixos.system.hostname; }
# march
(
mkConditional (inputs.config.nixos.system.march != null)
{
nixpkgs =
{
hostPlatform = { system = "x86_64-linux"; gcc =
{ arch = inputs.config.nixos.system.march; tune = inputs.config.nixos.system.march; }; };
2023-07-25 20:24:03 +08:00
config.qchem-config.optArch = inputs.config.nixos.system.march;
2023-07-23 00:09:54 +08:00
};
nix.settings.system-features = [ "gccarch-${inputs.config.nixos.system.march}" ];
boot.kernelPatches =
[{
name = "native kernel";
patch = null;
extraStructuredConfig =
{
GENERIC_CPU = inputs.lib.kernel.no;
"M${inputs.lib.strings.toUpper inputs.config.nixos.system.march}" = inputs.lib.kernel.yes;
};
}];
}
{ nixpkgs.hostPlatform = inputs.lib.mkDefault "x86_64-linux"; }
)
2023-07-23 15:49:00 +08:00
# gui.enable
2023-07-24 12:52:00 +08:00
(mkIf inputs.config.nixos.system.gui.enable
{
2023-07-27 11:05:14 +08:00
services.xserver =
{
enable = true;
displayManager.sddm.enable = true;
desktopManager.plasma5.enable = true;
videoDrivers = inputs.config.nixos.hardware.gpus;
};
systemd.services.display-manager.after = [ "network-online.target" ];
environment.sessionVariables."GTK_USE_PORTAL" = "1";
xdg.portal.extraPortals = with inputs.pkgs; [ xdg-desktop-portal-gtk xdg-desktop-portal-wlr ];
i18n.inputMethod =
{
enabled = "fcitx5";
fcitx5.addons = with inputs.pkgs; [ fcitx5-rime fcitx5-chinese-addons fcitx5-mozc ];
};
2023-07-24 12:52:00 +08:00
})
2023-07-23 00:09:54 +08:00
];
2023-07-22 00:01:56 +08:00
}