Using deploy-rs with existing configuration

I have an existing NixOS configuration:

{ pkgs, lib }:

with lib;

{
  imports = [
    # <nixpkgs/nixos/modules/profiles/qemu-guest.nix>
  ];

  config = {
    fileSystems."/" = {
      device = "/dev/disk/by-label/nixos";
      fsType = "ext4";
      autoResize = true;
    };

    boot.growPartition = true;
    boot.kernelParams = [ "console=ttyS0" ];
    boot.loader.grub.device = "/dev/vda";
    boot.loader.timeout = 0;

    networking = {
      hostName = "ci";
    };

    i18n.defaultLocale = "en_US.UTF-8";
    console.keyMap = "fr";

    users.users.alice = {
      initialPassword = "alice";
      isNormalUser = true;
      extraGroups = [ "wheel" ];
    };

    services.openssh.enable = true;
    networking.firewall.enable = false;
    security.sudo.wheelNeedsPassword = false;

    system.stateVersion = "23.11";

    environment.systemPackages = with pkgs; [ hello ];
  };
}

I have tried to wrap it up in deploy-rs:

{
  description = "deployment";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils";
    deploy-rs.url = "github:serokell/deploy-rs";
  };

  outputs = { self, nixpkgs, flake-utils, deploy-rs }:
    flake-utils.lib.eachSystem [ flake-utils.lib.system.x86_64-linux ]
      (system:
        let
          pkgs = import nixpkgs { inherit system; };
          # nixpkgs with deploy-rs overlay but force the nixpkgs package
          deployPkgs = import nixpkgs {
            inherit system;
            overlays = [
              deploy-rs.overlay
              (self: super: { deploy-rs = { inherit (pkgs) deploy-rs; lib = super.deploy-rs.lib; }; })
            ];
          };
        in
        rec
        {
          nixosConfigurations = {
            bare = nixpkgs.lib.nixosSystem {
              inherit system;
              modules = [ ./bare.nix ];
            };
          };

          deploy = {
            nodes = {
              bare = {
                hostname = "localhost";
                sshUser = "alice";
                sshOpts = [ "-p" "2222" ];
                remoteBuild = false;
                profiles.system = {
                  user = "root";
                  path = deployPkgs.deploy-rs.lib.${system}.activate.nixos self.nixosConfigurations.bare;
                };
              };
            };
          };

          checks = builtins.mapAttrs (system: deployLib: deployLib.deployChecks self.deploy) deploy-rs.lib;

          devShell = pkgs.mkShell {
              buildInputs = [ pkgs.deploy-rs ];
              inputsFrom = [];
            };
        });
}

But it fails strangely:

deploy '.#bare' -d
🚀 ❓ [deploy] [DEBUG] Checking for flake support
🚀 ℹ [deploy] [INFO] Running checks for flake in .
error:
       … while checking flake output 'nixosConfigurations'

         at /nix/store/hwsdv71bmaqvzbii5viryxc8slw4vr5v-source/lib.nix:73:15:

           72|             {
           73|               ${key} = (attrs.${key} or { })
             |               ^
           74|               // (appendSystem key system ret);

       … while checking the NixOS configuration 'nixosConfigurations.x86_64-linux'

         at /nix/store/hwsdv71bmaqvzbii5viryxc8slw4vr5v-source/lib.nix:69:24:

           68|                 then (pushDownSystem system (attrs.hydraJobs or { }) ret.hydraJobs)
           69|                 else { ${system} = ret.${key}; };
             |                        ^
           70|             in

       error: attribute 'config' in selection path 'config.system.build.toplevel' not found
🚀 ❌ [deploy] [ERROR] Failed to check deployment: Nix checking command resulted in a bad exit code: Some(1)

I don’t get the error as bare.nix has a config attribute.

Any hint about what’s missing/wrong?

Im guessing that config.system.build.toplevel isnt defined correctly. Possibly attribute mismatch?

I’m not supposed to define it myself, however, it work in nix repl:

nix-repl> :lf .
Added 13 variables.

nix-repl> nixosConfigurations.x86_64-linux.bare.config.system.build.toplevel
«derivation /nix/store/46x1czi4sxh0w3fjyrka1zfdmi7prcmq-nixos-system-ci-23.11.20230810.ce5e4a6.drv»

Actually, flake-utils was causing the issue:

{
  description = "Black's deployments";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    deploy-rs.url = "github:serokell/deploy-rs";
  };

  outputs = { self, nixpkgs, deploy-rs }:
    let
      system = "x86_64-linux";
      pkgs = import nixpkgs { inherit system; };
    in
    {
      nixosConfigurations = {
        bare = nixpkgs.lib.nixosSystem {
          inherit system;
          modules = [ ./bare.nix ];
        };
      };

      deploy = {
        nodes = {
          bare = {
            hostname = "localhost";
            sshUser = "alice";
            sshOpts = [ "-p" "2222" ];
            remoteBuild = false;
            profiles.system = {
              user = "root";
              path = deploy-rs.lib.${system}.activate.nixos self.nixosConfigurations.bare;
            };
          };
        };
      };

      checks = builtins.mapAttrs (system: deployLib: deployLib.deployChecks self.deploy) deploy-rs.lib;
      devShell.${system} =
        pkgs.mkShell {
          buildInputs = [ pkgs.deploy-rs ];
          inputsFrom = [ ];
        };
    };
}