# vim: set foldlevel=0 foldmethod=marker foldenable :
{
  description = "NixOS configuration with Home Manager";
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/24.05";
    nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
    apple-silicon = {
      url = "github:tpwrules/nixos-apple-silicon";
      inputs.nixpkgs.follows = "nixpkgs-unstable";
    };
    lix = {
      url = "git+https://git@git.lix.systems/lix-project/lix?ref=refs/tags/2.90-beta.1";
      flake = false;
    };
    lix-module = {
      url = "https://git.lix.systems/lix-project/nixos-module/archive/2.90.0-rc1.tar.gz";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    nix-ld = {
      url = "github:Mic92/nix-ld";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    nur.url = github:nix-community/NUR;
    home-manager = {
      url = "github:nix-community/home-manager/release-24.05";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    home-manager-unstable = {
      url = "github:nix-community/home-manager"; #/release-23.11";
      inputs.nixpkgs.follows = "nixpkgs-unstable";
    };
    displaylink = {
      url = "file+https://marq42.xyz/displaylink-580.zip";
      flake = false;
    };
  };
  outputs = inputs@{ 
    self, 
      nixpkgs,
      nixpkgs-unstable,
      lix-module,
      nix-ld,
      home-manager,
      nur,
      ... }: {
 homeManagerConfigurations.soundblaster = 
        # import ./home.nix {
        #   inherit nixpkgs lix-module nix-ld home-manager nur;
        # }
	home-manager.lib.homeManagerConfiguration {
          pkgs = nixpkgs.legacyPackages.x86_64-linux;
	  # configuration = { pkgs, lib, ... }: {
	  #   imports = [ ./home.nix ];
	  #   nixpkgs = {
          #     config = { allowUnfree = true; };
	  #   };
          # };
	  modules = [
	    ./home.nix {
	      home = {
	        username = "mir";
		homeDirectory = "/home/mir";
	      };
	    }
	  ];
	};

        nixosConfigurations = {

          kremzeek = # {{{
            let 
              system = "x86_64-linux";
              specialArgs = { inherit inputs; };
              modules = [
		nix-ld.nixosModules.nix-ld
                "${nixpkgs}/nixos/modules/installer/cd-dvd/installation-cd-graphical-calamares.nix" {
                  networking.wireless.enable = false;
                }
                ./configuration.nix {
                  networking.hostName = "kremzeek";
                  boot.loader.efi.canTouchEfiVariables = true;
                  # sound.enable = true;
                  # hardware.pulseaudio.enable = true;
                }
                home-manager.nixosModules.home-manager
                {
                  home-manager.useGlobalPkgs = true;
                  home-manager.useUserPackages = true;
                  home-manager.users.mir = import ./home.nix;
                  home-manager.extraSpecialArgs = specialArgs;
                }
              ]; # end of modules
            in
              nixpkgs.lib.nixosSystem {inherit system modules specialArgs; }; # }}}
          galvatron = # {{{
            let 
              system = "aarch64-linux";
              specialArgs = { inherit inputs; };
              modules = [
		nix-ld.nixosModules.nix-ld
                ./configuration.nix {
                  services.xserver.videoDrivers = [ "modesetting" ];
                  boot.binfmt.emulatedSystems = ["x86_64-linux"];
                  hardware.asahi = {
                    peripheralFirmwareDirectory = ./galvatron/firmware;
                    # useExperimentalGPUDriver = true;
                    experimentalGPUInstallMode = "driver";
                    # experimentalGPUInstallMode = "overlay";
                  };
                  boot.loader.efi.canTouchEfiVariables = false;
                  networking = {
                    hostName = "galvatron";
                    hostId = "57184c38";
                  };
                  sound.enable = true; # only on unstable?
                }
                ./hardware/galvatron-hw.nix
                ./modules/sound/pipewire.nix
                inputs.apple-silicon.nixosModules.apple-silicon-support
                inputs.home-manager.nixosModules.home-manager {
                  home-manager.useGlobalPkgs = true;
                  home-manager.useUserPackages = true;
                  home-manager.users.mir = import ./home.nix;
                  home-manager.extraSpecialArgs = specialArgs;
                }
              ]; # end of modules
            in
              nixpkgs.lib.nixosSystem {inherit system modules specialArgs; }; # }}}
          breakdown = # {{{
            let 
              system = "x86_64-linux";
              specialArgs = { inherit inputs; };
              modules = [
		nix-ld.nixosModules.nix-ld
                ./configuration.nix {
                  networking = {
                    hostName = "breakdown";
                    hostId = "3ba70c47";
                  };
                  boot.loader.efi.canTouchEfiVariables = true;
                  sound.enable = true;
                }
                ./server/services.nix
                # ./hardware/breakdown-hw.nix
                ./hardware/generic.nix
                ./modules/sound/pipewire.nix
                home-manager.nixosModules.home-manager
                {
                  home-manager.useGlobalPkgs = true;
                  home-manager.useUserPackages = true;
                  home-manager.users.mir = import ./home.nix;
                  home-manager.extraSpecialArgs = specialArgs;
                }
              ]; # end of modules
            in
              nixpkgs.lib.nixosSystem {inherit system modules specialArgs; }; # }}}
          starscream = # {{{
            let 
              system = "x86_64-linux";
              specialArgs = { inherit inputs; };
              modules = [
		nix-ld.nixosModules.nix-ld
                ./configuration.nix {
                  services.xserver.videoDrivers = [ "modesetting" "displaylink" ];
                  networking = {
                    hostName = "starscream";
                    hostId = "45ca7150";
                  };
                  boot.loader.efi.canTouchEfiVariables = true;
                  sound.enable = true;
                }
                ./hardware/starscream-hw.nix
                ./modules/sound/pipewire.nix
                home-manager.nixosModules.home-manager
                {
                  home-manager.useGlobalPkgs = true;
                  home-manager.useUserPackages = true;
                  home-manager.users.mir = import ./home.nix;
                  home-manager.extraSpecialArgs = specialArgs;
                }
              ]; # end of modules
            in
              nixpkgs.lib.nixosSystem {inherit system modules specialArgs; }; # }}}
          knockout = # {{{
            let
              system = "x86_64-linux";
              specialArgs = { inherit inputs; };
              modules = [
		nix-ld.nixosModules.nix-ld
                # inputs.nur.nixosModules.nur
                lix-module.nixosModules.default
                ./configuration.nix {
                  services.xserver.videoDrivers = [ "modesetting" "displaylink" ];
                  boot.loader.efi.canTouchEfiVariables = true;
                  networking = {
                    hostName = "knockout";
                    hostId = "499130bf";
                  };
                  sound.enable = true;
                }
                ./modules/droidcam-obs.nix # only this machine
                ./hardware/knockout-hw.nix
                ./modules/sound/pipewire.nix
                inputs.home-manager.nixosModules.home-manager
                {
                  home-manager.useGlobalPkgs = true;
                  home-manager.useUserPackages = true;
                  home-manager.users.mir = import ./home.nix;
                  home-manager.extraSpecialArgs = specialArgs;
                }
              ]; # end of modules
            in
              inputs.nixpkgs.lib.nixosSystem {inherit system modules specialArgs; }; # }}}

          ravage = # {{{
	          let 
              system = "x86_64-linux";
	            specialArgs = { inherit inputs; };
              modules = [
		nix-ld.nixosModules.nix-ld
                ./configuration.nix {
	                services.xserver.videoDrivers = [ "modesetting" "displaylink" ];
                  networking = {
		                hostName = "ravage";
		                hostId = "c53d3e32";
	                };
	                boot.loader.efi.canTouchEfiVariables = true;
	                sound.enable = true;
                }
                ./hardware/ravage-hw.nix
	              ./modules/sound/pipewire.nix
                home-manager.nixosModules.home-manager
                {
                  home-manager.useGlobalPkgs = true;
                  home-manager.useUserPackages = true;
                  home-manager.users.mir = import ./home.nix;
	                home-manager.extraSpecialArgs = specialArgs;
                }
              ]; # end of modules
	          in
	            nixpkgs.lib.nixosSystem {inherit system modules specialArgs; }; # }}}
        };
      };
}