{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
  };

  outputs = { self, nixpkgs }: {
    nixosConfigurations = {
      b450m-d3sh = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";

        pkgs = nixpkgs.legacyPackages.${system};
        lib = nixpkgs.lib;

        modules = [
          # Base system settings
          {
            # Ensure the Nix package manager can handle Flakes
            nix = {
              package = pkgs.nixFlakes;
              extraOptions = "experimental-features = nix-command flakes";
            };

            # Basic system configuration
            networking.hostName = "b450m-d3sh";
            networking.networkmanager.enable = true;
            time.timeZone = "America/Detroit";
            i18n.defaultLocale = "en_US.UTF-8";

            # Enable automatic system upgrades
            systemd.timers.nixos-upgrade = {
              enable = true;
              timerConfig.OnCalendar = "weekly";
              wantedBy = [ "timers.target" ];
            };
            systemd.services.nixos-upgrade = {
              script = "${pkgs.nixos-rebuild}/bin/nixos-rebuild switch --upgrade";
              serviceConfig.Type = "oneshot";
            };

            # Garbage collection settings
            nix.gc = {
              automatic = true;
              dates = "weekly";
              options = "--max-age 3d";
            };
          }

          # Desktop Environment (Plasma 6)
          {
            services.xserver.enable = true;
            services.displayManager.sddm.enable = true;
            services.displayManager.defaultSession = "plasma";
            services.displayManager.sddm.wayland.enable = false;
            services.desktopManager.plasma6.enable = true;
            programs.gnupg.agent.pinentryPackage = lib.mkForce pkgs.pinentry-qt;
          }

          # Software Packages
          {
            environment.systemPackages = with pkgs; [
              # Essentials
              git keepassxc bitwarden python3 appimage-run papirus-icon-theme
              gnome.dconf-editor libreoffice-qt gnome.gnome-tweaks spotify tailscale vlc
              gimp wget libsForQt5.ghostwriter wine-staging pavucontrol fluffychat distrobox
              geany thunderbird ntfs3g firefox flatpak mullvad-vpn discord kopia tdesktop
              flameshot microsoft-edge ollama screen nodejs pipx ncdu nvtop php 
              adapta-gtk-theme mlocate yt-dlp waybar wofi networkmanagerapplet kitty mako
              swaybg swaylock grim slurp jq wl-clipboard notify-desktop libnotify playerctl
              pamixer swayidle emojione xclip sway-contrib.grimshot gthumb 
              xfce.thunar-archive-plugin xfce.thunar-volman unzip gnome.file-roller lxrandr
              pinta okular cinnamon.nemo-with-extensions plex-media-player virt-manager

              # Additional Tools
              fish nfs-utils nvidiaPackages.stable podman cups openssh

              # Programming Languages
              python311Packages.pip python312
            ];
          }

          # Fish Shell
          {
            users.users.derrik = {
              isNormalUser = true;
              description = "Derrik Diener";
              shell = pkgs.fish;
              extraGroups = [ "networkmanager" "wheel" "vboxusers" ]; 
            };
            programs.fish.enable = true;
          }

          # Flatpak and XDG
          {
            services.flatpak.enable = true;
            xdg.portal.enable = true;
          }

          # Virtualization
          {
            virtualisation.podman = {
              enable = true;
              dockerCompat = true;
              defaultNetwork.settings.dns_enabled = true;
            };

            virtualisation.virtualbox.host.enable = true;
            boot.kernelModules = [ "vboxdrv" "vboxnetadp" "vboxnetflt" "vboxpci" ];
            virtualisation.libvirtd.enable = true;

            virtualisation.waydroid.enable = true;
          }

          # Other Services and Drivers
          {
            services.printing.enable = true;
            sound.enable = true;
            hardware.pulseaudio.enable = false;
            security.rtkit.enable = true;
            services.pipewire = {
              enable = true;
              alsa.enable = true;
              alsa.support32Bit = true;
              pulse.enable = true;
            };
            services.tailscale.enable = true;
            networking.firewall.checkReversePath = "loose";
            hardware.opengl = {
              enable = true;
              driSupport = true;
              driSupport32Bit = true;
            };
            services.xserver.videoDrivers = [ "nvidia" ];
          }

          # Swap
          {
            swapDevices = [
              { device = "/var/lib/swapfile"; size = 4096; }
            ];
          }

          # NVIDIA (optional - include only if you have an NVIDIA GPU)
          { 
            hardware.nvidia = {
              modesetting.enable = true;
              powerManagement.enable = false;
              powerManagement.finegrained = false;
              open = false;
              nvidiaSettings = true;
              package = config.boot.kernelPackages.nvidiaPackages.stable;
            }; 
          }
        ];
      };
    };
  };
}
