{
  config,
  lib,
  pkgs,
  ...
}:
let
  cfg = config.modules.remoteBuild;
  remoteBuilder = lib.mkIf cfg.become-remote-builder {
    users.users.remotebuild = {
      isSystemUser = true;
      shell = pkgs.bashInteractive;
      group = "remotebuild";
      # useDefaultShell = true;

      # ssh-keygen -f /root/.ssh/remotebuild
      openssh.authorizedKeys.keyFiles = [ ./remotebuild.pub ];
      openssh.authorizedKeys.keys = [
        # Laptop-system
        "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIE/4h+WCBBW82puv8SMdUbkWymF4amEMuZitgFztB6oZ doloroo@proton.me"
        # Laptop-user-doloro
        "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOuNlm8vq6MvWsVU/RW4oq7npQngjIxNFpjEWbAS/8H2 root@doloro-nixos-laptop"
      ];
      initialPassword = "remotebuilder";
    };

    users.groups.remotebuild = { };

    nix.settings.trusted-users = [ "remotebuild" ];
  };
  useBulders = lib.mkIf cfg.use-remote-builders {
    nix.distributedBuilds = true;
    nix.settings.builders-use-substitutes = true;

    # Define every build machine here..
    # also define in home manager (TODO make a single file with all builders)
    nix.buildMachines = [
      {
        # Main desktop pc
        # ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKqsFEgtcTDw89GaZJg8P/FE1xngIXmiUZl8j0b+V7n+ root@doloroo-main
        hostName = "doloroo-main";
        sshUser = "remotebuild";
        sshKey = "/root/.ssh/remotebuild";
        system = "x86_64-linux";
        maxJobs = 8;
        speedFactor = 2;
        supportedFeatures = [
          "nixos-test"
          "big-parallel"
          "kvm"
        ];
      }
    ];
  };
in
{
  options.modules.remoteBuild = {
    use-remote-builders = lib.mkEnableOption "remoteBuild";
    become-remote-builder = lib.mkEnableOption "remoteBuild";
  };
  config = lib.attrsets.recursiveUpdate useBulders remoteBuilder;
}
