分割文件

This commit is contained in:
2023-06-05 21:53:13 +08:00
parent bf3bab5587
commit 64dd9c5798
13 changed files with 196 additions and 145 deletions

165
basic.nix
View File

@@ -1,119 +1,73 @@
{ config, pkgs, lib, ... } @inputs:
{
# 基本设置
nix.settings.experimental-features = [ "nix-command" "flakes" ];
networking.hostName = "chn-PC";
networking.networkmanager.enable = true;
time.timeZone = "Asia/Shanghai";
i18n =
{
defaultLocale = "zh_CN.UTF-8";
supportedLocales = ["zh_CN.UTF-8/UTF-8" "en_US.UTF-8/UTF-8" "C.UTF-8/UTF-8"];
};
system.stateVersion = "22.11";
# 输入法
i18n.inputMethod =
{
enabled = "fcitx5";
fcitx5.addons = with pkgs; [fcitx5-rime fcitx5-chinese-addons fcitx5-mozc];
};
# 图形界面
services.xserver =
{
enable = true;
displayManager.sddm.enable = true;
desktopManager.plasma5.enable = true;
videoDrivers = [ "nvidia" "intel" "qxl" ];
};
hardware.nvidia.prime =
{
offload.enable = true;
intelBusId = "PCI:0:2:0";
nvidiaBusId = "PCI:1:0:0";
};
# 打印机
services.printing.enable = true;
# 声音
sound.enable = true;
hardware.pulseaudio.enable = false;
security.rtkit.enable = true;
services.pipewire =
{
enable = true;
alsa.enable = true;
alsa.support32Bit = true;
pulse.enable = true;
};
# 虚拟机(作为顾客)
services.qemuGuest.enable = true;
services.spice-vdagentd.enable = true;
# waydroid
virtualisation.waydroid.enable = true;
virtualisation.lxd.enable = true;
virtualisation =
{
waydroid.enable = true;
lxd.enable = true;
};
# 用户
users.users.chn =
users =
{
isNormalUser = true;
extraGroups = [ "networkmanager" "wheel" "wireshark" "libvirtd" ];
passwordFile = config.sops.secrets."password/chn".path;
shell = pkgs.zsh;
};
users.mutableUsers = false;
sops.secrets."password/chn".neededForUsers = true;
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.chn = { pkgs, ... }:
{
home.stateVersion = "22.11";
programs.zsh =
users.chn =
{
enable = true;
initExtraBeforeCompInit =
''
# p10k instant prompt
P10K_INSTANT_PROMPT="$XDG_CACHE_HOME/p10k-instant-prompt-''${(%):-%n}.zsh"
[[ ! -r "$P10K_INSTANT_PROMPT" ]] || source "$P10K_INSTANT_PROMPT"
HYPHEN_INSENSITIVE="true"
'';
plugins =
[
{
file = "powerlevel10k.zsh-theme";
name = "powerlevel10k";
src = "${pkgs.zsh-powerlevel10k}/share/zsh-powerlevel10k";
}
{
file = "p10k.zsh";
name = "powerlevel10k-config";
src = ./p10k-config;
}
{
name = "zsh-exa";
src = pkgs.fetchFromGitHub
{
owner = "ptavares";
repo = "zsh-exa";
rev = "0.2.3";
sha256 = "0vn3iv9d3c1a4rigq2xm52x8zjaxlza1pd90bw9mbbkl9iq8766r";
};
}
];
isNormalUser = true;
extraGroups = [ "networkmanager" "wheel" "wireshark" "libvirtd" ];
passwordFile = config.sops.secrets."password/chn".path;
shell = pkgs.zsh;
};
# xsession.profileExtra =
# ''
# export GTK_USE_PORTAL="1"
# '';
mutableUsers = false;
};
sops.secrets."password/chn".neededForUsers = true;
home-manager =
{
useGlobalPkgs = true;
useUserPackages = true;
users.chn = { pkgs, ... }:
{
home.stateVersion = "22.11";
programs.zsh =
{
enable = true;
initExtraBeforeCompInit =
''
# p10k instant prompt
P10K_INSTANT_PROMPT="$XDG_CACHE_HOME/p10k-instant-prompt-''${(%):-%n}.zsh"
[[ ! -r "$P10K_INSTANT_PROMPT" ]] || source "$P10K_INSTANT_PROMPT"
HYPHEN_INSENSITIVE="true"
'';
plugins =
[
{
file = "powerlevel10k.zsh-theme";
name = "powerlevel10k";
src = "${pkgs.zsh-powerlevel10k}/share/zsh-powerlevel10k";
}
{
file = "p10k.zsh";
name = "powerlevel10k-config";
src = ./p10k-config;
}
{
name = "zsh-exa";
src = pkgs.fetchFromGitHub
{
owner = "ptavares";
repo = "zsh-exa";
rev = "0.2.3";
sha256 = "0vn3iv9d3c1a4rigq2xm52x8zjaxlza1pd90bw9mbbkl9iq8766r";
};
}
];
};
};
};
# 软件包
@@ -204,7 +158,7 @@
[ noto-fonts source-han-sans source-han-serif source-code-pro hack-font jetbrains-mono nerdfonts ];
fontconfig.defaultFonts =
{
emoji = [ "Noto Color Emoji" ];
emoji = [ "Noto Color Emoji" ];
monospace = [ "Noto Sans Mono CJK SC" "Sarasa Mono SC" "DejaVu Sans Mono"];
sansSerif = ["Noto Sans CJK SC" "Source Han Sans SC" "DejaVu Sans"];
serif = ["Noto Serif CJK SC" "Source Han Serif SC" "DejaVu Serif"];
@@ -235,7 +189,8 @@
# sops
sops = { defaultSopsFile = ./secrets/chn-PC.yaml; age.sshKeyPaths = [ "/etc/ssh/ssh_host_ed25519_key" ]; };
# 翻墙
# 网络和翻墙
networking.networkmanager.enable = true;
services.dnsmasq =
{
enable = true;

View File

@@ -63,6 +63,7 @@
nixosConfigurations."chn-PC" = inputs.nixpkgs.lib.nixosSystem
{
system = "x86_64-linux";
specialArgs = inputs;
modules = [
({ config.nixpkgs.overlays =
[(final: prev:
@@ -71,7 +72,6 @@
nix-vscode-extensions = inputs.nix-vscode-extensions.extensions."${prev.system}";
} )]; })
./basic.nix
./hardware/chn-PC.nix
inputs.home-manager.nixosModules.home-manager
inputs.sops-nix.nixosModules.sops
inputs.touchix.nixosModules.v2ray-forwarder

View File

@@ -1,44 +1,5 @@
{ config, lib, pkgs, modulesPath, ... }:
{
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
nixpkgs.config.allowUnfree = true;
hardware = {
enableAllFirmware = true;
cpu.intel.updateMicrocode = true;
};
fileSystems = {
"/" = {
device = "/dev/mapper/root";
fsType = "btrfs";
options = [ "subvol=@root,compress-force=zstd:15" ];
};
"/boot" = {
device = "/dev/disk/by-uuid/50DE-B72A";
fsType = "vfat";
};
};
boot = {
loader = {
timeout = 5;
systemd-boot.enable = true;
efi.canTouchEfiVariables = true;
};
initrd = {
luks.devices.root = {
device = "/dev/disk/by-partuuid/49fe75e3-bd94-4c75-9b21-2c77a1f74c4e";
header = "/dev/disk/by-partuuid/c341ca23-bb14-4927-9b31-a9dcc959d0f5";
allowDiscards = true;
};
systemd.enable = true;
availableKernelModules = [ "ahci" "nvme" "sr_mod" "usb_storage" "virtio_blk" "virtio_pci" "xhci_pci" ];
};
kernelPackages = pkgs.linuxPackages_xanmod_latest;
kernelModules = [ "kvm-intel" ];
extraModulePackages = with config.boot.kernelPackages; [ cpupower xone xpadneo ];
extraModprobeConfig = "options kvm_intel nested=1";
};
}

12
modules/basic/basic.nix Normal file
View File

@@ -0,0 +1,12 @@
{ hostname }:
{
config =
{
nixpkgs.hostPlatform = "x86_64-linux";
nix.settings.experimental-features = [ "nix-command" "flakes" ];
networking.hostName = hostname;
time.timeZone = "Asia/Shanghai";
system.stateVersion = "22.11";
nixpkgs.config.allowUnfree = true;
};
}

18
modules/boot/basic.nix Normal file
View File

@@ -0,0 +1,18 @@
{ efi }: inputs:
{
config =
{
boot =
{
loader =
{
timeout = 5;
systemd-boot.enable = true;
efi.canTouchEfiVariables = efi;
};
initrd.systemd.enable = true;
kernelPackages = inputs.pkgs.linuxPackages_xanmod_latest;
};
hardware.enableAllFirmware = true;
};
}

15
modules/boot/chn-PC.nix Normal file
View File

@@ -0,0 +1,15 @@
inputs:
{
config =
{
boot =
{
initrd.availableKernelModules
= [ "ahci" "nvme" "sr_mod" "usb_storage" "virtio_blk" "virtio_pci" "xhci_pci" ];
kernelModules = [ "kvm-intel" ];
extraModulePackages = with inputs.config.boot.kernelPackages; [ cpupower xone xpadneo ];
extraModprobeConfig = "options kvm_intel nested=1";
};
hardware.cpu.intel.updateMicrocode = true;
};
}

View File

@@ -0,0 +1,8 @@
{
config.services.xserver =
{
enable = true;
displayManager.sddm.enable = true;
desktopManager.plasma5.enable = true;
};
}

View File

@@ -0,0 +1,12 @@
{
config =
{
services.xserver.videoDrivers = [ "nvidia" "intel" "qxl" ];
hardware.nvidia.prime =
{
offload.enable = true;
intelBusId = "PCI:0:2:0";
nvidiaBusId = "PCI:1:0:0";
};
}
}

View File

@@ -0,0 +1,25 @@
{
config =
{
fileSystems =
{
"/" =
{
device = "/dev/mapper/root";
fsType = "btrfs";
options = [ "subvol=@root,compress-force=zstd:15" ];
};
"/boot" =
{
device = "/dev/disk/by-uuid/50DE-B72A";
fsType = "vfat";
};
};
boot.initrd.luks.devices.root =
{
device = "/dev/disk/by-partuuid/49fe75e3-bd94-4c75-9b21-2c77a1f74c4e";
header = "/dev/disk/by-partuuid/c341ca23-bb14-4927-9b31-a9dcc959d0f5";
allowDiscards = true;
};
};
}

20
modules/i18n/basic.nix Normal file
View File

@@ -0,0 +1,20 @@
{ fcitx }: input:
{
config.i18n =
{
defaultLocale = "zh_CN.UTF-8";
supportedLocales = ["zh_CN.UTF-8/UTF-8" "en_US.UTF-8/UTF-8" "C.UTF-8/UTF-8"];
}
//
(
if fcitx then
{
inputMethod =
{
enabled = "fcitx5";
fcitx5.addons = with pkgs; [fcitx5-rime fcitx5-chinese-addons fcitx5-mozc];
};
}
else {}
);
}

View File

@@ -0,0 +1,3 @@
{
config.services.printing.enable = true;
}

15
modules/sound/basic.nix Normal file
View File

@@ -0,0 +1,15 @@
{
config =
{
sound.enable = true;
hardware.pulseaudio.enable = false;
security.rtkit.enable = true;
services.pipewire =
{
enable = true;
alsa.enable = true;
alsa.support32Bit = true;
pulse.enable = true;
};
};
}

7
modules/vm/guest.nix Normal file
View File

@@ -0,0 +1,7 @@
{
config.services =
{
qemuGuest.enable = true;
spice-vdagentd.enable = true;
};
}