From b0eccdf7694628814e6eeb1b6e0d9d1006ed5170 Mon Sep 17 00:00:00 2001 From: Joshua Yuen Date: Sat, 26 Jul 2025 01:18:21 -0400 Subject: [PATCH] Added hyprland, zsh, sddm, and xdg --- configuration.nix | 32 ++-------------- flake.lock | 22 +++++++++++ flake.nix | 41 +++++++++++--------- hosts/vm/default.nix | 16 ++++++++ hosts/vm/hardware.nix | 3 ++ hosts/vm/host-packages.nix | 9 +++++ hosts/vm/variables.nix | 5 +++ modules/core/default.nix | 20 ++++++++++ modules/core/gdm.nix | 9 +++++ modules/core/hyprland.nix | 16 ++++++++ modules/core/packages.nix | 8 ++++ modules/core/sddm.nix | 12 ++++++ modules/core/system.nix | 14 +++++++ modules/core/user.nix | 38 ++++++++++++++++++ modules/drivers/default.nix | 8 ++++ modules/drivers/vm-guest-services.nix | 21 ++++++++++ modules/home/default.nix | 12 ++++++ modules/home/hyprland/binds.nix | 16 ++++++++ modules/home/hyprland/default.nix | 9 +++++ modules/home/hyprland/hyprland.nix | 49 ++++++++++++++++++++++++ modules/home/kitty.nix | 18 +++++++++ modules/home/xdg.nix | 26 +++++++++++++ modules/home/zsh/default.nix | 55 +++++++++++++++++++++++++++ modules/home/zsh/zshrc-personal.nix | 11 ++++++ modules/options/default.nix | 8 ++++ modules/options/hyprland.nix | 24 ++++++++++++ profiles/vm/default.nix | 22 +++++++++++ rebuild.sh | 2 + 28 files changed, 479 insertions(+), 47 deletions(-) create mode 100644 hosts/vm/default.nix create mode 100644 hosts/vm/hardware.nix create mode 100644 hosts/vm/host-packages.nix create mode 100644 hosts/vm/variables.nix create mode 100644 modules/core/default.nix create mode 100644 modules/core/gdm.nix create mode 100644 modules/core/hyprland.nix create mode 100644 modules/core/packages.nix create mode 100644 modules/core/sddm.nix create mode 100644 modules/core/system.nix create mode 100644 modules/core/user.nix create mode 100644 modules/drivers/default.nix create mode 100644 modules/drivers/vm-guest-services.nix create mode 100644 modules/home/default.nix create mode 100644 modules/home/hyprland/binds.nix create mode 100644 modules/home/hyprland/default.nix create mode 100644 modules/home/hyprland/hyprland.nix create mode 100644 modules/home/kitty.nix create mode 100644 modules/home/xdg.nix create mode 100644 modules/home/zsh/default.nix create mode 100644 modules/home/zsh/zshrc-personal.nix create mode 100644 modules/options/default.nix create mode 100644 modules/options/hyprland.nix create mode 100644 profiles/vm/default.nix diff --git a/configuration.nix b/configuration.nix index 2634d10..5a6d71a 100644 --- a/configuration.nix +++ b/configuration.nix @@ -3,30 +3,19 @@ # https://search.nixos.org/options and in the NixOS manual (`nixos-help`). { config, lib, pkgs, ... }: -let - nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/tarball/26d499fc9f1d567283d5d56fcf367edd815dba1d.tar.gz"; -in - { imports = [ # Include the results of the hardware scan. - # ./hardware-configuration.nix + ./hardware-configuration.nix ./hyprland.nix + ./modules/main-user.nix ]; # Use the systemd-boot EFI boot loader. boot.loader.systemd-boot.enable = true; boot.loader.efi.canTouchEfiVariables = true; - # Virtual machine options - # virtualisation.vmVariant = { - # virtualisation = { - # memorySize = 8192; - # cores = 8; - # }; - # }; - - networking.hostName = "nixos"; # Define your hostname. + # networking.hostName = "nixos"; # Define your hostname. # Pick only one of the below networking options. # networking.wireless.enable = true; # Enables wireless support via wpa_supplicant. # networking.networkmanager.enable = true; # Easiest to use and most distros use this by default. @@ -76,21 +65,6 @@ in # Enable touchpad support (enabled default in most desktopManager). # services.libinput.enable = true; - # Define a user account. Don't forget to set a password with ‘passwd’. - users.users.josh = { - isNormalUser = true; - initialPassword = "test"; - extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user. - packages = with pkgs; [ - cowsay - lolcat - htop - firefox - pciutils - vim - ]; - }; - # List packages installed in system profile. To search, run: # $ nix search wget # environment.systemPackages = with pkgs; [ diff --git a/flake.lock b/flake.lock index 06c0920..ae44d61 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,26 @@ { "nodes": { + "home-manager": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1753479839, + "narHash": "sha256-E/rPVh7vyPMJUFl2NAew+zibNGfVbANr8BP8nLRbLkQ=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "0b9bf983db4d064764084cd6748efb1ab8297d1e", + "type": "github" + }, + "original": { + "owner": "nix-community", + "ref": "release-25.05", + "repo": "home-manager", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1753345091, @@ -18,6 +39,7 @@ }, "root": { "inputs": { + "home-manager": "home-manager", "nixpkgs": "nixpkgs" } } diff --git a/flake.nix b/flake.nix index 37c992e..a9e0e07 100644 --- a/flake.nix +++ b/flake.nix @@ -1,34 +1,39 @@ { + description = "NixOS configuration"; + inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-25.05"; + home-manager.url = "github:nix-community/home-manager/release-25.05"; + home-manager.inputs.nixpkgs.follows = "nixpkgs"; }; - outputs = { self, nixpkgs, ... }: - let - system = "x86_64-linux"; - in - { - nixosConfigurations.nixos = nixpkgs.lib.nixosSystem { + outputs = { nixpkgs, home-manager, ... } @ inputs: let + system = "x86_64-linux"; + host = "vm"; + profile = "vm"; + username = "josh"; + in { + nixosConfigurations = { + nixos = nixpkgs.lib.nixosSystem { + inherit system; + specialArgs = { inherit inputs; }; modules = [ - { nix.settings.experimental-features = ["nix-command" "flakes"]; } ./configuration.nix ]; }; - nixosConfigurations.nixosvm = nixpkgs.lib.nixosSystem { + nixosvm = nixpkgs.lib.nixosSystem { inherit system; + specialArgs = { + inherit inputs; + inherit host; + inherit profile; + inherit username; + }; modules = [ - { - nix.settings.experimental-features = ["nix-command" "flakes"]; - virtualisation.vmVariant = { - virtualisation = { - memorySize = 8192; - cores = 8; - }; - }; - } - ./configuration.nix + ./hosts/${host} ]; }; }; + }; } \ No newline at end of file diff --git a/hosts/vm/default.nix b/hosts/vm/default.nix new file mode 100644 index 0000000..830a185 --- /dev/null +++ b/hosts/vm/default.nix @@ -0,0 +1,16 @@ +{ + profile, + ... +}: +{ + imports = [ + ../../profiles/${profile} + ../../modules/core + ../../modules/options + + ./hardware.nix + ./host-packages.nix + ]; + + modules.hyprland.enable = true; +} \ No newline at end of file diff --git a/hosts/vm/hardware.nix b/hosts/vm/hardware.nix new file mode 100644 index 0000000..077404a --- /dev/null +++ b/hosts/vm/hardware.nix @@ -0,0 +1,3 @@ +{ + +} \ No newline at end of file diff --git a/hosts/vm/host-packages.nix b/hosts/vm/host-packages.nix new file mode 100644 index 0000000..08293c5 --- /dev/null +++ b/hosts/vm/host-packages.nix @@ -0,0 +1,9 @@ +{ + pkgs, + ... +}: +{ + environment.systemPackages = with pkgs; [ + + ]; +} \ No newline at end of file diff --git a/hosts/vm/variables.nix b/hosts/vm/variables.nix new file mode 100644 index 0000000..0649c58 --- /dev/null +++ b/hosts/vm/variables.nix @@ -0,0 +1,5 @@ +{ + # Set Display Manager + # 'gdm', 'sddm' + displayManager = "sddm"; +} \ No newline at end of file diff --git a/modules/core/default.nix b/modules/core/default.nix new file mode 100644 index 0000000..4a69fbf --- /dev/null +++ b/modules/core/default.nix @@ -0,0 +1,20 @@ +{ + host, + ... +}: let + vars = import ../../hosts/${host}/variables.nix; +in { + imports = [ + ./hyprland.nix + ./packages.nix + ./system.nix + ./user.nix + ] + ++ ( + if vars.displayManager == "gdm" + then [ ./gdm.nix ] + else if vars.displayManager == "sddm" + then [ ./sddm.nix ] + else [] + ); +} \ No newline at end of file diff --git a/modules/core/gdm.nix b/modules/core/gdm.nix new file mode 100644 index 0000000..c697330 --- /dev/null +++ b/modules/core/gdm.nix @@ -0,0 +1,9 @@ +{ + ... +}: +{ + services.xserver.displayManager.gdm = { + enable = true; + wayland.enable = true; + }; +} \ No newline at end of file diff --git a/modules/core/hyprland.nix b/modules/core/hyprland.nix new file mode 100644 index 0000000..6a4fe3f --- /dev/null +++ b/modules/core/hyprland.nix @@ -0,0 +1,16 @@ +{ + config, + lib, + ... +}: +with lib; +let + cfg = config.modules.hyprland; +in +{ + config = mkIf cfg.enable { + programs.hyprland = { + enable = true; + }; + }; +} \ No newline at end of file diff --git a/modules/core/packages.nix b/modules/core/packages.nix new file mode 100644 index 0000000..425724f --- /dev/null +++ b/modules/core/packages.nix @@ -0,0 +1,8 @@ +{ + config, + pkgs, + ... +}: +{ + +} \ No newline at end of file diff --git a/modules/core/sddm.nix b/modules/core/sddm.nix new file mode 100644 index 0000000..5d8bdac --- /dev/null +++ b/modules/core/sddm.nix @@ -0,0 +1,12 @@ +{ + ... +}: +{ + services.displayManager.sddm = { + enable = true; + wayland.enable = true; + }; + + # To prevent getting stuck at shutdown + systemd.extraConfig = "DefaultTimeoutStopSec=10s"; +} \ No newline at end of file diff --git a/modules/core/system.nix b/modules/core/system.nix new file mode 100644 index 0000000..4630389 --- /dev/null +++ b/modules/core/system.nix @@ -0,0 +1,14 @@ +{ + ... +}: +{ + nix = { + settings = { + experimental-features = [ + "nix-command" + "flakes" + ]; + }; + }; + system.stateVersion = "25.05"; +} \ No newline at end of file diff --git a/modules/core/user.nix b/modules/core/user.nix new file mode 100644 index 0000000..1e7636e --- /dev/null +++ b/modules/core/user.nix @@ -0,0 +1,38 @@ +{ + host, + inputs, + pkgs, + profile, + username, + ... +}: +{ + imports = [ inputs.home-manager.nixosModules.home-manager ]; + home-manager = { + useUserPackages = true; + useGlobalPkgs = false; + backupFileExtension = "backup"; + extraSpecialArgs = { inherit host inputs profile username; }; + users.${username} = { + imports = [ ./../home ]; + home = { + username = "${username}"; + homeDirectory = "/home/${username}"; + stateVersion = "25.05"; + }; + }; + }; + + users.mutableUsers = true; + users.users.${username} = { + isNormalUser = true; + intialPassword = "changeme"; + extraGroups = [ + "wheel" + ]; + shell = pkgs.zsh; + ignoreShellProgramCheck = true; + }; + + nix.settings.allowed-users = [ "${username}" ]; +} \ No newline at end of file diff --git a/modules/drivers/default.nix b/modules/drivers/default.nix new file mode 100644 index 0000000..99fa3da --- /dev/null +++ b/modules/drivers/default.nix @@ -0,0 +1,8 @@ +{ + ... +}: +{ + imports = [ + ./vm-guest-services.nix + ]; +} \ No newline at end of file diff --git a/modules/drivers/vm-guest-services.nix b/modules/drivers/vm-guest-services.nix new file mode 100644 index 0000000..7525318 --- /dev/null +++ b/modules/drivers/vm-guest-services.nix @@ -0,0 +1,21 @@ +{ + config, + lib, + pkgs, + ... +}: +with lib; +let + cfg = config.vm.guest-services; +in +{ + options.vm.guest-services = { + enable = mkEnableOption "Enable Virtual Machine Guest Services"; + }; + + config = mkIf cfg.enable { + services.qemuGuest.enable = true; + services.spice-vdagentd.enable = true; + services.spice-webdavd.enable = true; + }; +} \ No newline at end of file diff --git a/modules/home/default.nix b/modules/home/default.nix new file mode 100644 index 0000000..6e708c2 --- /dev/null +++ b/modules/home/default.nix @@ -0,0 +1,12 @@ +{ + host, + ... +}: +{ + imports = [ + ./hyprland + ./kitty.nix + ./xdg.nix + ./zsh + ]; +} \ No newline at end of file diff --git a/modules/home/hyprland/binds.nix b/modules/home/hyprland/binds.nix new file mode 100644 index 0000000..237eb26 --- /dev/null +++ b/modules/home/hyprland/binds.nix @@ -0,0 +1,16 @@ +{ + lib, + osConfig, + ... +}: +with lib; +let + cfg = osConfig.modules.hyprland; +in +{ + wayland.windowManager.hyprland.settings = { + bind = [ + "$modifier,Return,exec,${cfg.terminal}" + ]; + }; +} \ No newline at end of file diff --git a/modules/home/hyprland/default.nix b/modules/home/hyprland/default.nix new file mode 100644 index 0000000..d1048a3 --- /dev/null +++ b/modules/home/hyprland/default.nix @@ -0,0 +1,9 @@ +{ + ... +}: +{ + imports = [ + ./binds.nix + ./hyprland.nix + ]; +} \ No newline at end of file diff --git a/modules/home/hyprland/hyprland.nix b/modules/home/hyprland/hyprland.nix new file mode 100644 index 0000000..224b1eb --- /dev/null +++ b/modules/home/hyprland/hyprland.nix @@ -0,0 +1,49 @@ +{ + config, + host, + lib, + osConfig, + pkgs, + ... +}: +with lib; +let + cfg = osConfig.modules.hyprland; +in +{ + config = mkIf cfg.enable { + home.packages = with pkgs; [ + kitty + ]; + + systemd.user.targets.hyprland-session.Unit.Wants = [ + "xdg-desktop-autostart.target" + ]; + + wayland.windowManager.hyprland = { + enable = true; + package = pkgs.hyprland; + systemd = { + enable = true; + enableXdgAutostart = true; + }; + xwayland.enable = true; + settings = { + general = { + "$modifier" = "SUPER"; + }; + + env = [ + "NIXOS_OZONE_WL, 1" + "XDG_CURRENT_DESKTOP, Hyprland" + "XDG_SESSION_DESKTOP, Hyprland" + "XDG_SESSION_TYPE, wayland" + ]; + + ecosystem = { + no_update_news = true; + }; + }; + }; + }; +} \ No newline at end of file diff --git a/modules/home/kitty.nix b/modules/home/kitty.nix new file mode 100644 index 0000000..493258b --- /dev/null +++ b/modules/home/kitty.nix @@ -0,0 +1,18 @@ +{ + lib, + osConfig, + pkgs, + ... +}: +with lib; +let + cfg = osConfig.modules.hyprland; +in +{ + config = mkIf (cfg.terminal == "kitty") { + programs.kitty = { + enable = true; + package = pkgs.kitty; + }; + }; +} \ No newline at end of file diff --git a/modules/home/xdg.nix b/modules/home/xdg.nix new file mode 100644 index 0000000..3b90d50 --- /dev/null +++ b/modules/home/xdg.nix @@ -0,0 +1,26 @@ +{ + lib, + osConfig, + pkgs, + ... +}: +with lib; +let + hyprlandCfg = osConfig.modules.hyprland; +in +{ + xdg = { + enable = true; + mime.enable = true; + mimeApps.enable = true; + portal = { + enable = true; + extraPortals = mkIf hyprlandCfg.enable [ + pkgs.xdg-desktop-portal-hyprland + ]; + configPackages = mkIf hyprlandCfg.enable [ + pkgs.hyprland + ]; + }; + }; +} \ No newline at end of file diff --git a/modules/home/zsh/default.nix b/modules/home/zsh/default.nix new file mode 100644 index 0000000..b58f5dd --- /dev/null +++ b/modules/home/zsh/default.nix @@ -0,0 +1,55 @@ +{ + config, + lib, + pkgs, + profile, + ... +}: +{ + imports = [ + ./zshrc-personal.nix + ]; + + programs.zsh = { + enable = true; + autosuggestion.enable = true; + syntaxHighlighting = { + enable = true; + highlighters = [ + "main" + "brackets" + "pattern" + "root" + ]; + }; + historySubstringSearch.enable = true; + + history = { + ignoreDups = false; + save = 100000; + size = 100000; + }; + + initContent = '' + # vi keybindings for menu select + bindkey -M menuselect 'h' vi-backward-char + bindkey -M menuselect 'k' vi-up-line-or-history + bindkey -M menuselect 'j' vi-down-line-or-history + bindkey -M menuselect 'l' vi-forward-char + + # Tab to accept current selection + bind-key -M menuselect '^I' accept-and-infer-next-history + ''; + + shellAliases = { + ".. " = "cd .."; + "..." = "cd../.."; + ls = "ls --color=auto"; + ll = "ls -al"; + grep = "grep --color=auto"; + back = "cd $OLDPWD"; + gs = "git status"; + ssha = "eval $(ssh-agent) && ssh-add"; + }; + }; +} \ No newline at end of file diff --git a/modules/home/zsh/zshrc-personal.nix b/modules/home/zsh/zshrc-personal.nix new file mode 100644 index 0000000..bee5a8b --- /dev/null +++ b/modules/home/zsh/zshrc-personal.nix @@ -0,0 +1,11 @@ +{ + pkgs, + ... +}: +{ + home.packages = with pkgs; [zsh]; + + home.file."./.zshrc-personal".text = '' + export EDITOR=vim + ''; +} \ No newline at end of file diff --git a/modules/options/default.nix b/modules/options/default.nix new file mode 100644 index 0000000..86cd777 --- /dev/null +++ b/modules/options/default.nix @@ -0,0 +1,8 @@ +{ + ... +}: +{ + imports = [ + ./hyprland.nix + ]; +} \ No newline at end of file diff --git a/modules/options/hyprland.nix b/modules/options/hyprland.nix new file mode 100644 index 0000000..1ddcb43 --- /dev/null +++ b/modules/options/hyprland.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + ... +}: +with lib; +let + cfg = config.modules.hyprland; +in +{ + options.modules.hyprland = { + enable = mkEnableOption "Enable Hyprland"; + terminal = mkOption { + type = types.enum [ + "kitty" + "alacritty" + ]; + default = "kitty"; + description = '' + The terminal to use for Hyprland. + ''; + }; + }; +} \ No newline at end of file diff --git a/profiles/vm/default.nix b/profiles/vm/default.nix new file mode 100644 index 0000000..197a4ab --- /dev/null +++ b/profiles/vm/default.nix @@ -0,0 +1,22 @@ +{ + vm, + ... +}: +{ + imports = [ + ../../modules/drivers + ]; + + virtualisation.vmVariant = { + virtualisation = { + memorySize = 8192; + cores = 8; + }; + }; + + # drivers.amdgpu.enable = false; + # drivers.nvidia.enable = false; + # drivers.nvidia-prime.enable = false; + # drivers.intel.enable = false; + vm.guest-services.enable = true; +} \ No newline at end of file diff --git a/rebuild.sh b/rebuild.sh index b45dec9..68801ac 100755 --- a/rebuild.sh +++ b/rebuild.sh @@ -1,5 +1,7 @@ echo "Removing old qcow2 disk ..." rm -f ./nixos.qcow2 + echo "Building new VM ..." nix build .#nixosConfigurations.nixosvm.config.system.build.vm + echo "Done!"