From c47ad94679556eff6c546a9d11c9a818718c588a Mon Sep 17 00:00:00 2001 From: Dmitrii Gudov Date: Fri, 19 Dec 2025 07:46:32 +0300 Subject: [PATCH] some refactor in WIP --- flake.lock | 13 -- flake.nix | 78 +++++----- home-manager/modules/zsh/zsh.nix | 1 + hosts/fenrir-nixos/configuration.nix | 142 ++++++++++++++++++ hosts/fenrir-nixos/hardware-configuration.nix | 43 ++++++ {nixos => hosts/loki-nixos}/configuration.nix | 14 +- hosts/loki-nixos/hardware-configuration.nix | 40 +++++ nixos/hardware-stub.nix | 7 - personal.stub.nix | 1 - 9 files changed, 266 insertions(+), 73 deletions(-) create mode 100755 hosts/fenrir-nixos/configuration.nix create mode 100755 hosts/fenrir-nixos/hardware-configuration.nix rename {nixos => hosts/loki-nixos}/configuration.nix (92%) create mode 100644 hosts/loki-nixos/hardware-configuration.nix delete mode 100644 nixos/hardware-stub.nix diff --git a/flake.lock b/flake.lock index 350f296..bb5970b 100644 --- a/flake.lock +++ b/flake.lock @@ -74,18 +74,6 @@ "type": "github" } }, - "hw": { - "flake": false, - "locked": { - "path": "./nixos/hardware-stub.nix", - "type": "path" - }, - "original": { - "path": "./nixos/hardware-stub.nix", - "type": "path" - }, - "parent": [] - }, "naersk": { "inputs": { "nixpkgs": "nixpkgs_2" @@ -164,7 +152,6 @@ "root": { "inputs": { "home-manager": "home-manager", - "hw": "hw", "nixpkgs": "nixpkgs", "personal": "personal", "todo": "todo", diff --git a/flake.nix b/flake.nix index 820be27..b6826f6 100644 --- a/flake.nix +++ b/flake.nix @@ -17,63 +17,59 @@ inputs.home-manager.follows = "home-manager"; }; - # Per-user settings (override locally; keep stub tracked) personal = { url = "path:./personal.stub.nix"; flake = false; }; - - # Per-machine hardware config (override locally; keep stub tracked) - hw = { - url = "path:./nixos/hardware-stub.nix"; - flake = false; - }; }; outputs = inputs@{ self, nixpkgs, home-manager, ... }: let - system = "x86_64-linux"; - personal = import inputs.personal; - username = personal.username or "krosh"; - host = personal.host or "loki-nixos"; - gitName = personal.gitName or "Dmitrii Gudov"; gitEmail = personal.gitEmail or "gudovdo@my.msu.ru"; - pkgs = nixpkgs.legacyPackages.${system}; - in { - homeConfigurations.${username} = - home-manager.lib.homeManagerConfiguration { - inherit pkgs; - modules = [ ./home-manager/home.nix ]; - extraSpecialArgs = { inherit inputs username gitName gitEmail; }; + mkHost = { hostName, system ? "x86_64-linux" }: + nixpkgs.lib.nixosSystem { + inherit system; + + specialArgs = { inherit inputs username gitName gitEmail hostName; }; + + modules = [ + ./hosts/${hostName}/configuration.nix + + home-manager.nixosModules.home-manager + { + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + + home-manager.users.${username} = import ./home-manager/home.nix; + home-manager.extraSpecialArgs = { + inherit inputs username gitName gitEmail; + }; + } + ]; }; + pkgsFor = system: nixpkgs.legacyPackages.${system}; - nixosConfigurations.${host} = nixpkgs.lib.nixosSystem { - inherit system; + in { + # homeConfigurations.${username} = + # home-manager.lib.homeManagerConfiguration { + # pkgs = pkgsFor "x86_64-linux"; + # modules = [ ./home-manager/home.nix ]; + # extraSpecialArgs = { inherit inputs username gitName gitEmail; }; + # }; - # if your NixOS modules want these too - specialArgs = { inherit inputs username gitName gitEmail; }; - - modules = [ - # hardware-configuration comes from `inputs.hw` - (import inputs.hw) - - ./nixos/configuration.nix - - home-manager.nixosModules.home-manager - { - home-manager.useGlobalPkgs = true; - home-manager.useUserPackages = true; - - home-manager.users.${username} = import ./home-manager/home.nix; - home-manager.extraSpecialArgs = { - inherit inputs username gitName gitEmail; - }; - } - ]; + nixosConfigurations = { + loki-nixos = mkHost { + hostName = "loki-nixos"; + system = "x86_64-linux"; + }; + fenrir-nixos = mkHost { + hostName = "fenrir-nixos"; + system = "x86_64-linux"; + }; }; }; } diff --git a/home-manager/modules/zsh/zsh.nix b/home-manager/modules/zsh/zsh.nix index 317519f..62f8c6a 100644 --- a/home-manager/modules/zsh/zsh.nix +++ b/home-manager/modules/zsh/zsh.nix @@ -21,6 +21,7 @@ bat ripgrep entr + busybox ]; home.file.".p10k.zsh".source = ./p10k.zsh; diff --git a/hosts/fenrir-nixos/configuration.nix b/hosts/fenrir-nixos/configuration.nix new file mode 100755 index 0000000..4ef8905 --- /dev/null +++ b/hosts/fenrir-nixos/configuration.nix @@ -0,0 +1,142 @@ +{ config, pkgs, ... }: + +{ + networking.hostName = "fenrir-nixos"; # Define your hostname. + imports = [ ../../nixos/custom.nix ]; + + fileSystems."/".options = [ "ssd" "noatime" "compress=zstd" ]; + + swapDevices = [{ + device = "/swapfile"; + size = 4 * 1024; # Creates an 4GB swap file + randomEncryption.enable = true; + }]; + + boot.loader.systemd-boot.enable = true; + boot.loader.efi.canTouchEfiVariables = true; + + # TODO: fix conflicted configurations + + # This runs only intel/amdgpu igpus and nvidia dgpus do not drain power. + + ##### disable nvidia, very nice battery life. + # boot.extraModprobeConfig = '' + # blacklist nouveau + # options nouveau modeset=0 + # ''; + + # services.udev.extraRules = '' + # # Remove NVIDIA USB xHCI Host Controller devices, if present + # ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x0c0330", ATTR{power/control}="auto", ATTR{remove}="1" + + # # Remove NVIDIA USB Type-C UCSI devices, if present + # ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x0c8000", ATTR{power/control}="auto", ATTR{remove}="1" + + # # Remove NVIDIA Audio devices, if present + # ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x040300", ATTR{power/control}="auto", ATTR{remove}="1" + + # # Remove NVIDIA VGA/3D controller devices + # ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x03[0-9]*", ATTR{power/control}="auto", ATTR{remove}="1" + # ''; + + services.thermald.enable = true; + services.power-profiles-daemon.enable = false; + services.auto-cpufreq = { + enable = true; + settings = { + battery = { + governor = "powersave"; + turbo = "never"; + }; + charger = { + governor = "powersave"; + turbo = "auto"; + }; + }; + }; + + # boot.blacklistedKernelModules = + # [ "nouveau" "nvidia" "nvidia_drm" "nvidia_modeset" ]; + + # TODO: try to connect proxy on all system + + networking.networkmanager = { enable = true; }; + + time.timeZone = "Europe/Moscow"; + + i18n.defaultLocale = "en_US.UTF-8"; + + i18n.extraLocaleSettings = { + LC_ADDRESS = "ru_RU.UTF-8"; + LC_IDENTIFICATION = "ru_RU.UTF-8"; + LC_MEASUREMENT = "ru_RU.UTF-8"; + LC_MONETARY = "ru_RU.UTF-8"; + LC_NAME = "ru_RU.UTF-8"; + LC_NUMERIC = "ru_RU.UTF-8"; + LC_PAPER = "ru_RU.UTF-8"; + LC_TELEPHONE = "ru_RU.UTF-8"; + LC_TIME = "ru_RU.UTF-8"; + }; + + services.xserver.enable = true; + + services.xserver.displayManager.gdm.enable = true; + services.xserver.desktopManager.gnome.enable = true; + + services.xserver.xkb = { + layout = "us,ru"; + variant = ""; + options = "grp:win_space_toggle"; + }; + + services.printing.enable = true; + + services.pulseaudio.enable = false; + security.rtkit.enable = true; + services.pipewire = { + enable = true; + alsa.enable = true; + alsa.support32Bit = true; + pulse.enable = true; + }; + + # services.xserver.libinput.enable = true; + + users.users.krosh = { + isNormalUser = true; + description = "krosh"; + extraGroups = [ "networkmanager" "wheel" ]; + }; + + system.stateVersion = "25.11"; + + programs.hyprland = { + enable = true; + withUWSM = true; + # xwayland.enable = true; # Xwayland can be disabled. + }; + + hardware.graphics.enable = true; + services.xserver.videoDrivers = [ "modesetting" "nvidia" ]; + # hardware.nvidia.open = true; + hardware.nvidia = { + open = true; + modesetting.enable = true; # полезно и для Wayland/tearing + prime = { + offload.enable = true; + offload.enableOffloadCmd = true; # добавит скрипт `nvidia-offload` + + # intelBusId = "PCI:0:2:0"; # <-- подставь свои + # nvidiaBusId = "PCI:1:0:0"; # <-- подставь свои + }; + }; + + programs.uwsm.enable = true; + + users.users.krosh.shell = pkgs.zsh; + + security.polkit.enable = true; + # hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.latest; + + environment.sessionVariables.NIXOS_OZONE_WL = "1"; +} diff --git a/hosts/fenrir-nixos/hardware-configuration.nix b/hosts/fenrir-nixos/hardware-configuration.nix new file mode 100755 index 0000000..74cf09f --- /dev/null +++ b/hosts/fenrir-nixos/hardware-configuration.nix @@ -0,0 +1,43 @@ +# 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 = [ "nvme" "xhci_pci" "usbhid" "usb_storage" "sd_mod" ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ "kvm-amd" ]; + boot.extraModulePackages = [ ]; + + fileSystems."/" = + { device = "/dev/disk/by-uuid/679969dd-4c5e-47bd-94ab-95cbb1fc5bd3"; + fsType = "btrfs"; + options = [ + "subvol=@" + ]; + }; + + fileSystems."/boot" = + { device = "/dev/disk/by-uuid/5584-3E01"; + fsType = "vfat"; + options = [ "fmask=0077" "dmask=0077" ]; + }; + + swapDevices = [ ]; + + # 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.enp2s0.useDHCP = lib.mkDefault true; + # networking.interfaces.wlo1.useDHCP = lib.mkDefault true; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; + hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; +} + diff --git a/nixos/configuration.nix b/hosts/loki-nixos/configuration.nix similarity index 92% rename from nixos/configuration.nix rename to hosts/loki-nixos/configuration.nix index 8f49065..b4db19b 100644 --- a/nixos/configuration.nix +++ b/hosts/loki-nixos/configuration.nix @@ -1,15 +1,8 @@ -# 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 = [ # Include the results of the hardware scan. - # ./hardware-configuration.nix - ./custom.nix - # - ]; + networking.hostName = "loki-nixos"; # Define your hostname. + imports = [ ../../nixos/custom.nix ]; fileSystems."/".options = [ "ssd" "noatime" "compress=zstd" ]; swapDevices = [{ @@ -25,7 +18,6 @@ boot.loader.systemd-boot.enable = true; boot.loader.efi.canTouchEfiVariables = true; - networking.hostName = "loki-nixos"; # Define your hostname. # networking.wireless.enable = true; # Enables wireless support via wpa_supplicant. # Configure network proxy if necessary @@ -94,7 +86,7 @@ # Define a user account. Don't forget to set a password with ‘passwd’. users.users.krosh = { isNormalUser = true; - description = "Krosh"; + description = "krosh"; extraGroups = [ "fprint" "networkmanager" "wheel" "libvirtd" ]; packages = with pkgs; [ diff --git a/hosts/loki-nixos/hardware-configuration.nix b/hosts/loki-nixos/hardware-configuration.nix new file mode 100644 index 0000000..5229ffb --- /dev/null +++ b/hosts/loki-nixos/hardware-configuration.nix @@ -0,0 +1,40 @@ +# 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" "nvme" "usb_storage" "sd_mod" "sdhci_pci" ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ "kvm-intel" ]; + boot.extraModulePackages = [ ]; + + fileSystems."/" = + { device = "/dev/disk/by-uuid/57528dff-a344-4f53-83e9-2959547fc44b"; + fsType = "btrfs"; + options = [ "subvol=@" ]; + }; + + fileSystems."/boot" = + { device = "/dev/disk/by-uuid/9084-E330"; + fsType = "vfat"; + options = [ "fmask=0077" "dmask=0077" ]; + }; + + swapDevices = [ ]; + + # 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.enp0s31f6.useDHCP = lib.mkDefault true; + # networking.interfaces.wlp0s20f3.useDHCP = lib.mkDefault true; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; + hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; +} diff --git a/nixos/hardware-stub.nix b/nixos/hardware-stub.nix deleted file mode 100644 index ae2c9ee..0000000 --- a/nixos/hardware-stub.nix +++ /dev/null @@ -1,7 +0,0 @@ -{ ... }: { - assertions = [{ - assertion = false; - message = - "Override hw: --override-input hw path:/etc/nixos/hardware-configuration.nix"; - }]; -} diff --git a/personal.stub.nix b/personal.stub.nix index c267659..243b548 100644 --- a/personal.stub.nix +++ b/personal.stub.nix @@ -1,6 +1,5 @@ { username = "krosh"; - host = "loki-nixos"; gitName = "Dmitrii Gudov"; gitEmail = "gudovdo@my.msu.ru";