let 
  mods = import ./modules;
  users = import ./users;
in {
  meta.nixpkgs = <nixpkgs>;
  meta.specialArgs = {
    inherit mods users;
  };
  defaults = { pkgs, ... }: {
    imports = [ <home-manager/nixos> ];
    boot.tmp.useTmpfs = true;
  };

  kat-probook = { name, nodes, ... }: {
    deployment.allowLocalDeployment = true;

    imports = [
      ./machines/kat-probook/configuration.nix
      users.root
      users.catvayor
    ];
    networking.hostName = name;
  };

  kat-r86s = { name, nodes, ... }: {
    imports = [
      ./machines/kat-r86s/configuration.nix
      users.root
    ];
    networking.hostName = name;
    users.users.root.openssh.authorizedKeys.keys = [
      "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAA16foz+XzwKwyIR4wFgNIAE3Y7AfXyEsUZFVVz8Rie catvayor@katvayor"
    ];
  };

  kat-test = { name, nodes, ... }: {
    deployment = {
      allowLocalDeployment = true;
      targetHost = "test.kat";
    };

    imports = [
      ./machines/kat-test/configuration.nix
      users.root
      users.catvayor
    ];
    networking.hostName = name;
    users.users.root.openssh.authorizedKeys.keys = [
      "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAA16foz+XzwKwyIR4wFgNIAE3Y7AfXyEsUZFVVz8Rie catvayor@katvayor"
    ];
    home-manager.users.catvayor = {
      imports = [ mods.home.mail ];
    };
  };

  kat-virt = { name, nodes, ... }: {
    deployment.targetHost = "virt.kat";

    imports = [
      ./machines/kat-virt/configuration.nix
      users.root
    ];
    networking.hostName = name;
    users.users.root.openssh.authorizedKeys.keys = [
      "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAA16foz+XzwKwyIR4wFgNIAE3Y7AfXyEsUZFVVz8Rie catvayor@katvayor"
    ];
  };


  kat-iso = { name, pkgs, ... }:{
    deployment = {
      allowLocalDeployment = false;
      targetHost = null;
    };

    imports = [
      <nixpkgs/nixos/modules/installer/cd-dvd/installation-cd-minimal-new-kernel-no-zfs.nix>
      users.root
    ];

    networking = {
      hostName = name;
      networkmanager.enable = true;
      wireless.enable = false;
    };
    console.keyMap = "fr";

    environment.systemPackages = with pkgs; [ perl git ];
    boot.supportedFilesystems = [ "bcachefs" ];
    programs.zsh.enable = true;
    services.openssh.enable = true;
    users.users.root.openssh.authorizedKeys.keys = [
      "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAA16foz+XzwKwyIR4wFgNIAE3Y7AfXyEsUZFVVz8Rie catvayor@katvayor"
    ];

    environment.etc = {
      "config_base.nix" = {
        mode = "0444";
        text = ''
          { config, lib, pkgs, ... }: {
            imports = [ ./hardware-configuration.nix ];
            boot.loader.systemd-boot.enable = true;
            boot.loader.efi.canTouchEfiVariables = true;
            boot.supportedFilesystems = [ "bcachefs" ];
            boot.kernelPackages = pkgs.linuxPackages_latest;
            # networking.networkmanager.enable = true;
            networking.hostName = "kat-undefined";

            time.timeZone = "Europe/Paris";
            i18n.defaultLocale = "en_US.UTF-8";
            console = {
              font = "Lat2-Terminus16";
              keyMap = "fr";
            };
            services.netbird.enable = true;
            services.openssh.enable = true;
            users.users.root.openssh.authorizedKeys.keys = [
              "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAA16foz+XzwKwyIR4wFgNIAE3Y7AfXyEsUZFVVz8Rie catvayor@katvayor"
            ];
            system.stateVersion = "23.11";
          }
        '';
      };
    };
  };
}
