From 5054b1356461c38c484b32dd67ef70bb3299a4c7 Mon Sep 17 00:00:00 2001 From: Crony Akatsuki Date: Wed, 29 Jan 2025 21:26:50 +0100 Subject: [PATCH] Install nh and friends, modularize nixos conf. --- flake.nix | 5 +- hosts/default/configuration.nix | 207 ------------------ hosts/nixos/configuration.nix | 108 +++++++++ .../hardware-configuration.nix | 0 hosts/{default => nixos}/home.nix | 4 + modules/nixos/bluetooth.nix | 15 ++ modules/nixos/default.nix | 11 + modules/nixos/disable-hibernation.nix | 30 +++ modules/nixos/gaming.nix | 15 ++ modules/nixos/nvidia.nix | 27 +++ modules/nixos/plasma.nix | 21 ++ modules/nixos/stylix.nix | 51 +++++ .../default => modules/nixos}/wallpaper.png | Bin modules/nixos/zsh.nix | 17 ++ 14 files changed, 302 insertions(+), 209 deletions(-) delete mode 100644 hosts/default/configuration.nix create mode 100644 hosts/nixos/configuration.nix rename hosts/{default => nixos}/hardware-configuration.nix (100%) rename hosts/{default => nixos}/home.nix (98%) create mode 100644 modules/nixos/bluetooth.nix create mode 100644 modules/nixos/default.nix create mode 100644 modules/nixos/disable-hibernation.nix create mode 100644 modules/nixos/gaming.nix create mode 100644 modules/nixos/nvidia.nix create mode 100644 modules/nixos/plasma.nix create mode 100644 modules/nixos/stylix.nix rename {hosts/default => modules/nixos}/wallpaper.png (100%) create mode 100644 modules/nixos/zsh.nix diff --git a/flake.nix b/flake.nix index 3efd833..70fc387 100644 --- a/flake.nix +++ b/flake.nix @@ -27,11 +27,12 @@ home-manager, ... } @ inputs: { - nixosConfigurations.default = nixpkgs.lib.nixosSystem { + nixosConfigurations.nixos = nixpkgs.lib.nixosSystem { specialArgs = {inherit inputs;}; modules = [ - ./hosts/default/configuration.nix + ./hosts/nixos/configuration.nix inputs.stylix.nixosModules.stylix + ./modules/nixos ]; }; }; diff --git a/hosts/default/configuration.nix b/hosts/default/configuration.nix deleted file mode 100644 index a6bde3c..0000000 --- a/hosts/default/configuration.nix +++ /dev/null @@ -1,207 +0,0 @@ -{ - config, - inputs, - pkgs, - ... -}: { - imports = [ - # Include the results of the hardware scan. - ./hardware-configuration.nix - inputs.home-manager.nixosModules.home-manager - ]; - - # Bootloader. - boot.loader.systemd-boot.enable = true; - boot.loader.efi.canTouchEfiVariables = true; - - # Get nicer hostname - networking.hostName = "nixos"; # Define your hostname. - - # Enable flakes - nix.settings.experimental-features = ["nix-command" "flakes"]; - - # Enable bluetooth - hardware.bluetooth.enable = true; - hardware.bluetooth.powerOnBoot = true; - - # Setup gpu - hardware.graphics = { - enable = true; - enable32Bit = true; - }; - - # Allow for nvidia - services.xserver.videoDrivers = ["nvidia"]; - hardware.nvidia.open = false; - hardware.nvidia.modesetting.enable = true; - hardware.nvidia.powerManagement.enable = true; - hardware.nvidia.nvidiaSettings = true; - hardware.nvidia.prime = { - offload = { - enableOffloadCmd = true; - enable = true; - }; - - nvidiaBusId = "PCI:1:0:0"; - amdgpuBusId = "PCI:5:0:0"; - }; - - # Enable networking - networking.networkmanager.enable = true; - - # Set your time zone. - time.timeZone = "Europe/Zagreb"; - - # Select internationalisation properties. - i18n.defaultLocale = "en_US.UTF-8"; - - i18n.extraLocaleSettings = { - LC_ADDRESS = "hr_HR.UTF-8"; - LC_IDENTIFICATION = "hr_HR.UTF-8"; - LC_MEASUREMENT = "hr_HR.UTF-8"; - LC_MONETARY = "hr_HR.UTF-8"; - LC_NAME = "hr_HR.UTF-8"; - LC_NUMERIC = "hr_HR.UTF-8"; - LC_PAPER = "hr_HR.UTF-8"; - LC_TELEPHONE = "hr_HR.UTF-8"; - LC_TIME = "hr_HR.UTF-8"; - }; - - # Enable the X11 windowing system. - services.xserver.enable = true; - - # Configure keymap in X11 - services.xserver.xkb = { - layout = "us"; - variant = ""; - options = "caps:escape"; - }; - - # Enable the KDE Plasma Desktop Environment. - services.displayManager.sddm.enable = true; - services.desktopManager.plasma6.enable = true; - environment.plasma6.excludePackages = with pkgs.kdePackages; [ - plasma-browser-integration - konsole - oxygen - ]; - - # Enable sound with pipewire. - services.pulseaudio.enable = false; - security.rtkit.enable = true; - services.pipewire = { - enable = true; - alsa.enable = true; - alsa.support32Bit = true; - pulse.enable = true; - }; - - # Define a user account. Don't forget to set a password with ‘passwd’. - users.users.crony = { - isNormalUser = true; - description = "Crony"; - extraGroups = ["networkmanager" "wheel" "video" "input" "audio" "libvirtd"]; - }; - - # Setup home manager - home-manager = { - extraSpecialArgs = {inherit inputs;}; - backupFileExtension = "backup"; - users = { - crony = import ./home.nix; - }; - }; - - # Disable hibernation, sleep and other friends - systemd.targets = { - sleep = { - enable = false; - unitConfig.DefaultDependencies = "no"; - }; - suspend = { - enable = false; - unitConfig.DefaultDependencies = "no"; - }; - hibernate = { - enable = false; - unitConfig.DefaultDependencies = "no"; - }; - "hybrid-sleep" = { - enable = false; - unitConfig.DefaultDependencies = "no"; - }; - }; - - # Allow unfree packages - nixpkgs.config.allowUnfree = true; - - # List packages installed in system profile - environment.systemPackages = with pkgs; [ - neovim - mangohud - ]; - - # Getting gaming setup - programs.steam.enable = true; - programs.steam.gamescopeSession.enable = true; - programs.gamemode.enable = true; - - # Installing zsh - programs.zsh.enable = true; - users.defaultUserShell = pkgs.zsh; - environment.pathsToLink = [ "/share/zsh" ]; - - # Enable sytling using stylix - stylix.enable = true; - stylix.autoEnable = true; - stylix.image = ./wallpaper.png; - stylix.base16Scheme = "${pkgs.base16-schemes}/share/themes/gruvbox-dark-medium.yaml"; - - # Change Cursor - stylix.cursor.package = pkgs.bibata-cursors; - stylix.cursor.name = "Bibata-Modern-Ice"; - - # Change u those fonts - stylix.fonts = { - serif = { - package = pkgs.dejavu_fonts; - name = "DejaVu Serif"; - }; - - sansSerif = { - package = pkgs.dejavu_fonts; - name = "DejaVu Sans"; - }; - - monospace = { - package = pkgs.nerd-fonts.caskaydia-cove; - name = "CaskaydiaCove Nerd Font"; - }; - - emoji = { - package = pkgs.noto-fonts-emoji; - name = "Noto Color Emoji"; - }; - }; - - # Enable nixd to see nixpkgs path - nix.nixPath = ["nixpkgs=${inputs.nixpkgs}"]; - - # Change terminal font size - stylix.fonts.sizes.terminal = 15; - - # Change chrome settings - stylix.targets.chromium.enable = true; - - # Enable zram swap device - zramSwap.enable = true; - - # Nfs share - fileSystems."/mnt/share" = { - device = "192.168.0.4:/mnt/nfs"; - fsType = "nfs"; - }; - - # DO NOT CHANGE - system.stateVersion = "24.11"; # Did you read the comment? -} diff --git a/hosts/nixos/configuration.nix b/hosts/nixos/configuration.nix new file mode 100644 index 0000000..9ba1bea --- /dev/null +++ b/hosts/nixos/configuration.nix @@ -0,0 +1,108 @@ +{ + inputs, + pkgs, + ... +}: { + imports = [ + # Include the results of the hardware scan. + ./hardware-configuration.nix + inputs.home-manager.nixosModules.home-manager + ]; + + # Bootloader. + boot.loader.systemd-boot.enable = true; + boot.loader.efi.canTouchEfiVariables = true; + + # Get nicer hostname + networking.hostName = "nixos"; # Define your hostname. + + # Enable flakes + nix.settings.experimental-features = ["nix-command" "flakes"]; + + # Setup gpu + hardware.graphics = { + enable = true; + enable32Bit = true; + }; + + # Enable networking + networking.networkmanager.enable = true; + + # Set your time zone. + time.timeZone = "Europe/Zagreb"; + + # Select internationalisation properties. + i18n.defaultLocale = "en_US.UTF-8"; + + i18n.extraLocaleSettings = { + LC_ADDRESS = "hr_HR.UTF-8"; + LC_IDENTIFICATION = "hr_HR.UTF-8"; + LC_MEASUREMENT = "hr_HR.UTF-8"; + LC_MONETARY = "hr_HR.UTF-8"; + LC_NAME = "hr_HR.UTF-8"; + LC_NUMERIC = "hr_HR.UTF-8"; + LC_PAPER = "hr_HR.UTF-8"; + LC_TELEPHONE = "hr_HR.UTF-8"; + LC_TIME = "hr_HR.UTF-8"; + }; + + # Enable the X11 windowing system. + services.xserver.enable = true; + + # Configure keymap in X11 + services.xserver.xkb = { + layout = "us"; + variant = ""; + options = "caps:escape"; + }; + + # Enable sound with pipewire. + services.pulseaudio.enable = false; + security.rtkit.enable = true; + services.pipewire = { + enable = true; + alsa.enable = true; + alsa.support32Bit = true; + pulse.enable = true; + }; + + # Define a user account. Don't forget to set a password with ‘passwd’. + users.users.crony = { + isNormalUser = true; + description = "Crony"; + extraGroups = ["networkmanager" "wheel" "video" "input" "audio" "libvirtd"]; + }; + + # Setup home manager + home-manager = { + extraSpecialArgs = {inherit inputs;}; + backupFileExtension = "backup"; + users = { + crony = import ./home.nix; + }; + }; + + # Allow unfree packages + nixpkgs.config.allowUnfree = true; + + # List packages installed in system profile + environment.systemPackages = with pkgs; [ + neovim + mangohud + ]; + + # Enable nixd to see nixpkgs path + nix.nixPath = ["nixpkgs=${inputs.nixpkgs}"]; + + # Enable zram swap device + zramSwap.enable = true; + + # Nfs share + fileSystems."/mnt/share" = { + device = "192.168.0.4:/mnt/nfs"; + fsType = "nfs"; + }; + + # DO NOT CHANGE + system.stateVersion = "24.11"; +} diff --git a/hosts/default/hardware-configuration.nix b/hosts/nixos/hardware-configuration.nix similarity index 100% rename from hosts/default/hardware-configuration.nix rename to hosts/nixos/hardware-configuration.nix diff --git a/hosts/default/home.nix b/hosts/nixos/home.nix similarity index 98% rename from hosts/default/home.nix rename to hosts/nixos/home.nix index 36de850..9de69c6 100644 --- a/hosts/default/home.nix +++ b/hosts/nixos/home.nix @@ -19,6 +19,9 @@ keepassxc restic age + nh + nix-output-monitor + nvd ]; # Enable programs to get their themes @@ -240,6 +243,7 @@ # Default environmental variables home.sessionVariables = { EDITOR = "nvim"; + FLAKE = "/home/crony/Repos/nixos"; }; # Let Home Manager install and manage itself. diff --git a/modules/nixos/bluetooth.nix b/modules/nixos/bluetooth.nix new file mode 100644 index 0000000..30dd41e --- /dev/null +++ b/modules/nixos/bluetooth.nix @@ -0,0 +1,15 @@ +{ + lib, + config, + ... +}: { + # Enable bluetooth + options = { + crony.bluetooth.enable = lib.mkEnableOption "enable bluetooth"; + }; + + config = lib.mkIf config.crony.bluetooth.enable { + hardware.bluetooth.enable = true; + hardware.bluetooth.powerOnBoot = true; + }; +} diff --git a/modules/nixos/default.nix b/modules/nixos/default.nix new file mode 100644 index 0000000..4231d1d --- /dev/null +++ b/modules/nixos/default.nix @@ -0,0 +1,11 @@ +{lib, ...}: { + imports = [./bluetooth.nix ./nvidia.nix ./plasma.nix ./disable-hibernation.nix ./gaming.nix ./zsh.nix ./stylix.nix]; + + crony.bluetooth.enable = lib.mkDefault true; + crony.nvidia.enable = lib.mkDefault true; + crony.plasma.enable = lib.mkDefault true; + crony.hibernation.disable = lib.mkDefault true; + crony.gaming.enable = lib.mkDefault true; + crony.zsh.enable = lib.mkDefault true; + crony.stylix.enable = lib.mkDefault true; +} diff --git a/modules/nixos/disable-hibernation.nix b/modules/nixos/disable-hibernation.nix new file mode 100644 index 0000000..6f52d81 --- /dev/null +++ b/modules/nixos/disable-hibernation.nix @@ -0,0 +1,30 @@ +{ + config, + lib, + ... +}: { + options = { + crony.hibernation.disable = lib.mkEnableOption "disable hibernation and friends"; + }; + config = lib.mkIf config.crony.hibernation.disable { + # Disable hibernation, sleep and other friends + systemd.targets = { + sleep = { + enable = false; + unitConfig.DefaultDependencies = "no"; + }; + suspend = { + enable = false; + unitConfig.DefaultDependencies = "no"; + }; + hibernate = { + enable = false; + unitConfig.DefaultDependencies = "no"; + }; + "hybrid-sleep" = { + enable = false; + unitConfig.DefaultDependencies = "no"; + }; + }; + }; +} diff --git a/modules/nixos/gaming.nix b/modules/nixos/gaming.nix new file mode 100644 index 0000000..fcc0582 --- /dev/null +++ b/modules/nixos/gaming.nix @@ -0,0 +1,15 @@ +{ + config, + lib, + ... +}: { + # Getting gaming setup + options = { + crony.gaming.enable = lib.mkEnableOption "enable gaming related stuff, like steam and gamemode"; + }; + config = lib.mkIf config.crony.gaming.enable { + programs.steam.enable = true; + programs.steam.gamescopeSession.enable = true; + programs.gamemode.enable = true; + }; +} diff --git a/modules/nixos/nvidia.nix b/modules/nixos/nvidia.nix new file mode 100644 index 0000000..5f350c3 --- /dev/null +++ b/modules/nixos/nvidia.nix @@ -0,0 +1,27 @@ +{ + lib, + config, + ... +}: { + # Allow for nvidia + options = { + crony.nvidia.enable = lib.mkEnableOption "enable nvidia"; + }; + + config = lib.mkIf config.crony.nvidia.enable { + services.xserver.videoDrivers = ["nvidia"]; + hardware.nvidia.open = false; + hardware.nvidia.modesetting.enable = true; + hardware.nvidia.powerManagement.enable = true; + hardware.nvidia.nvidiaSettings = true; + hardware.nvidia.prime = { + offload = { + enableOffloadCmd = true; + enable = true; + }; + + nvidiaBusId = "PCI:1:0:0"; + amdgpuBusId = "PCI:5:0:0"; + }; + }; +} diff --git a/modules/nixos/plasma.nix b/modules/nixos/plasma.nix new file mode 100644 index 0000000..09aa1ef --- /dev/null +++ b/modules/nixos/plasma.nix @@ -0,0 +1,21 @@ +{ + pkgs, + config, + lib, + ... +}: { + options = { + crony.plasma.enable = lib.mkEnableOption "enable plasma"; + }; + + config = lib.mkIf config.crony.plasma.enable { + # Enable the KDE Plasma Desktop Environment. + services.displayManager.sddm.enable = true; + services.desktopManager.plasma6.enable = true; + environment.plasma6.excludePackages = with pkgs.kdePackages; [ + plasma-browser-integration + konsole + oxygen + ]; + }; +} diff --git a/modules/nixos/stylix.nix b/modules/nixos/stylix.nix new file mode 100644 index 0000000..46cccf6 --- /dev/null +++ b/modules/nixos/stylix.nix @@ -0,0 +1,51 @@ +{ + pkgs, + config, + lib, + ... +}: { + options = { + crony.stylix.enable = lib.mkEnableOption "enable stylix and style my system"; + }; + + config = lib.mkIf config.crony.stylix.enable { + # Enable sytling using stylix + stylix.enable = true; + stylix.autoEnable = true; + stylix.image = ./wallpaper.png; + stylix.base16Scheme = "${pkgs.base16-schemes}/share/themes/gruvbox-dark-medium.yaml"; + + # Change Cursor + stylix.cursor.package = pkgs.bibata-cursors; + stylix.cursor.name = "Bibata-Modern-Ice"; + + # Change u those fonts + stylix.fonts = { + serif = { + package = pkgs.dejavu_fonts; + name = "DejaVu Serif"; + }; + + sansSerif = { + package = pkgs.dejavu_fonts; + name = "DejaVu Sans"; + }; + + monospace = { + package = pkgs.nerd-fonts.caskaydia-cove; + name = "CaskaydiaCove Nerd Font"; + }; + + emoji = { + package = pkgs.noto-fonts-emoji; + name = "Noto Color Emoji"; + }; + }; + + # Change terminal font size + stylix.fonts.sizes.terminal = 15; + + # Change chrome settings + stylix.targets.chromium.enable = true; + }; +} diff --git a/hosts/default/wallpaper.png b/modules/nixos/wallpaper.png similarity index 100% rename from hosts/default/wallpaper.png rename to modules/nixos/wallpaper.png diff --git a/modules/nixos/zsh.nix b/modules/nixos/zsh.nix new file mode 100644 index 0000000..fea2b53 --- /dev/null +++ b/modules/nixos/zsh.nix @@ -0,0 +1,17 @@ +{ + config, + lib, + pkgs, + ... +}: { + options = { + crony.zsh.enable = lib.mkEnableOption "install and enable zsh for all users"; + }; + + config = lib.mkIf config.crony.zsh.enable { + # Installing zsh + programs.zsh.enable = true; + users.defaultUserShell = pkgs.zsh; + environment.pathsToLink = ["/share/zsh"]; + }; +}