From 9e549fb7335211b5854bf7db0396b2e9e7a349a4 Mon Sep 17 00:00:00 2001 From: Ryan Yin Date: Thu, 4 May 2023 23:40:50 +0800 Subject: [PATCH] feat: add new host - msi-rtx4090 --- flake.nix | 33 +++++++++--- home/i3/default.nix | 7 +++ hosts/default.nix | 10 ---- hosts/msi-rtx4090/default.nix | 55 ++++++++++++++++++++ hosts/msi-rtx4090/hardware-configuration.nix | 41 +++++++++++++++ hosts/nixos-test/default.nix | 6 ++- modules/i3.nix | 4 +- 7 files changed, 137 insertions(+), 19 deletions(-) delete mode 100644 hosts/default.nix create mode 100644 hosts/msi-rtx4090/default.nix create mode 100644 hosts/msi-rtx4090/hardware-configuration.nix diff --git a/flake.nix b/flake.nix index d4f68fb1..b8d03291 100644 --- a/flake.nix +++ b/flake.nix @@ -25,7 +25,7 @@ }; # 这是 flake.nix 的标准格式,inputs 是 flake 的依赖,outputs 是 flake 的输出 - # inputs 中的每一项都被拉取、构建后,被作为参数传递给 outputs 函数 + # inputs 中的每一项都被拉取、构建后,被作为参数传递给 outputs 函数 inputs = { # flake inputs 有很多种引用方式,应用最广泛的是 github 的引用方式 @@ -42,12 +42,12 @@ # outputs 的参数都是 inputs 中定义的依赖项,可以通过它们的名称来引用。 # 不过 self 是个例外,这个特殊参数指向 outputs 自身(自引用),以及 flake 根目录 # 这里的 @ 语法将函数的参数 attribute set 取了个别名,方便在内部使用 - outputs = inputs@{ + outputs = inputs@{ self, nixpkgs, home-manager, nix-vscode-extensions, - ... + ... }: { # 名为 nixosConfigurations 的 outputs 会在执行 `nixos-rebuild switch --flake .` 时被使用 # 默认情况下会使用与主机 hostname 同名的 nixosConfigurations,但是也可以通过 `--flake .#` 来指定 @@ -62,7 +62,7 @@ # NixOS Module 可以是一个 attribute set,也可以是一个返回 attribute set 的函数 # 如果是函数,那么它的参数就是当前的 NixOS Module 的参数. # 根据 Nix Wiki 对 NixOS modules 的描述,NixOS modules 函数的参数可以有这四个(详见本仓库中的 modules 文件): - # + # # config: The configuration of the entire system # options: All option declarations refined with all definition and declaration references. # pkgs: The attribute set extracted from the Nix package collection and enhanced with the nixpkgs.config option. @@ -71,7 +71,7 @@ # nix flake 的 modules 系统可将配置模块化,提升配置的可维护性 # 默认只能传上面这四个参数,如果需要传其他参数,必须使用 specialArgs modules = [ - ./hosts + ./hosts/nixos-test # home-manager 作为 nixos 的一个 module # 这样在 nixos-rebuild switch 时,home-manager 也会被自动部署,不需要额外执行 home-manager switch 命令 @@ -87,8 +87,29 @@ ]; }; + msi-rtx4090 = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + + modules = [ + ./hosts/msi-rtx4090 + + # home-manager 作为 nixos 的一个 module + # 这样在 nixos-rebuild switch 时,home-manager 也会被自动部署,不需要额外执行 home-manager switch 命令 + home-manager.nixosModules.home-manager + { + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + + # 使用 home-manager.extraSpecialArgs 自定义传递给 ./home 的参数 + home-manager.extraSpecialArgs = inputs; + home-manager.users.ryan = import ./home; + } + ]; + }; + + # 如果你在 x86_64-linux 平台上执行 nix build,那么默认会使用这个配置,或者也能通过 `.#` 参数来指定非 default 的配置 - # packages.x86_64-linux.default = + # packages.x86_64-linux.default = }; }; } diff --git a/home/i3/default.nix b/home/i3/default.nix index ad944613..4352a271 100644 --- a/home/i3/default.nix +++ b/home/i3/default.nix @@ -18,6 +18,13 @@ executable = true; # make all scripts executable }; + + # set cursor size and dpi for 4k monitor + xresources.properties = { + "Xcursor.size" = 16; + "Xft.dpi" = 192; + }; + # 直接以 text 的方式,在 nix 配置文件中硬编码文件内容 # home.file.".xxx".text = '' # xxx diff --git a/hosts/default.nix b/hosts/default.nix deleted file mode 100644 index 286f91ba..00000000 --- a/hosts/default.nix +++ /dev/null @@ -1,10 +0,0 @@ -{ - ... -}: { - imports = - [ - ./nixos-test - ../modules/system.nix - ../modules/i3.nix - ]; -} \ No newline at end of file diff --git a/hosts/msi-rtx4090/default.nix b/hosts/msi-rtx4090/default.nix new file mode 100644 index 00000000..7e53d7f3 --- /dev/null +++ b/hosts/msi-rtx4090/default.nix @@ -0,0 +1,55 @@ +# Edit this configuration file to define what should be installed on +# your system. Help is available in the configuration.nix(5) man page +# and in the NixOS manual (accessible by running ‘nixos-help’). + +{ config, pkgs, ... }: + +{ + imports = + [ + ../../modules/system.nix + ../../modules/i3.nix + + # Include the results of the hardware scan. + ./hardware-configuration.nix + ]; + + # Bootloader. + boot.loader = { + efi = { + canTouchEfiVariables = true; + efiSysMountPoint = "/boot/efi"; # ← use the same mount point here. + }; + systemd-boot.enable = true; + }; + + networking.hostName = "msi-rtx4090"; # Define your hostname. + # networking.wireless.enable = true; # Enables wireless support via wpa_supplicant. + + # Configure network proxy if necessary + # networking.proxy.default = "http://user:password@proxy:port/"; + # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain"; + + # Enable networking + networking.networkmanager.enable = true; + networking.defaultGateway = "192.168.5.201"; + + # for Nvidia GPU + services.xserver.videoDrivers = ["nvidia"]; + hardware.opengl.enable = true; + hardware.nvidia = { + package = config.boot.kernelPackages.nvidiaPackages.stable; + modesetting.enable = true; + }; + + # This value determines the NixOS release from which the default + # settings for stateful data, like file locations and database versions + # on your system were taken. It‘s perfectly fine and recommended to leave + # this value at the release version of the first install of this system. + # Before changing this value read the documentation for this option + # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html). + system.stateVersion = "22.11"; # Did you read the comment? + +} + + diff --git a/hosts/msi-rtx4090/hardware-configuration.nix b/hosts/msi-rtx4090/hardware-configuration.nix new file mode 100644 index 00000000..5bbe9771 --- /dev/null +++ b/hosts/msi-rtx4090/hardware-configuration.nix @@ -0,0 +1,41 @@ +# Do not modify this file! It was generated by ‘nixos-generate-config’ +# and may be overwritten by future invocations. Please make changes +# to /etc/nixos/configuration.nix instead. +{ config, lib, pkgs, modulesPath, ... }: + +{ + imports = + [ (modulesPath + "/installer/scan/not-detected.nix") + ]; + + boot.initrd.availableKernelModules = [ "xhci_pci" "ahci" "nvme" "usbhid" "uas" "usb_storage" "sd_mod" ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ "kvm-intel" ]; + boot.extraModulePackages = [ ]; + + fileSystems."/" = + { device = "/dev/disk/by-uuid/9730ef67-577c-4dc9-8563-f431c1cf25fb"; + fsType = "ext4"; + }; + + fileSystems."/boot/efi" = + { device = "/dev/disk/by-uuid/8DA9-86FF"; + fsType = "vfat"; + }; + + swapDevices = + [ { device = "/dev/disk/by-uuid/5364261a-3ecc-4754-b114-ff44c529627e"; } + ]; + + # Enables DHCP on each ethernet and wireless interface. In case of scripted networking + # (the default) this is the recommended approach. When using systemd-networkd it's + # still possible to use this option, but it's recommended to use it in conjunction + # with explicit per-interface declarations with `networking.interfaces..useDHCP`. + networking.useDHCP = lib.mkDefault true; + # networking.interfaces.enp5s0.useDHCP = lib.mkDefault true; + # networking.interfaces.wlo1.useDHCP = lib.mkDefault true; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; + powerManagement.cpuFreqGovernor = lib.mkDefault "powersave"; + hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; +} diff --git a/hosts/nixos-test/default.nix b/hosts/nixos-test/default.nix index 2b0c32b0..06168321 100644 --- a/hosts/nixos-test/default.nix +++ b/hosts/nixos-test/default.nix @@ -6,7 +6,11 @@ { imports = - [ # Include the results of the hardware scan. + [ + ../../modules/system.nix + ../../modules/i3.nix + + # Include the results of the hardware scan. ./hardware-configuration.nix ]; diff --git a/modules/i3.nix b/modules/i3.nix index 17da1d1c..20a6df3d 100644 --- a/modules/i3.nix +++ b/modules/i3.nix @@ -4,14 +4,14 @@ { # i3 related options - environment.pathsToLink = [ "/libexec" ]; # links /libexec from derivations to /run/current-system/sw + environment.pathsToLink = [ "/libexec" ]; # links /libexec from derivations to /run/current-system/sw services.xserver = { enable = true; desktopManager = { xterm.enable = false; }; - + displayManager = { defaultSession = "none+i3"; lightdm.enable = false;