From 9fddd3f4c84abecc5f49cfdc8ffe56ca3ca0a335 Mon Sep 17 00:00:00 2001 From: Alexandre1a Date: Wed, 14 Jan 2026 22:10:18 +0100 Subject: [PATCH] Factorised some nix expressions because I had some time to spare, started adding a new host --- hosts/common/home.nix | 7 +- hosts/common/modules.nix | 6 +- hosts/light/configuration.nix | 37 +++++++++++ hosts/macos/configuration.nix | 41 +++++------- hosts/macos/home.nix | 20 +++--- hosts/macos/modules.nix | 2 +- hosts/nixos/configuration.nix | 73 ++++++++++----------- hosts/nixos/hardware-configuration.nix | 28 ++++++-- hosts/nixos/home.nix | 91 +++++++++++++------------- hosts/nixos/modules.nix | 4 +- modules/common/environment.nix | 24 +++++++ modules/common/nix.nix | 6 ++ modules/common/spotify.nix | 22 ++++--- modules/common/ssh.nix | 14 ++-- modules/home-manager/shell.nix | 76 ++++++++++----------- modules/nixos/bootloader.nix | 12 ++++ modules/nixos/gamming/nvidia.nix | 54 ++++++++------- modules/nixos/gamming/steam.nix | 24 ++++--- modules/nixos/locale.nix | 15 +++-- modules/nixos/secrets.nix | 4 +- modules/nixos/wireless.nix | 20 ++++-- 21 files changed, 348 insertions(+), 232 deletions(-) create mode 100644 modules/common/environment.nix create mode 100644 modules/nixos/bootloader.nix diff --git a/hosts/common/home.nix b/hosts/common/home.nix index cb3edf7..9db5f06 100644 --- a/hosts/common/home.nix +++ b/hosts/common/home.nix @@ -28,12 +28,9 @@ home = { packages = with pkgs; [ # CLI - btop hello - fastfetch yt-dlp syncthing # ToDo: configure it ig - cmatrix spicetify-cli # Dev CLI doxygen @@ -41,9 +38,6 @@ pkg-config swig pandoc - gh - fzf - eza # GUI apps vscode @@ -70,6 +64,7 @@ python312 # The main interpreter #pip # The package manager ]; + shellAliases = { drs = "sudo darwin-rebuild switch --flake ~/Developer/nix/NixOSDots#macOS"; nrs = "sudo nixos-rebuild switch --flake ~/Developer/nix/NixOSDots#nixos"; diff --git a/hosts/common/modules.nix b/hosts/common/modules.nix index df4817d..3a09b2b 100644 --- a/hosts/common/modules.nix +++ b/hosts/common/modules.nix @@ -1,6 +1,10 @@ { + # Common nixos systems modules (not nix-darwin) imports = [ ../../modules/common/nix.nix - ../../modules/nixos/locale.nix + ../../modules/nixos/locale.nix # For localisation options + ../../modules/common/ssh.nix + ../../modules/nixos/bootloader.nix + ../../modules/common/environment.nix ]; } \ No newline at end of file diff --git a/hosts/light/configuration.nix b/hosts/light/configuration.nix index c1dbc9c..bc106a9 100644 --- a/hosts/light/configuration.nix +++ b/hosts/light/configuration.nix @@ -4,4 +4,41 @@ ./modules.nix ]; + networking = { + hostName = "light"; + }; + + # Users + # Don't forget to add a password or change the username + users = { + users = { + light = { # Here + isNormalUser = true; + # You can change the description too ! + description = "A lightweight system for lowend or performance machines" + shell = pkgs.zsh; + extraGroups = [ "networkmanager" "wheel" ]; + }; + }; + }; + + # Home-Manager config + home-manager = { + extraSpecialArgs = { inherit inputs }; + useGlobalPkgs = true; + useUserPackages = true; + backupFileExtension = "HM-backup"; + users = { + # Change this to your username + "light" = import ./home.nix"; + }; + }; + + environment = { + systemPackages = with pkgs; [ + wget + git + ]; + }; + } diff --git a/hosts/macos/configuration.nix b/hosts/macos/configuration.nix index b81348c..8bda416 100644 --- a/hosts/macos/configuration.nix +++ b/hosts/macos/configuration.nix @@ -13,31 +13,20 @@ environment = { systemPackages = with pkgs; [ - # Basic text editing for all users - neovim - vim - # General tools - btop - eza - fastfetch - ffmpeg - fzf - git git-lfs - gnupg - wget - tree - netcat - tmux #telnet ]; pathsToLink = [ "/share/zsh" ]; }; # Create the user - users.users.alex = { - description = "Alexandre Delcamp--Enache"; - home = "/Users/alex"; - shell = pkgs.zsh; + users = { + users = { + alex = { + description = "Alexandre Delcamp--Enache"; + home = "/Users/alex"; + shell = pkgs.zsh; + }; + }; }; # HomeManager home-manager = { @@ -61,14 +50,18 @@ }; # Enable required settings # TouchID login - security.pam.services.sudo_local.touchIdAuth = true; - + security = { + pam = { + services = { + sudo_local = { + touchIdAuth = true; + }; + }; + }; + }; # Target arch nixpkgs = { hostPlatform = "aarch64-darwin"; - config = { - allowUnfree = true; - }; }; # Nix-Darwin State Version system = { diff --git a/hosts/macos/home.nix b/hosts/macos/home.nix index b369845..dc00ca8 100644 --- a/hosts/macos/home.nix +++ b/hosts/macos/home.nix @@ -6,14 +6,14 @@ ../common/home.nix ]; - home.stateVersion = "25.11"; - # Allow unfree packages - #nixpkgs.config.allowUnfree = true; - - home.packages = with pkgs; [ - # Window management (maybe configure it with home-manager) - yabai - skhd - #borders - ]; + + home = { + packages = with pkgs; [ + # Window management (maybe configure it with home-manager) + yabai + skhd + #borders + ]; + stateVersion = "25.11"; + }; } diff --git a/hosts/macos/modules.nix b/hosts/macos/modules.nix index ebfccaf..dc6d777 100644 --- a/hosts/macos/modules.nix +++ b/hosts/macos/modules.nix @@ -3,7 +3,7 @@ { # Enpty file for future imports imports = [ - ../common/modules.nix + ../../modules/common/nix.nix ../../modules/macos/ollama.nix ../../modules/common/ai.nix ]; diff --git a/hosts/nixos/configuration.nix b/hosts/nixos/configuration.nix index 6c7c2e1..e9c9743 100644 --- a/hosts/nixos/configuration.nix +++ b/hosts/nixos/configuration.nix @@ -11,11 +11,12 @@ ./modules.nix ]; - # Bootloader. - boot.loader.systemd-boot.enable = true; - boot.loader.efi.canTouchEfiVariables = true; - - networking.hostName = "nixos"; # Define your hostname. + networking = { + hostName = "nixos"; # Define your hostname. + networkmanager = { + enable = true; # Enables wireless connectivity + }; + }; # networking.wireless.enable = true; # Enables wireless support via wpa_supplicant. @@ -47,17 +48,19 @@ # networking.proxy.default = "http://user:password@proxy:port/"; # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain"; - # Enable networking - networking.networkmanager.enable = true; # Define a user account. Don't forget to set a password with ‘passwd’. - users.users.alex = { - isNormalUser = true; - description = "Alexandre Delcamp--Enache"; - shell = pkgs.zsh; - extraGroups = [ "networkmanager" "wheel" ]; - packages = with pkgs; [ - ]; + users = { + users = { + alex = { + isNormalUser = true; + description = "Alexandre Delcamp--Enache"; + shell = pkgs.zsh; + extraGroups = [ "networkmanager" "wheel" ]; + packages = with pkgs; [ + ]; + }; + }; }; home-manager = { @@ -83,36 +86,28 @@ enableAutosuggestions = true; }; }; - # Hint Electron Apps to use Wayland - environment = { - sessionVariables.NIXOS_OZONE_WL = "1"; - pathsToLink = [ "/share/zsh" ]; - }; - # Allow unfree packages - nixpkgs.config.allowUnfree = true; # List packages installed in system profile. To search, run: # $ nix search wget - environment.systemPackages = with pkgs; [ - # vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default. - wget - git - tree - kitty - neovim - playerctl + environment = { + systemPackages = with pkgs; [ + playerctl - # Nvidia packages - nvtopPackages.nvidia - # Video accel - libva - libva-utils - # Cuda - cudatoolkit + # Nvidia packages + nvtopPackages.nvidia + # Video accel + libva + libva-utils + # Cuda + cudatoolkit - # Theme SDDM - sddm-astronaut - ]; + # Theme SDDM + sddm-astronaut + ]; + # Hint Electron Apps to use Wayland + sessionVariables.NIXOS_OZONE_WL = "1"; + pathsToLink = [ "/share/zsh" ]; + }; # Some programs need SUID wrappers, can be configured further or are # started in user sessions. diff --git a/hosts/nixos/hardware-configuration.nix b/hosts/nixos/hardware-configuration.nix index f60eecf..6e8eb3c 100644 --- a/hosts/nixos/hardware-configuration.nix +++ b/hosts/nixos/hardware-configuration.nix @@ -8,10 +8,14 @@ [ (modulesPath + "/installer/scan/not-detected.nix") ]; - boot.initrd.availableKernelModules = [ "xhci_pci" "ahci" "nvme" "usb_storage" "usbhid" "sd_mod" ]; - boot.initrd.kernelModules = [ ]; - boot.kernelModules = [ "kvm-intel" ]; - boot.extraModulePackages = [ ]; + boot = { + initrd = { + availableKernelModules = [ "xhci_pci" "ahci" "nvme" "usb_storage" "usbhid" "sd_mod" ]; + kernelModules = [ ]; + }; + kernelModules = [ "kvm-intel" ]; + extraModulePackages = [ ]; + }; fileSystems."/" = { device = "/dev/disk/by-uuid/09ecff70-45e5-48b4-baed-00534605fc04"; @@ -30,10 +34,20 @@ # (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 ={ + useDHCP = lib.mkDefault true; + }; # networking.interfaces.eno1.useDHCP = lib.mkDefault true; # networking.interfaces.wlp4s0.useDHCP = lib.mkDefault true; - nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; - hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; + nixpkgs = { + hostPlatform = lib.mkDefault "x86_64-linux"; + }; + hardware = { + cpu = { + intel = { + updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; + }; + }; + }; } diff --git a/hosts/nixos/home.nix b/hosts/nixos/home.nix index c6c8ab8..74ba554 100644 --- a/hosts/nixos/home.nix +++ b/hosts/nixos/home.nix @@ -14,54 +14,60 @@ # You should not change this value, even if you update Home Manager. If you do # want to update the value, then make sure to first check the Home Manager # release notes. - home.stateVersion = "25.11"; # Please read the comment before changing. - # The home.packages option allows you to install Nix packages into your - # environment. - home.packages = with pkgs; [ - # # Adds the 'hello' command to your environment. It prints a friendly - # # "Hello, world!" when run. + home = { + stateVersion = "25.11"; # Please read the comment before changing. + packages = with pkgs; [ + # # Adds the 'hello' command to your environment. It prints a friendly + # # "Hello, world!" when run. - # Hyprland related (rice, etc...) - wofi - alacritty - firefox - cava - # File manager - kdePackages.dolphin - kdePackages.gwenview - # Hypr* ecosystem - hyprlauncher + # Hyprland related (rice, etc...) + wofi + alacritty + firefox + cava + # File manager + kdePackages = [ + dolphin + gwenview + ] + # Hypr* ecosystem + hyprlauncher - # # It is sometimes useful to fine-tune packages, for example, by applying - # # overrides. You can do that directly here, just don't forget the - # # parentheses. Maybe you want to install Nerd Fonts with a limited number of - # # fonts? - # (pkgs.nerdfonts.override { fonts = [ "FantasqueSansMono" ]; }) + # # It is sometimes useful to fine-tune packages, for example, by applying + # # overrides. You can do that directly here, just don't forget the + # # parentheses. Maybe you want to install Nerd Fonts with a limited number of + # # fonts? + # (pkgs.nerdfonts.override { fonts = [ "FantasqueSansMono" ]; }) - # # You can also create simple shell scripts directly inside your - # # configuration. For example, this adds a command 'my-hello' to your - # # environment: - # (pkgs.writeShellScriptBin "my-hello" '' - # echo "Hello, ${config.home.username}!" - # '') - ]; + # # You can also create simple shell scripts directly inside your + # # configuration. For example, this adds a command 'my-hello' to your + # # environment: + # (pkgs.writeShellScriptBin "my-hello" '' + # echo "Hello, ${config.home.username}!" + # '') + ]; + # Home Manager is pretty good at managing dotfiles. The primary way to manage + # plain files is through 'home.file'. + file = { + # # Building this configuration will create a copy of 'dotfiles/screenrc' in + # # the Nix store. Activating the configuration will then make '~/.screenrc' a + # # symlink to the Nix store copy. + # ".screenrc".source = dotfiles/screenrc; - # Home Manager is pretty good at managing dotfiles. The primary way to manage - # plain files is through 'home.file'. - home.file = { - # # Building this configuration will create a copy of 'dotfiles/screenrc' in - # # the Nix store. Activating the configuration will then make '~/.screenrc' a - # # symlink to the Nix store copy. - # ".screenrc".source = dotfiles/screenrc; - - # # You can also set the file content immediately. - # ".gradle/gradle.properties".text = '' - # org.gradle.console=verbose - # org.gradle.daemon.idletimeout=3600000 - # ''; + # # You can also set the file content immediately. + # ".gradle/gradle.properties".text = '' + # org.gradle.console=verbose + # org.gradle.daemon.idletimeout=3600000 + # ''; + }; + sessionVariables = { + EDITOR = "vim"; + }; }; + + # Home Manager can also manage your environment variables through # 'home.sessionVariables'. These will be explicitly sourced when using a # shell provided by Home Manager. If you don't want to manage your shell @@ -78,7 +84,4 @@ # # /etc/profiles/per-user/alex/etc/profile.d/hm-session-vars.sh # - home.sessionVariables = { - # EDITOR = "emacs"; - }; } diff --git a/hosts/nixos/modules.nix b/hosts/nixos/modules.nix index f4cf143..6ee78d2 100644 --- a/hosts/nixos/modules.nix +++ b/hosts/nixos/modules.nix @@ -7,11 +7,9 @@ inputs.sops-nix.nixosModules.sops ../../modules/nixos/secrets.nix # Sops # ../../modules/nixos/wireless.nix # For the wifi - ../../modules/nixos/locale.nix # For localisation options ../../modules/nixos/gamming/nvidia.nix # Nvidia (Drivers and Settings) ../../modules/nixos/gamming/steam.nix # For Steam/Proton/Lutris/MangoHUD/Heroic/Bottles - ../../modules/common/spotify.nix # Spotify/Spicetify - ../../modules/common/ssh.nix + ../../modules/common/spotify.nix # Spotify ../../modules/common/ai.nix ]; } diff --git a/modules/common/environment.nix b/modules/common/environment.nix new file mode 100644 index 0000000..dc058e1 --- /dev/null +++ b/modules/common/environment.nix @@ -0,0 +1,24 @@ +{ pkgs, ... }: +{ + environment = { + systemPackages = with pkgs; [ + # Text editors + neovim + vim + # Sytem utilities + wget + git + tree + btop + eza + fastfetch + ffmpeg + fzf + netcat + tmux + gnupg + cmatrix + gh + ]; + } +} \ No newline at end of file diff --git a/modules/common/nix.nix b/modules/common/nix.nix index 92c5903..4e23477 100644 --- a/modules/common/nix.nix +++ b/modules/common/nix.nix @@ -25,4 +25,10 @@ ]; }; }; + + nixpkgs = { + config = { + allowUnfree = true; + }; + }; } \ No newline at end of file diff --git a/modules/common/spotify.nix b/modules/common/spotify.nix index b5df166..ec0128b 100644 --- a/modules/common/spotify.nix +++ b/modules/common/spotify.nix @@ -2,13 +2,19 @@ { # Installs Spotify and Spicetify (import this module in configuration.nix) - environment.systemPackages = with pkgs; [ - spotify - ]; + environment = { + systemPackages = with pkgs; [ + spotify + ]; + }; - # Local discovery - networking.firewall.allowedTCPPorts = [ 57621 ]; - - # Spotify Connect - networking.firewall.allowedUDPPorts = [ 5353 ]; + + networking = { + firewall = { + # Local discovery + allowedTCPPorts = [ 57621 ]; + # Spotify Connect + allowedUDPPorts = [ 5353 ]; + }; + }; } diff --git a/modules/common/ssh.nix b/modules/common/ssh.nix index 4ca1d7c..ac65a79 100644 --- a/modules/common/ssh.nix +++ b/modules/common/ssh.nix @@ -1,10 +1,12 @@ { # The OpenSSH agent - programs.ssh = { - startAgent = true; - extraConfig = '' - Host github.com - IdentityFile ~/.ssh/github - ''; + programs = { + ssh = { + startAgent = true; + extraConfig = '' + Host github.com + IdentityFile ~/.ssh/github + ''; + }; }; } diff --git a/modules/home-manager/shell.nix b/modules/home-manager/shell.nix index 4024aa7..ada40aa 100644 --- a/modules/home-manager/shell.nix +++ b/modules/home-manager/shell.nix @@ -1,45 +1,47 @@ { pkgs, ... }: { - programs.zsh = { - enable = true; - package = pkgs.zsh; - enableCompletion = true; - autocd = true; - initContent = "fastfetch --logo small -s DateTime:Battery:CPU:GPU:Memory:Host:Media"; - - autosuggestion = { + programs = { + zsh = { enable = true; - strategy = [ "match_prev_cmd" ]; - highlight = "fg=grey, underline"; - }; + package = pkgs.zsh; + enableCompletion = true; + autocd = true; + initContent = "fastfetch --logo small -s DateTime:Battery:CPU:GPU:Memory:Host:Media"; - history = { - append = true; - extended = true; - ignoreSpace = false; - save = 100000; - size = 100000; - saveNoDups = true; - share = true; - }; - - oh-my-zsh = { - enable = true; - package = pkgs.oh-my-zsh; - plugins = [ - "git" - "react-native" - "golang" - "docker" - #"brew" - "eza" - "fzf" - "gh" - "kitty" - #"zsh-autosuggestions" - #"zsh-syntax-highlighting" - ]; + autosuggestion = { + enable = true; + strategy = [ "match_prev_cmd" ]; + highlight = "fg=grey, underline"; + }; + + history = { + append = true; + extended = true; + ignoreSpace = false; + save = 100000; + size = 100000; + saveNoDups = true; + share = true; + }; + + oh-my-zsh = { + enable = true; + package = pkgs.oh-my-zsh; + plugins = [ + "git" + "react-native" + "golang" + "docker" + #"brew" + "eza" + "fzf" + "gh" + "kitty" + #"zsh-autosuggestions" + #"zsh-syntax-highlighting" + ]; + }; }; }; } diff --git a/modules/nixos/bootloader.nix b/modules/nixos/bootloader.nix new file mode 100644 index 0000000..d95f048 --- /dev/null +++ b/modules/nixos/bootloader.nix @@ -0,0 +1,12 @@ +{ + boot = { + loader = { + systemd-boot = { + enable = true; + }; + efi = { + canTouchEfiVariables = true; + }; + }; + }; +} \ No newline at end of file diff --git a/modules/nixos/gamming/nvidia.nix b/modules/nixos/gamming/nvidia.nix index a2bc03a..4381136 100644 --- a/modules/nixos/gamming/nvidia.nix +++ b/modules/nixos/gamming/nvidia.nix @@ -22,34 +22,42 @@ kernelParams = [ "nvidia-drm.modset=1" # DRM modesetting ]; - initrd.kernelModules = [ - "nvidia" - "nvidia_modeset" - "nvidia_uvm" - "nvidia_drm" - ]; + initrd = { + kernelModules = [ + "nvidia" + "nvidia_modeset" + "nvidia_uvm" + "nvidia_drm" + ]; + }; kernelModules = [ "nvidia" "nvidia_modeset" "nvidia_uvm" "nvidia_drm" ]; }; # Environment variables - environment.sessionVariables = { - # Backend GBM for NVIDIA - GBM_BACKEND = "nvidia-drm"; - - # Use NVIDIA pilot for libva (video acceleration) - LIBVA_DRIVER_NAME = "nvidia"; - - # Vendor library OpenGL - __GLX_VENDOR_LIBRARY_NAME = "nvidia"; - - XDG_SESSION_TYPE = "wayland"; - - WLR_NO_HARDWARE_CURSORS = "1"; - - # Native Wayland Electron Apps - NIXOS_OZONE_WL = "1"; + environment ={ + sessionVariables = { + # Backend GBM for NVIDIA + GBM_BACKEND = "nvidia-drm"; + + # Use NVIDIA pilot for libva (video acceleration) + LIBVA_DRIVER_NAME = "nvidia"; + + # Vendor library OpenGL + __GLX_VENDOR_LIBRARY_NAME = "nvidia"; + + XDG_SESSION_TYPE = "wayland"; + + WLR_NO_HARDWARE_CURSORS = "1"; + + # Native Wayland Electron Apps + NIXOS_OZONE_WL = "1"; + }; }; # Nvidia Drivers - services.xserver.videoDrivers = [ "nvidia" ]; + services = { + xserver = { + videoDrivers = [ "nvidia" ]; + }; + }; } diff --git a/modules/nixos/gamming/steam.nix b/modules/nixos/gamming/steam.nix index 502eb9b..73e44db 100644 --- a/modules/nixos/gamming/steam.nix +++ b/modules/nixos/gamming/steam.nix @@ -15,17 +15,21 @@ }; # Proton GE - environment.sessionVariables = { - STEAM_EXTRA_COMPAT_TOOLS_PATHS = - "/home/alex/.steam/root/compatibilitytools.d"; + environment = { + sessionVariables = { + STEAM_EXTRA_COMPAT_TOOLS_PATHS = + "/home/alex/.steam/root/compatibilitytools.d"; + }; }; # Programmes requis - environment.systemPackages = with pkgs; [ - mangohud - protonup-ng - lutris - heroic - bottles - ]; + environment = { + systemPackages = with pkgs; [ + mangohud + protonup-ng + lutris + heroic + bottles + ]; + }; } diff --git a/modules/nixos/locale.nix b/modules/nixos/locale.nix index f4dc29c..f00cfe4 100644 --- a/modules/nixos/locale.nix +++ b/modules/nixos/locale.nix @@ -19,12 +19,17 @@ }; # Keymap in X11 - services.xserver.xkb = { - layout = "fr"; - #variant = "fr"; + services = { + xserver = { + xkb = { + layout = "fr"; + #variant = "fr"; + }; + }; }; # Keymap in the console - console.keyMap = "fr"; - + console = { + keyMap = "fr"; + }; } diff --git a/modules/nixos/secrets.nix b/modules/nixos/secrets.nix index a1cc3d2..f35f4e0 100644 --- a/modules/nixos/secrets.nix +++ b/modules/nixos/secrets.nix @@ -5,6 +5,8 @@ defaultSopsFile = ../../secrets/secrets.yaml; defaultSopsFormat = "yaml"; - age.keyFile = "${config.home-manager.users.alex.home.homeDirectory}/.config/sops/age/keys.txt"; + age = { + keyFile = "${config.home-manager.users.alex.home.homeDirectory}/.config/sops/age/keys.txt"; + }; }; } diff --git a/modules/nixos/wireless.nix b/modules/nixos/wireless.nix index 575e87a..ef308fe 100644 --- a/modules/nixos/wireless.nix +++ b/modules/nixos/wireless.nix @@ -1,15 +1,21 @@ { config, ... }: { - sops.secrets."wireless/freebox-password" = { - owner = "root"; - group = "root"; - mode = "0400"; + sops = { + secrets = { + "wireless/freebox-password" = { + owner = "root"; + group = "root"; + mode = "0400"; + }; + }; }; - networking.wireless.networks = { - Freebox-357429 = { - pskRaw = "ext:${config.sops.secrets."wireless/freebox-password".path}"; + networking = { + wireless.networks = { + Freebox-357429 = { + pskRaw = "ext:${config.sops.secrets."wireless/freebox-password".path}"; + }; }; }; }