writeShellScriptBin "unexpected '"', expecting '.' or '='"

i followed Trivial builders | nixpkgs and added to my configuration.nix:

writeShellScriptBin "test.sh"
  ''
  echo "test"
  '';

it returns error error: syntax error, unexpected '"', expecting '.' or '='.
after advise from matrix i tried adding it to my packages:

environment.systemPackages with pkgs; [
writeShellScriptBin "test.sh"
  ''
  echo "test"
  '';
]

this returns

A definition for option `environment.systemPackages."[definition 1-entry 1]"' is not of type `package'. Definition values:
       - In `/etc/nixos/packages.nix': <function>
environment.systemPackages = with pkgs; [
  (writeShellScriptBin "test.sh" ''
    echo "test"
  '')
];

Maybe give the language tutorial a shot, you’re still struggling with basic syntax: Nix language basics — nix.dev documentation

Note that all NixOS configuration is in big attribute sets, so make sure to understand how to write those specifically.