Overwriting nixos configuration attibute for vm

I have this file to add a password to the default user password to test nixos configurations:

let
  nixpkgs = <nixpkgs>;
  pkgs = import nixpkgs {};
  configuration = import ./configuration.nix pkgs;
  nixos = import "${nixpkgs}/nixos" {
    configuration = pkgs.lib.recursiveUpdate configuration {
      users.users.alice.initialPassword = "danger";
    };
  };
in
  nixos.vm

so you can test your configuration running nix-build vm.nix.

I wonder if this is the most straight forward way to add an attribute to the attribute set of the user.
Is there a better way to do the same?

an alternative is:

vmconf.nix:

{  pkgs,  lib,  ...} @ nixpkgs: let
  conf = import ./configuration.nix nixpkgs;
in
  lib.recursiveUpdate conf {users.users.alice.initialPassword = "danger";}

and nix-build '<nixpkgs/nixos>' -A vm -I nixos-config=./vmconf.nix

But this one confuses me a bit.
I think the command <nixpkgs/nixos> points to the default.nix in nixos folder in nixpkgs. But how can this again point to nixpkgs.pkgs and nixpkgs.lib?

i am also wondering why the two snippets have different results (different hash)

i think the answer to my original question is:

{ config, pkgs, ... }: {
  imports = [./configuration.nix];
  users.users.alice.initialPassword = "danger";
}

and run nix-build '<nixpkgs/nixos>' -A vm -I nixos-config=./vm.nix

still wondering, why is it producing a different result from the initial post?