diff --git a/home-manager/dotfiles/bottom/bottom.toml b/dotfiles/bottom/bottom.toml similarity index 100% rename from home-manager/dotfiles/bottom/bottom.toml rename to dotfiles/bottom/bottom.toml diff --git a/home-manager/dotfiles/hypr/hypridle.conf b/dotfiles/hypr/hypridle.conf similarity index 100% rename from home-manager/dotfiles/hypr/hypridle.conf rename to dotfiles/hypr/hypridle.conf diff --git a/home-manager/dotfiles/hypr/hyprland.conf b/dotfiles/hypr/hyprland.conf similarity index 100% rename from home-manager/dotfiles/hypr/hyprland.conf rename to dotfiles/hypr/hyprland.conf diff --git a/home-manager/dotfiles/hypr/hyprlock.conf b/dotfiles/hypr/hyprlock.conf similarity index 100% rename from home-manager/dotfiles/hypr/hyprlock.conf rename to dotfiles/hypr/hyprlock.conf diff --git a/home-manager/dotfiles/mako/config b/dotfiles/mako/config similarity index 100% rename from home-manager/dotfiles/mako/config rename to dotfiles/mako/config diff --git a/home-manager/dotfiles/nvim/.stylua.toml b/dotfiles/nvim/.stylua.toml similarity index 100% rename from home-manager/dotfiles/nvim/.stylua.toml rename to dotfiles/nvim/.stylua.toml diff --git a/home-manager/dotfiles/nvim/LICENSE b/dotfiles/nvim/LICENSE similarity index 100% rename from home-manager/dotfiles/nvim/LICENSE rename to dotfiles/nvim/LICENSE diff --git a/home-manager/dotfiles/nvim/init.lua b/dotfiles/nvim/init.lua similarity index 100% rename from home-manager/dotfiles/nvim/init.lua rename to dotfiles/nvim/init.lua diff --git a/home-manager/dotfiles/nvim/lazy-lock.json b/dotfiles/nvim/lazy-lock.json similarity index 100% rename from home-manager/dotfiles/nvim/lazy-lock.json rename to dotfiles/nvim/lazy-lock.json diff --git a/home-manager/dotfiles/nvim/lua/core/bootstrap.lua b/dotfiles/nvim/lua/core/bootstrap.lua similarity index 100% rename from home-manager/dotfiles/nvim/lua/core/bootstrap.lua rename to dotfiles/nvim/lua/core/bootstrap.lua diff --git a/home-manager/dotfiles/nvim/lua/core/default_config.lua b/dotfiles/nvim/lua/core/default_config.lua similarity index 100% rename from home-manager/dotfiles/nvim/lua/core/default_config.lua rename to dotfiles/nvim/lua/core/default_config.lua diff --git a/home-manager/dotfiles/nvim/lua/core/init.lua b/dotfiles/nvim/lua/core/init.lua similarity index 100% rename from home-manager/dotfiles/nvim/lua/core/init.lua rename to dotfiles/nvim/lua/core/init.lua diff --git a/home-manager/dotfiles/nvim/lua/core/mappings.lua b/dotfiles/nvim/lua/core/mappings.lua similarity index 100% rename from home-manager/dotfiles/nvim/lua/core/mappings.lua rename to dotfiles/nvim/lua/core/mappings.lua diff --git a/home-manager/dotfiles/nvim/lua/core/utils.lua b/dotfiles/nvim/lua/core/utils.lua similarity index 100% rename from home-manager/dotfiles/nvim/lua/core/utils.lua rename to dotfiles/nvim/lua/core/utils.lua diff --git a/home-manager/dotfiles/nvim/lua/custom/chadrc.lua b/dotfiles/nvim/lua/custom/chadrc.lua similarity index 100% rename from home-manager/dotfiles/nvim/lua/custom/chadrc.lua rename to dotfiles/nvim/lua/custom/chadrc.lua diff --git a/home-manager/dotfiles/nvim/lua/custom/configs/dap.lua b/dotfiles/nvim/lua/custom/configs/dap.lua similarity index 100% rename from home-manager/dotfiles/nvim/lua/custom/configs/dap.lua rename to dotfiles/nvim/lua/custom/configs/dap.lua diff --git a/home-manager/dotfiles/nvim/lua/custom/configs/formatter.lua b/dotfiles/nvim/lua/custom/configs/formatter.lua similarity index 100% rename from home-manager/dotfiles/nvim/lua/custom/configs/formatter.lua rename to dotfiles/nvim/lua/custom/configs/formatter.lua diff --git a/home-manager/dotfiles/nvim/lua/custom/configs/lspconfig.lua b/dotfiles/nvim/lua/custom/configs/lspconfig.lua similarity index 100% rename from home-manager/dotfiles/nvim/lua/custom/configs/lspconfig.lua rename to dotfiles/nvim/lua/custom/configs/lspconfig.lua diff --git a/home-manager/dotfiles/nvim/lua/custom/configs/null-ls.lua b/dotfiles/nvim/lua/custom/configs/null-ls.lua similarity index 100% rename from home-manager/dotfiles/nvim/lua/custom/configs/null-ls.lua rename to dotfiles/nvim/lua/custom/configs/null-ls.lua diff --git a/home-manager/dotfiles/nvim/lua/custom/init.lua b/dotfiles/nvim/lua/custom/init.lua similarity index 100% rename from home-manager/dotfiles/nvim/lua/custom/init.lua rename to dotfiles/nvim/lua/custom/init.lua diff --git a/home-manager/dotfiles/nvim/lua/custom/mappings.lua b/dotfiles/nvim/lua/custom/mappings.lua similarity index 100% rename from home-manager/dotfiles/nvim/lua/custom/mappings.lua rename to dotfiles/nvim/lua/custom/mappings.lua diff --git a/home-manager/dotfiles/nvim/lua/custom/plugins.lua b/dotfiles/nvim/lua/custom/plugins.lua similarity index 100% rename from home-manager/dotfiles/nvim/lua/custom/plugins.lua rename to dotfiles/nvim/lua/custom/plugins.lua diff --git a/home-manager/dotfiles/nvim/lua/plugins/configs/cmp.lua b/dotfiles/nvim/lua/plugins/configs/cmp.lua similarity index 100% rename from home-manager/dotfiles/nvim/lua/plugins/configs/cmp.lua rename to dotfiles/nvim/lua/plugins/configs/cmp.lua diff --git a/home-manager/dotfiles/nvim/lua/plugins/configs/lazy_nvim.lua b/dotfiles/nvim/lua/plugins/configs/lazy_nvim.lua similarity index 100% rename from home-manager/dotfiles/nvim/lua/plugins/configs/lazy_nvim.lua rename to dotfiles/nvim/lua/plugins/configs/lazy_nvim.lua diff --git a/home-manager/dotfiles/nvim/lua/plugins/configs/lspconfig.lua b/dotfiles/nvim/lua/plugins/configs/lspconfig.lua similarity index 100% rename from home-manager/dotfiles/nvim/lua/plugins/configs/lspconfig.lua rename to dotfiles/nvim/lua/plugins/configs/lspconfig.lua diff --git a/home-manager/dotfiles/nvim/lua/plugins/configs/mason.lua b/dotfiles/nvim/lua/plugins/configs/mason.lua similarity index 100% rename from home-manager/dotfiles/nvim/lua/plugins/configs/mason.lua rename to dotfiles/nvim/lua/plugins/configs/mason.lua diff --git a/home-manager/dotfiles/nvim/lua/plugins/configs/nvimtree.lua b/dotfiles/nvim/lua/plugins/configs/nvimtree.lua similarity index 100% rename from home-manager/dotfiles/nvim/lua/plugins/configs/nvimtree.lua rename to dotfiles/nvim/lua/plugins/configs/nvimtree.lua diff --git a/home-manager/dotfiles/nvim/lua/plugins/configs/others.lua b/dotfiles/nvim/lua/plugins/configs/others.lua similarity index 100% rename from home-manager/dotfiles/nvim/lua/plugins/configs/others.lua rename to dotfiles/nvim/lua/plugins/configs/others.lua diff --git a/home-manager/dotfiles/nvim/lua/plugins/configs/telescope.lua b/dotfiles/nvim/lua/plugins/configs/telescope.lua similarity index 100% rename from home-manager/dotfiles/nvim/lua/plugins/configs/telescope.lua rename to dotfiles/nvim/lua/plugins/configs/telescope.lua diff --git a/home-manager/dotfiles/nvim/lua/plugins/configs/treesitter.lua b/dotfiles/nvim/lua/plugins/configs/treesitter.lua similarity index 100% rename from home-manager/dotfiles/nvim/lua/plugins/configs/treesitter.lua rename to dotfiles/nvim/lua/plugins/configs/treesitter.lua diff --git a/home-manager/dotfiles/nvim/lua/plugins/init.lua b/dotfiles/nvim/lua/plugins/init.lua similarity index 100% rename from home-manager/dotfiles/nvim/lua/plugins/init.lua rename to dotfiles/nvim/lua/plugins/init.lua diff --git a/home-manager/dotfiles/tmux/tmux.conf b/dotfiles/tmux/tmux.conf similarity index 100% rename from home-manager/dotfiles/tmux/tmux.conf rename to dotfiles/tmux/tmux.conf diff --git a/home-manager/dotfiles/waybar/config.jsonc b/dotfiles/waybar/config.jsonc similarity index 100% rename from home-manager/dotfiles/waybar/config.jsonc rename to dotfiles/waybar/config.jsonc diff --git a/home-manager/dotfiles/waybar/mocha.css b/dotfiles/waybar/mocha.css similarity index 100% rename from home-manager/dotfiles/waybar/mocha.css rename to dotfiles/waybar/mocha.css diff --git a/home-manager/dotfiles/waybar/style.css b/dotfiles/waybar/style.css similarity index 100% rename from home-manager/dotfiles/waybar/style.css rename to dotfiles/waybar/style.css diff --git a/home-manager/dotfiles/wofi/style.css b/dotfiles/wofi/style.css similarity index 100% rename from home-manager/dotfiles/wofi/style.css rename to dotfiles/wofi/style.css diff --git a/flake.lock b/flake.lock index b929dae..7086e77 100644 --- a/flake.lock +++ b/flake.lock @@ -490,16 +490,15 @@ }, "nixos-hardware": { "locked": { - "lastModified": 1738638143, - "narHash": "sha256-ZYMe4c4OCtIUBn5hx15PEGr0+B1cNEpl2dsaLxwY2W0=", + "lastModified": 1738816619, + "narHash": "sha256-5yRlg48XmpcX5b5HesdGMOte+YuCy9rzQkJz+imcu6I=", "owner": "NixOS", "repo": "nixos-hardware", - "rev": "9bdd53f5908453e4d03f395eb1615c3e9a351f70", + "rev": "2eccff41bab80839b1d25b303b53d339fbb07087", "type": "github" }, "original": { "owner": "NixOS", - "ref": "master", "repo": "nixos-hardware", "type": "github" } diff --git a/flake.nix b/flake.nix index 9466fd5..5c2294f 100644 --- a/flake.nix +++ b/flake.nix @@ -13,7 +13,7 @@ hyprland.url = "github:hyprwm/Hyprland"; # NixOS community managed hardware specific features/fixes - nixos-hardware.url = "github:NixOS/nixos-hardware/master"; + nixos-hardware.url = "github:NixOS/nixos-hardware"; # Secure boot lanzaboote = { @@ -41,37 +41,47 @@ }; outputs = {nixpkgs, ...} @ inputs: let - system = "x86_64-linux"; - hostName = "rihla"; - pkgs = nixpkgs.legacyPackages.${system}; - in { - nixosConfigurations = { - "${hostName}" = nixpkgs.lib.nixosSystem { - inherit system; - modules = [ - inputs.lanzaboote.nixosModules.lanzaboote - inputs.disko.nixosModules.disko - inputs.nixos-hardware.nixosModules.framework-13-7040-amd - inputs.sops-nix.nixosModules.sops - inputs.home-manager.nixosModules.home-manager - ./nixos/configuration.nix - ./nixos/disko-config.nix - ./nixos/hardware-configuration.nix - { - home-manager = { - sharedModules = [ - ./modules/home-manager/yubikey-touch-detector.nix - ]; - }; - } - ]; + inherit (nixpkgs) lib; + mkHost = host: { + ${host} = nixpkgs.lib.nixosSystem { specialArgs = { - inherit inputs hostName; + inherit inputs; + + # Extend lib with lib.custom + lib = nixpkgs.lib.extend (self: super: { custom = import ./lib { inherit (nixpkgs) lib; }; }); }; + + modules = [ ./hosts/nixos/${host} ]; }; }; + mkHostConfigs = hosts: lib.foldl (acc: set: acc // set) { } (lib.map (host: mkHost host) hosts); + readHosts = folder: lib.attrNames (builtins.readDir ./hosts/${folder}); + in { + nixosConfigurations = mkHostConfigs (readHosts "nixos"); - devShell.x86_64-linux = pkgs.mkShell { + # nixosConfigurations = { + # rihla = nixpkgs.lib.nixosSystem { + # system = "x86_64-linux"; + # modules = [ + # inputs.lanzaboote.nixosModules.lanzaboote + # inputs.disko.nixosModules.disko + # inputs.nixos-hardware.nixosModules.framework-13-7040-amd + # inputs.sops-nix.nixosModules.sops + # inputs.home-manager.nixosModules.home-manager + # ./nixos/configuration.nix + # ./nixos/disko-config.nix + # ./nixos/hardware-configuration.nix + # ]; + # specialArgs = { + # inherit inputs; + # hostName = "rihla"; + # }; + # }; + # }; + + devShell.x86_64-linux = let + pkgs = nixpkgs.legacyPackages.x86_64-linux; + in pkgs.mkShell { buildInputs = with pkgs; [ nil alejandra diff --git a/home-manager/home.nix b/home-manager/home.nix deleted file mode 100644 index deaa3e9..0000000 --- a/home-manager/home.nix +++ /dev/null @@ -1,131 +0,0 @@ -# This is your home-manager configuration file -# Use this to configure your home environment (it replaces ~/.config/nixpkgs/home.nix) -{ - lib, - config, - pkgs, - ... -}: let - # Be sure to actually install the font first! - font = "ComicCodeLigatures"; - username = "shahab"; - email = "${username}@dogar.dev"; - fullName = "Shahab Dogar"; -in { - # You can import other home-manager modules here - imports = [ - # Custom import to configure font - (import ./configs/alacritty.nix { - inherit pkgs config font; - }) - - # Custom import for username and email - (import ./configs/git.nix { - inherit pkgs config lib; - userEmail = email; - userName = fullName; - }) - - ./configs/firefox.nix - ./configs/direnv.nix - ./configs/ssh.nix - ./configs/nvim.nix - ./configs/starship.nix - ./configs/zsh.nix - ./configs/btop.nix - ]; - - nixpkgs = { - # Configure your nixpkgs instance - config = { - # Disable if you don't want unfree packages - allowUnfree = true; - - # Workaround for https://github.com/nix-community/home-manager/issues/2942 - allowUnfreePredicate = _: true; - }; - }; - - fonts = { - fontconfig.enable = true; - }; - - home = { - inherit username; - - # https://nixos.wiki/wiki/FAQ/When_do_I_update_stateVersion - stateVersion = "24.05"; - homeDirectory = "/home/${username}"; - sessionVariables = { - EDITOR = "nvim"; - NIXOS_OZONE_WL = "1"; - }; - - file = { - "${config.xdg.configHome}/tmux".source = ./dotfiles/tmux; - "${config.xdg.configHome}/bottom".source = ./dotfiles/bottom; - "${config.xdg.configHome}/nvim".source = ./dotfiles/nvim; - "${config.xdg.configHome}/hypr".source = ./dotfiles/hypr; - "${config.xdg.configHome}/waybar".source = ./dotfiles/waybar; - "${config.xdg.configHome}/wofi".source = ./dotfiles/wofi; - "${config.xdg.configHome}/mako".source = ./dotfiles/mako; - }; - - packages = with pkgs; [ - nh - bottom - lazygit - neofetch - discord - eza - ripgrep - rm-improved - dust - gh - zoxide - xcp - unzip - prismlauncher - tmux - lazygit - gcc - zig - protonmail-desktop - protonvpn-gui - cloudflare-warp - kubectl - gparted - k9s - gnupg - postgresql_17 - dig - bash - kitty - wofi - dolphin - waybar - font-awesome - mako - hyprshot - hyprlock - hypridle - hyprpolkitagent - pavucontrol - tree - wl-clipboard-rs - brightnessctl - age - nerd-fonts.jetbrains-mono - obsidian - ]; - }; - - # Enable home-manager - programs.home-manager.enable = true; - - # Add service to monitor yubikey requirement - services.yubikey-touch-detector.enable = true; - - # Nicely reload system units when changing configs - systemd.user.startServices = "sd-switch"; -} diff --git a/home-manager/configs/alacritty.nix b/home/shahab/common/core/alacritty.nix similarity index 78% rename from home-manager/configs/alacritty.nix rename to home/shahab/common/core/alacritty.nix index ce0145d..83b15fc 100644 --- a/home-manager/configs/alacritty.nix +++ b/home/shahab/common/core/alacritty.nix @@ -1,4 +1,9 @@ -{font, ...}: { +{ + config, + ... +}: + +{ programs.alacritty = { enable = true; @@ -24,9 +29,9 @@ font = { size = 14; - normal.family = font; - bold.family = font; - italic.family = font; + normal.family = config.hostSpec.font; + bold.family = config.hostSpec.font; + italic.family = config.hostSpec.font; }; cursor = { diff --git a/home/shahab/common/core/default.nix b/home/shahab/common/core/default.nix new file mode 100644 index 0000000..647ab49 --- /dev/null +++ b/home/shahab/common/core/default.nix @@ -0,0 +1,96 @@ +{ + config, + lib, + pkgs, + hostSpec, + ... +}: +{ + imports = lib.flatten [ + (map lib.custom.relativeToRoot [ + "modules/common" + "modules/home-manager" + ]) + + ./alacritty.nix + ./direnv.nix + ./git.nix + ./fonts.nix + ]; + + inherit hostSpec; + + home = { + username = lib.mkDefault config.hostSpec.username; + homeDirectory = lib.mkDefault config.hostSpec.home; + stateVersion = lib.mkDefault "25.05"; + sessionPath = [ + "$HOME/.local/bin" + ]; + sessionVariables = { + FLAKE = "$HOME/src/nix/nix-config"; + SHELL = "zsh"; + TERM = "alacritty"; + TERMINAL = "alacritty"; + VISUAL = "nvim"; + EDITOR = "nvim"; + }; + + file = { + "${config.xdg.configHome}/nvim".source = lib.custom.relativeToRoot "dotfiles/nvim"; + }; + }; + + home.packages = with pkgs; [ + bottom + lazygit + discord + eza + ripgrep + rm-improved + dust + gh + zoxide + xcp + unzip + prismlauncher + tmux + lazygit + gcc + zig + protonmail-desktop + protonvpn-gui + cloudflare-warp + kubectl + gparted + k9s + gnupg + postgresql_17 + dig + bash + dolphin + font-awesome + tree + wl-clipboard-rs + brightnessctl + age + nerd-fonts.jetbrains-mono + obsidian + ]; + + nix = { + package = lib.mkDefault pkgs.nix; + settings = { + experimental-features = [ + "nix-command" + "flakes" + ]; + warn-dirty = false; + }; + }; + + programs.home-manager.enable = true; + + # Nicely reload system units when changing configs + systemd.user.startServices = "sd-switch"; +} diff --git a/home-manager/configs/direnv.nix b/home/shahab/common/core/direnv.nix similarity index 94% rename from home-manager/configs/direnv.nix rename to home/shahab/common/core/direnv.nix index 1d7196f..7c26805 100644 --- a/home-manager/configs/direnv.nix +++ b/home/shahab/common/core/direnv.nix @@ -1,8 +1,8 @@ -{...}: { +{ programs.direnv = { enable = true; - enableZshIntegration = true; enableBashIntegration = true; + enableZshIntegration = true; nix-direnv.enable = true; }; } diff --git a/home/shahab/common/core/fonts.nix b/home/shahab/common/core/fonts.nix new file mode 100644 index 0000000..ae8e811 --- /dev/null +++ b/home/shahab/common/core/fonts.nix @@ -0,0 +1,7 @@ +{ pkgs, ... }: +{ + fonts.fontconfig.enable = true; + home.packages = with pkgs; [ + nerd-fonts.jetbrains-mono + ]; +} diff --git a/home-manager/configs/git.nix b/home/shahab/common/core/git.nix similarity index 76% rename from home-manager/configs/git.nix rename to home/shahab/common/core/git.nix index 301faba..bebf3ac 100644 --- a/home-manager/configs/git.nix +++ b/home/shahab/common/core/git.nix @@ -1,15 +1,14 @@ { lib, pkgs, - userName, - userEmail, + config, ... }: { programs.git = { package = pkgs.gitAndTools.gitFull; enable = true; - userName = userName; - userEmail = userEmail; + userName = config.hostSpec.userFullName; + userEmail = config.hostSpec.email.user; extraConfig = { gpg = { @@ -22,7 +21,7 @@ gpgsign = true; }; user = { - signingKey = "~/.ssh/id_ed25519.pub"; + signingKey = "~/.ssh/id_rihla.pub"; }; pull = { rebase = true; diff --git a/home-manager/configs/btop.nix b/home/shahab/common/optional/btop.nix similarity index 100% rename from home-manager/configs/btop.nix rename to home/shahab/common/optional/btop.nix diff --git a/home-manager/configs/firefox.nix b/home/shahab/common/optional/firefox.nix similarity index 100% rename from home-manager/configs/firefox.nix rename to home/shahab/common/optional/firefox.nix diff --git a/home/shahab/common/optional/hyprland.nix b/home/shahab/common/optional/hyprland.nix new file mode 100644 index 0000000..704eb32 --- /dev/null +++ b/home/shahab/common/optional/hyprland.nix @@ -0,0 +1,27 @@ +{ + config, + lib, + pkgs, + ... +}: + +{ + home = { + file = { + "${config.xdg.configHome}/hypr".source = lib.custom.relativeToRoot "dotfiles/hypr"; + "${config.xdg.configHome}/waybar".source = lib.custom.relativeToRoot "dotfiles/waybar"; + "${config.xdg.configHome}/wofi".source = lib.custom.relativeToRoot "dotfiles/wofi"; + "${config.xdg.configHome}/mako".source = lib.custom.relativeToRoot "dotfiles/mako"; + }; + + packages = with pkgs; [ + hyprshot + hyprlock + hypridle + hyprpolkitagent + waybar + wofi + mako + ]; + }; +} diff --git a/home/shahab/common/optional/misc-packages.nix b/home/shahab/common/optional/misc-packages.nix new file mode 100644 index 0000000..04c64b0 --- /dev/null +++ b/home/shahab/common/optional/misc-packages.nix @@ -0,0 +1,43 @@ +{ + pkgs, + ... +}: + +{ + home.packages = with pkgs; [ + nh + bottom + discord + eza + ripgrep + rm-improved + dust + gh + zoxide + xcp + unzip + prismlauncher + lazygit + gcc + zig + protonmail-desktop + protonvpn-gui + cloudflare-warp + kubectl + gparted + k9s + gnupg + postgresql_17 + dig + bash + kitty + dolphin + waybar + font-awesome + tree + wl-clipboard-rs + brightnessctl + age + obsidian + ]; +} diff --git a/home-manager/configs/nvim.nix b/home/shahab/common/optional/nvim.nix similarity index 89% rename from home-manager/configs/nvim.nix rename to home/shahab/common/optional/nvim.nix index bf374b2..9ba7b94 100644 --- a/home-manager/configs/nvim.nix +++ b/home/shahab/common/optional/nvim.nix @@ -1,4 +1,8 @@ -{...}: { +{ + ... +}: + +{ programs.neovim = { enable = true; defaultEditor = true; diff --git a/home-manager/configs/ssh.nix b/home/shahab/common/optional/ssh.nix similarity index 100% rename from home-manager/configs/ssh.nix rename to home/shahab/common/optional/ssh.nix diff --git a/home-manager/configs/starship.nix b/home/shahab/common/optional/starship.nix similarity index 100% rename from home-manager/configs/starship.nix rename to home/shahab/common/optional/starship.nix diff --git a/home/shahab/common/optional/tmux.nix b/home/shahab/common/optional/tmux.nix new file mode 100644 index 0000000..05fd705 --- /dev/null +++ b/home/shahab/common/optional/tmux.nix @@ -0,0 +1,18 @@ +{ + config, + lib, + pkgs, + ... +}: + +{ + home = { + file = { + "${config.xdg.configHome}/tmux".source = lib.custom.relativeToRoot "dotfiles/tmux"; + }; + + packages = with pkgs; [ + tmux + ]; + }; +} diff --git a/home-manager/configs/zsh.nix b/home/shahab/common/optional/zsh.nix similarity index 100% rename from home-manager/configs/zsh.nix rename to home/shahab/common/optional/zsh.nix diff --git a/home/shahab/rihla.nix b/home/shahab/rihla.nix new file mode 100644 index 0000000..a54370b --- /dev/null +++ b/home/shahab/rihla.nix @@ -0,0 +1,38 @@ +{ + lib, + ... +}: +{ + imports = lib.flatten [ + # + # ========== Required Configs ========== + # + ./common/core + + # + # ========== Host-specific Optional Configs ========== + # + (map (config: "${builtins.toString ./.}/common/optional/${config}.nix") [ + "hyprland" + "starship" + "ssh" + "zsh" + "btop" + "firefox" + "nvim" + "tmux" + "misc-packages" + ]) + ]; + + services.yubikey-touch-detector.enable = true; + + home = { + # https://nixos.wiki/wiki/FAQ/When_do_I_update_stateVersion + stateVersion = "25.05"; + sessionVariables = { + EDITOR = "nvim"; + NIXOS_OZONE_WL = "1"; + }; + }; +} diff --git a/hosts/common/core/default.nix b/hosts/common/core/default.nix new file mode 100644 index 0000000..c842598 --- /dev/null +++ b/hosts/common/core/default.nix @@ -0,0 +1,102 @@ +{ + pkgs, + inputs, + config, + lib, + ... +}: + +{ + imports = lib.flatten [ + inputs.home-manager.nixosModules.home-manager + inputs.sops-nix.nixosModules.sops + + (map lib.custom.relativeToRoot [ + "modules/common" + "hosts/common/users/primary" + ]) + ]; + + hostSpec = { + username = "shahab"; + handle = "shahab96"; + email = { + user = "shahab@dogar.dev"; + }; + userFullName = "Shahab Dogar"; + domain = "rihla"; + networking.ports.tcp.ssh = 22; + }; + + networking.hostName = config.hostSpec.hostName; + + home-manager = { + useGlobalPkgs = true; + backupFileExtension = "bk"; + }; + + # + # ========= Overlays ========= + # + nixpkgs = { + config = { + allowUnfree = true; + allowUnfreePredicate = _: true; + }; + }; + + # + # ========= Nix Settings ========= + # + nix = { + settings = { + # See https://jackson.dev/post/nix-reasonable-defaults/ + connect-timeout = 5; + log-lines = 25; + min-free = 128000000; # 128MB + max-free = 1000000000; # 1GB + + auto-optimise-store = true; + warn-dirty = false; + trusted-users = [ "@wheel" ]; + + substituters = ["https://hyprland.cachix.org"]; + trusted-public-keys = ["hyprland.cachix.org-1:a7pgxzMz7+chwVL3/pzj6jIBMioiJM7ypFP8PwtkuGc="]; + experimental-features = [ + "nix-command" + "flakes" + ]; + }; + }; + + # ========== Nix Helper ========== + # Provide better build output and will also handle garbage collection in place of standard nix gc (garbace collection) + programs.nh = { + enable = true; + clean.enable = true; + clean.extraArgs = "--keep-since 10d --keep 10"; + flake = "/home/user/${config.hostSpec.home}/nix-config"; + }; + + # ========= Sops ========= + environment.systemPackages = with pkgs; [ + sops + ]; + + # + # ========== Localization ========== + # + i18n.defaultLocale = lib.mkDefault "en_US.UTF-8"; + i18n.extraLocaleSettings = { + LC_ADDRESS = "ur_PK"; + LC_IDENTIFICATION = "ur_PK"; + LC_MEASUREMENT = "ur_PK"; + LC_MONETARY = "ur_PK"; + LC_NAME = "ur_PK"; + LC_NUMERIC = "ur_PK"; + LC_PAPER = "ur_PK"; + LC_TELEPHONE = "ur_PK"; + LC_TIME = "ur_PK"; + }; + time.timeZone = lib.mkDefault "Asia/Karachi"; +} diff --git a/hosts/common/disks/rihla.nix b/hosts/common/disks/rihla.nix new file mode 100644 index 0000000..6ac525a --- /dev/null +++ b/hosts/common/disks/rihla.nix @@ -0,0 +1,100 @@ +{ + disko = { + devices = { + disk = { + main = { + device = "/dev/nvme0n1"; + type = "disk"; + content = { + type = "gpt"; + partitions = { + boot = { + name = "boot"; + size = "1M"; + type = "EF02"; + }; + esp = { + name = "ESP"; + size = "500M"; + type = "EF00"; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + }; + }; + luks = { + size = "100%"; + content = { + name = "crypted"; + type = "luks"; + passwordFile = "/tmp/secret.key"; + settings = { + allowDiscards = true; + crypttabExtraOpts = [ + "fido2-device=auto" + "token-timeout=10" + ]; + }; + content = { + type = "lvm_pv"; + vg = "crypt_vg"; + }; + }; + }; + }; + }; + }; + }; + lvm_vg = { + crypt_vg = { + type = "lvm_vg"; + lvs = { + swap = { + size = "64G"; + content = { + type = "swap"; + resumeDevice = true; + }; + }; + main = { + size = "100%"; + content = { + type = "btrfs"; + extraArgs = [ + "-L" + "nixos" + "-f" + ]; + subvolumes = { + "@root" = { + mountpoint = "/"; + mountOptions = [ + "compress=zstd" + ]; + }; + "@home" = { + mountpoint = "/home"; + mountOptions = [ + "subvol=home" + "compress=zstd" + "noatime" + ]; + }; + "@nix" = { + mountpoint = "/nix"; + mountOptions = [ + "subvol=nix" + "compress=zstd" + "noatime" + ]; + }; + }; + }; + }; + }; + }; + }; + }; + }; +} diff --git a/hosts/common/optional/1password.nix b/hosts/common/optional/1password.nix new file mode 100644 index 0000000..624fd85 --- /dev/null +++ b/hosts/common/optional/1password.nix @@ -0,0 +1,14 @@ +{ + config, + ... +}: + +{ + programs = { + _1password.enable = true; + _1password-gui = { + enable = true; + polkitPolicyOwners = [ config.hostSpec.username ]; + }; + }; +} diff --git a/hosts/common/optional/dconf.nix b/hosts/common/optional/dconf.nix new file mode 100644 index 0000000..317404d --- /dev/null +++ b/hosts/common/optional/dconf.nix @@ -0,0 +1,7 @@ +{ + ... +}: + +{ + programs.dconf.enable = true; +} diff --git a/hosts/common/optional/docker.nix b/hosts/common/optional/docker.nix new file mode 100644 index 0000000..94ebc6d --- /dev/null +++ b/hosts/common/optional/docker.nix @@ -0,0 +1,47 @@ +{ + pkgs, + ... +}: { + virtualisation = { + podman = { + enable = true; + dockerSocket.enable = true; + dockerCompat = true; + + autoPrune = { + enable = true; + dates = "weekly"; + }; + }; + + containers = { + registries = { + search = ["docker.io"]; + }; + }; + + libvirtd = { + enable = true; + qemu = { + swtpm.enable = true; + + ovmf = { + enable = true; + packages = with pkgs; [OVMFFull.fd]; + }; + }; + }; + + spiceUSBRedirection.enable = true; + }; + + environment.systemPackages = with pkgs; [ + virt-manager + virt-viewer + spice + spice-gtk + spice-protocol + win-virtio + win-spice + ]; +} diff --git a/hosts/common/optional/gaming.nix b/hosts/common/optional/gaming.nix new file mode 100644 index 0000000..a8f2f9f --- /dev/null +++ b/hosts/common/optional/gaming.nix @@ -0,0 +1,22 @@ +{ + pkgs, + ... +}: + +{ + programs = { + steam = { + enable = true; + gamescopeSession.enable = true; + }; + + # to run steam games in game mode, add the following to the game's properties from within steam + # gamemoderun %command% + gamemode.enable = true; + }; + + environment.systemPackages = with pkgs; [ + mangohud + protonup-qt + ]; +} diff --git a/hosts/common/optional/hyprland.nix b/hosts/common/optional/hyprland.nix new file mode 100644 index 0000000..fb45172 --- /dev/null +++ b/hosts/common/optional/hyprland.nix @@ -0,0 +1,24 @@ +{ + inputs, + pkgs, + ... +}: + +{ + programs.hyprland = { + enable = true; + package = inputs.hyprland.packages.${pkgs.stdenv.hostPlatform.system}.hyprland; + portalPackage = + inputs.hyprland.packages.${pkgs.stdenv.hostPlatform.system}.xdg-desktop-portal-hyprland; + }; + + environment.systemPackages = with pkgs; [ + hyprshot + hyprlock + hypridle + hyprpolkitagent + mako + waybar + wofi + ]; +} diff --git a/hosts/common/optional/nix-ld.nix b/hosts/common/optional/nix-ld.nix new file mode 100644 index 0000000..0fd12d5 --- /dev/null +++ b/hosts/common/optional/nix-ld.nix @@ -0,0 +1,7 @@ +{ + ... +}: + +{ + programs.nix-ld.enable = true; +} diff --git a/hosts/common/optional/secure-boot.nix b/hosts/common/optional/secure-boot.nix new file mode 100644 index 0000000..675fc82 --- /dev/null +++ b/hosts/common/optional/secure-boot.nix @@ -0,0 +1,10 @@ +{ + pkgs, + ... +}: + +{ + environment.systemPackages = with pkgs; [ + sbctl + ]; +} diff --git a/hosts/common/optional/services/audio.nix b/hosts/common/optional/services/audio.nix new file mode 100644 index 0000000..d9a81b6 --- /dev/null +++ b/hosts/common/optional/services/audio.nix @@ -0,0 +1,23 @@ +{ + pkgs, + ... +}: + +{ + services = { + # Enable sound with pipewire. + pulseaudio.enable = false; + pipewire = { + enable = true; + alsa.enable = true; + alsa.support32Bit = true; + pulse.enable = true; + wireplumber.enable = true; + }; + }; + security.rtkit.enable = true; + + environment.systemPackages = builtins.attrValues { + inherit (pkgs) pavucontrol; + }; +} diff --git a/hosts/common/optional/services/bluetooth.nix b/hosts/common/optional/services/bluetooth.nix new file mode 100644 index 0000000..c1d413a --- /dev/null +++ b/hosts/common/optional/services/bluetooth.nix @@ -0,0 +1,11 @@ +{ + ... +}: + +{ + services.blueman.enable = true; + hardware = { + bluetooth.enable = true; + bluetooth.powerOnBoot = true; + }; +} diff --git a/hosts/common/optional/services/firmware.nix b/hosts/common/optional/services/firmware.nix new file mode 100644 index 0000000..2482de6 --- /dev/null +++ b/hosts/common/optional/services/firmware.nix @@ -0,0 +1,7 @@ +{ + ... +}: + +{ + services.fwupd.enable = true; +} diff --git a/hosts/common/optional/services/greetd.nix b/hosts/common/optional/services/greetd.nix new file mode 100644 index 0000000..924fba6 --- /dev/null +++ b/hosts/common/optional/services/greetd.nix @@ -0,0 +1,16 @@ +{ + pkgs, + ... +}: + +{ + services.greetd = { + enable = true; + settings = { + default_session = { + command = "${pkgs.greetd.tuigreet}/bin/tuigreet --greeting 'Welcome to NixOS!' --asterisks --remember --remember-user-session --time --cmd ${pkgs.hyprland}/bin/Hyprland"; + user = "greeter"; + }; + }; + }; +} diff --git a/hosts/common/optional/services/openssh.nix b/hosts/common/optional/services/openssh.nix new file mode 100644 index 0000000..5a269fd --- /dev/null +++ b/hosts/common/optional/services/openssh.nix @@ -0,0 +1,15 @@ +{ + config, + ... +}: +let + sshPort = config.hostSpec.networking.ports.tcp.ssh; +in +{ + services.openssh = { + enable = true; + ports = [ sshPort ]; + }; + + networking.firewall.allowedTCPPorts = [ sshPort ]; +} diff --git a/hosts/common/optional/services/printing.nix b/hosts/common/optional/services/printing.nix new file mode 100644 index 0000000..c9b8527 --- /dev/null +++ b/hosts/common/optional/services/printing.nix @@ -0,0 +1,8 @@ +# Reminder that CUPS cpanel defaults to localhost:631 +{ + ... +}: + +{ + services.printing.enable = true; +} diff --git a/hosts/common/optional/services/smart-card.nix b/hosts/common/optional/services/smart-card.nix new file mode 100644 index 0000000..166db96 --- /dev/null +++ b/hosts/common/optional/services/smart-card.nix @@ -0,0 +1,7 @@ +{ + ... +}: + +{ + services.pcscd.enable = true; +} diff --git a/hosts/common/optional/yubikey.nix b/hosts/common/optional/yubikey.nix new file mode 100644 index 0000000..749e350 --- /dev/null +++ b/hosts/common/optional/yubikey.nix @@ -0,0 +1,22 @@ +{ + pkgs, + ... +}: + +{ + # yubikey login / sudo + security.pam = { + u2f = { + enable = true; + settings.cue = true; + }; + services = { + login.u2fAuth = true; + sudo.u2fAuth = true; + }; + }; + + environment.systemPackages = with pkgs; [ + yubikey-manager + ]; +} diff --git a/hosts/common/users/primary/default.nix b/hosts/common/users/primary/default.nix new file mode 100644 index 0000000..a2f7d21 --- /dev/null +++ b/hosts/common/users/primary/default.nix @@ -0,0 +1,53 @@ +{ + pkgs, + config, + lib, + inputs, + ... +}: +let + hostSpec = config.hostSpec; + pubKeys = lib.filesystem.listFilesRecursive ./keys; +in { + users = { + mutableUsers = false; + users.${hostSpec.username} = { + # Only do this if you have already configured zsh in home manager + ignoreShellProgramCheck = true; + + name = hostSpec.username; + shell = pkgs.zsh; + home = hostSpec.home; + isNormalUser = true; + hashedPassword = "$y$j9T$pvjyL7hL5x2VBarGNTnMl1$mLA2UsWTbfp8Hgp/ug5l8224thi..Mo8.p7ME.tDZ.4"; + extraGroups = [ + "networkmanager" + "wheel" + "input" + "libvirtd" + ]; + + # Read all keys in ./keys and add them to authorizedKeys. + openssh.authorizedKeys.keys = lib.lists.forEach pubKeys (key: builtins.readFile key); + + packages = with pkgs; [ + libnotify + ]; + }; + }; + + home-manager = { + extraSpecialArgs = { + inherit pkgs inputs; + hostSpec = config.hostSpec; + }; + users.${hostSpec.username}.imports = lib.flatten [ + ( + { config, ... }: + import (lib.custom.relativeToRoot "home/${hostSpec.username}/${hostSpec.hostName}.nix") { + inherit pkgs inputs config lib hostSpec; + } + ) + ]; + }; +} diff --git a/hosts/common/users/primary/keys/id_dogar.pub b/hosts/common/users/primary/keys/id_dogar.pub new file mode 100644 index 0000000..195c589 --- /dev/null +++ b/hosts/common/users/primary/keys/id_dogar.pub @@ -0,0 +1 @@ +ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPBijtTtb6UT5gssWolNGX1rcjAKsdtfz25fZMMnzq4v diff --git a/hosts/common/users/primary/keys/id_rihla.pub b/hosts/common/users/primary/keys/id_rihla.pub new file mode 100644 index 0000000..0546131 --- /dev/null +++ b/hosts/common/users/primary/keys/id_rihla.pub @@ -0,0 +1 @@ +ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGD/V4jLpuk7uAovkbHFr6uulfBKZmsH+BqmXIR2aYD0 diff --git a/hosts/nixos/rihla/default.nix b/hosts/nixos/rihla/default.nix new file mode 100644 index 0000000..a09e29e --- /dev/null +++ b/hosts/nixos/rihla/default.nix @@ -0,0 +1,92 @@ +{ + inputs, + lib, + ... +}: + +{ + imports = lib.flatten [ + # + # ========= Hardware ========= + # + ./hardware-configuration.nix + inputs.nixos-hardware.nixosModules.common-cpu-amd + inputs.nixos-hardware.nixosModules.common-gpu-amd + inputs.nixos-hardware.nixosModules.common-pc-ssd + inputs.nixos-hardware.nixosModules.framework-13-7040-amd + + # + # ======== Secure Boot ========= + # + inputs.lanzaboote.nixosModules.lanzaboote + + # + # ========= Disk Layout ========= + # + inputs.disko.nixosModules.disko + (lib.custom.relativeToRoot "hosts/common/disks/rihla.nix") + + # + # ========= Required Configs ========= + # + (map lib.custom.relativeToRoot [ + "hosts/common/core" + ]) + + # + # ========= Optional Configs ========= + # + (map (config: lib.custom.relativeToRoot "hosts/common/optional/${config}.nix") [ + "1password" + "dconf" + "docker" + "gaming" + "hyprland" + "nix-ld" + "secure-boot" + "yubikey" + ]) + + # + # ========= Optional Services ========= + # + (map (service: lib.custom.relativeToRoot "hosts/common/optional/services/${service}.nix") [ + "audio" + "bluetooth" + "firmware" + "greetd" + "openssh" + "printing" + "smart-card" + ]) + ]; + + # + # ========= Host specification ========= + # + hostSpec = { + hostName = "rihla"; + }; + + networking = { + networkmanager.enable = true; + enableIPv6 = false; + }; + + boot = { + loader = { + # Set this to true on first install. This must be false for secure boot. + systemd-boot.enable = lib.mkForce false; + efi.canTouchEfiVariables = true; + }; + + lanzaboote = { + enable = true; + pkiBundle = "/var/lib/sbctl"; + }; + }; + + security.rtkit.enable = true; + + system.stateVersion = "25.05"; +} diff --git a/hosts/nixos/rihla/hardware-configuration.nix b/hosts/nixos/rihla/hardware-configuration.nix new file mode 100644 index 0000000..e9b168a --- /dev/null +++ b/hosts/nixos/rihla/hardware-configuration.nix @@ -0,0 +1,47 @@ +# 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. +{ + pkgs, + config, + lib, + modulesPath, + ... +}: { + imports = [(modulesPath + "/installer/scan/not-detected.nix")]; + + boot = { + initrd = { + availableKernelModules = [ + "nvme" + "xhci_pci" + "ahci" + "usbhid" + "thunderbolt" + "usb_storage" + "sd_mod" + ]; + kernelModules = []; + }; + + kernelModules = ["kvm-amd"]; + extraModulePackages = []; + }; + + # 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.enp193s0f3u2.useDHCP = lib.mkDefault true; + # networking.interfaces.wlp1s0.useDHCP = lib.mkDefault true; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; + hardware = { + cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; + graphics = { + enable = true; + extraPackages = with pkgs; [amdvlk]; + }; + }; +} diff --git a/lib/default.nix b/lib/default.nix new file mode 100644 index 0000000..b911f01 --- /dev/null +++ b/lib/default.nix @@ -0,0 +1,8 @@ +{ + lib, + ... +}: + +{ + relativeToRoot = lib.path.append ../.; +} diff --git a/modules/common/default.nix b/modules/common/default.nix new file mode 100644 index 0000000..650f59d --- /dev/null +++ b/modules/common/default.nix @@ -0,0 +1,9 @@ +{ + ... +}: + +{ + imports = [ + ./host-spec.nix + ]; +} diff --git a/modules/common/host-spec.nix b/modules/common/host-spec.nix new file mode 100644 index 0000000..cad3547 --- /dev/null +++ b/modules/common/host-spec.nix @@ -0,0 +1,64 @@ +# Specifications For Differentiating Hosts +{ + config, + lib, + ... +}: +{ + options.hostSpec = { + username = lib.mkOption { + type = lib.types.str; + description = "The username of the host"; + }; + hostName = lib.mkOption { + type = lib.types.str; + description = "The hostname of the host"; + }; + email = lib.mkOption { + type = lib.types.attrsOf lib.types.str; + description = "The email of the user"; + }; + networking = lib.mkOption { + default = { }; + type = lib.types.attrsOf lib.types.anything; + description = "An attribute set of networking information"; + }; + domain = lib.mkOption { + type = lib.types.str; + description = "The domain of the host"; + }; + userFullName = lib.mkOption { + type = lib.types.str; + description = "The full name of the user"; + }; + handle = lib.mkOption { + type = lib.types.str; + description = "The handle of the user (eg: github user)"; + }; + home = lib.mkOption { + type = lib.types.str; + description = "The home directory of the user"; + default = "/home/${config.hostSpec.username}"; + }; + useYubikey = lib.mkOption { + type = lib.types.bool; + default = false; + description = "Used to indicate if the host uses a yubikey"; + }; + hdr = lib.mkOption { + type = lib.types.bool; + default = false; + description = "Used to indicate a host that uses HDR"; + }; + scaling = lib.mkOption { + type = lib.types.str; + default = "1"; + description = "Used to indicate what scaling to use. Floating point number"; + }; + font = lib.mkOption { + type = lib.types.str; + default = "ComicCodeLigatures"; + description = "Used to specify the system font"; + }; + }; +} diff --git a/modules/home-manager/default.nix b/modules/home-manager/default.nix new file mode 100644 index 0000000..3823c69 --- /dev/null +++ b/modules/home-manager/default.nix @@ -0,0 +1,9 @@ +{ + ... +}: + +{ + imports = [ + ./yubikey-touch-detector.nix + ]; +}