From 5965d43eff75e7572d353e4f41b0c168bf858290 Mon Sep 17 00:00:00 2001 From: Luke Else Date: Thu, 20 Mar 2025 15:26:29 +0000 Subject: [PATCH] Added nix files --- flake.nix | 37 +++++++++++++++++++++++++++++++++++++ hosts/desktop.nix | 28 ++++++++++++++++++++++++++++ hosts/laptop.nix | 24 ++++++++++++++++++++++++ hosts/vm.nix | 32 ++++++++++++++++++++++++++++++++ install.sh | 23 +++++++++++++++++++++++ modules/common.nix | 35 +++++++++++++++++++++++++++++++++++ modules/hyprland.nix | 25 +++++++++++++++++++++++++ modules/networking.nix | 15 +++++++++++++++ modules/user.nix | 15 +++++++++++++++ 9 files changed, 234 insertions(+) create mode 100644 flake.nix create mode 100644 hosts/desktop.nix create mode 100644 hosts/laptop.nix create mode 100644 hosts/vm.nix create mode 100644 install.sh create mode 100644 modules/common.nix create mode 100644 modules/hyprland.nix create mode 100644 modules/networking.nix create mode 100644 modules/user.nix diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..d167cf5 --- /dev/null +++ b/flake.nix @@ -0,0 +1,37 @@ +outputs = { nixpkgs, home-manager, ... }: + let + system = "x86_64-linux"; + in { + nixosConfigurations = { + laptop = nixpkgs.lib.nixosSystem { + inherit system; + modules = [ + ./hosts/laptop.nix + ./modules/common.nix + ./modules/hyprland.nix + ./modules/networking.nix + ./modules/user.nix + ]; + }; + desktop = nixpkgs.lib.nixosSystem { + inherit system; + modules = [ + ./hosts/desktop.nix + ./modules/common.nix + ./modules/hyprland.nix + ./modules/networking.nix + ./modules/user.nix + ]; + }; + vm = nixpkgs.lib.nixosSystem { + inherit system; + modules = [ + ./hosts/vm.nix + ./modules/common.nix + ./modules/hyprland.nix + ./modules/networking.nix + ./modules/user.nix + ]; + }; + }; + }; diff --git a/hosts/desktop.nix b/hosts/desktop.nix new file mode 100644 index 0000000..3a5c991 --- /dev/null +++ b/hosts/desktop.nix @@ -0,0 +1,28 @@ +{ config, pkgs, ... }: + +{ + networking.hostName = "desktop"; + + # NVIDIA proprietary drivers + services.xserver.videoDrivers = [ "nvidia" ]; + + hardware.nvidia = { + modesetting.enable = true; + open = false; + nvidiaSettings = true; + }; + + boot.initrd.luks.devices = { + root = { + device = "/dev/sda2"; + preLVM = true; + }; + }; + + # Dual display configuration + services.xserver = { + screenSection = '' + Option "metamodes" "HDMI-0: 1920x1080 +0+0, DP-0: 1920x1080 +1920+0" + ''; + }; +} diff --git a/hosts/laptop.nix b/hosts/laptop.nix new file mode 100644 index 0000000..56eab20 --- /dev/null +++ b/hosts/laptop.nix @@ -0,0 +1,24 @@ +{ config, pkgs, ... }: + +{ + networking.hostName = "laptop"; + + # Intel VA-API for GPU acceleration + hardware.opengl = { + enable = true; + driSupport = true; + extraPackages = with pkgs; [ + intel-media-driver + libva-utils + ]; + }; + + boot.initrd.luks.devices = { + root = { + device = "/dev/sda2"; + preLVM = true; + }; + }; + + services.xserver.videoDrivers = [ "intel" ]; +} diff --git a/hosts/vm.nix b/hosts/vm.nix new file mode 100644 index 0000000..388f97e --- /dev/null +++ b/hosts/vm.nix @@ -0,0 +1,32 @@ +{ config, pkgs, ... }: + +{ + networking.hostName = "vm"; + + # Use DHCP for networking + networking.useDHCP = true; + + # Disk encryption setup + boot.initrd.luks.devices = { + root = { + device = "/dev/sda2"; + preLVM = true; + }; + }; + + # Hyprland setup without GPU acceleration + services.xserver.enable = true; + services.xserver.videoDrivers = [ ]; + + # Use the same package set as desktop/laptop + environment.systemPackages = with pkgs; [ + alacritty + brave + helix + rustc cargo + go + nodejs + discord + spotify + ]; +} diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..b042c71 --- /dev/null +++ b/install.sh @@ -0,0 +1,23 @@ +# Assuming /dev/sda is the target disk +parted /dev/sda -- mklabel gpt +parted /dev/sda -- mkpart primary ext4 1MiB 100% +mkfs.ext4 /dev/sda2 +mount /dev/sda2 /mnt + +cryptsetup luksFormat /dev/sda2 +cryptsetup open /dev/sda2 root +mkfs.ext4 /dev/mapper/root +mount /dev/mapper/root /mnt + +mkdir -p /mnt/etc/nixos +git clone https://git.luke-else.co.uk/luke-else/nixos-config.git /mnt/etc/nixos + +nixos-generate-config --root /mnt + +nixos-install --flake /mnt/etc/nixos#vm + +passwd + +reboot + +# sudo nixos-rebuild switch --flake ~/nixos-config#vm \ No newline at end of file diff --git a/modules/common.nix b/modules/common.nix new file mode 100644 index 0000000..2fc31f9 --- /dev/null +++ b/modules/common.nix @@ -0,0 +1,35 @@ +{ config, pkgs, ... }: + +{ + # Bootloader + boot.loader.grub = { + enable = true; + version = 2; + device = "nodev"; + efiSupport = true; + }; + + fileSystems."/" = { + device = "/dev/mapper/root"; + fsType = "ext4"; + }; + + swapDevices = [{ device = "/swapfile"; size = 4096; }]; + + # Locales and timezone + time.timeZone = "Europe/London"; + i18n.defaultLocale = "en_GB.UTF-8"; + + # UFW Firewall + networking.firewall = { + enable = true; + allowedTCPPorts = [ 22 ]; # Allow SSH + }; + + # Enable SSH + services.openssh = { + enable = true; + permitRootLogin = "no"; + passwordAuthentication = false; + }; +} diff --git a/modules/hyprland.nix b/modules/hyprland.nix new file mode 100644 index 0000000..df0dd94 --- /dev/null +++ b/modules/hyprland.nix @@ -0,0 +1,25 @@ +{ config, pkgs, ... }: + +{ + programs.hyprland = { + enable = true; + xwayland.enable = true; + }; + + services.displayManager = { + enable = true; + defaultSession = "hyprland"; + }; + + environment.systemPackages = with pkgs; [ + alacritty # Terminal + brave # Browser + helix # Text editor + rustc cargo # Rust + go # Go + nodejs # Node.js + discord + spotify + bitwarden + ]; +} diff --git a/modules/networking.nix b/modules/networking.nix new file mode 100644 index 0000000..20d0d5d --- /dev/null +++ b/modules/networking.nix @@ -0,0 +1,15 @@ +{ config, pkgs, ... }: + +{ + networking = { + wireless = { + enable = true; + networks = { + "your-SSID" = { + psk = "your-wifi-password"; + }; + }; + }; + dhcp = true; + }; +} diff --git a/modules/user.nix b/modules/user.nix new file mode 100644 index 0000000..2f7f8ac --- /dev/null +++ b/modules/user.nix @@ -0,0 +1,15 @@ +{ config, pkgs, ... }: + +{ + users.users."luke-else" = { + isNormalUser = true; + home = "/home/luke-else"; + shell = pkgs.bash; + extraGroups = [ "wheel" "networkmanager" "docker" ]; + }; + + security.sudo = { + enable = true; + wheelNeedsPassword = true; + }; +}