Kernel module will not load the pcspkr module

I am trying to get the command beep to work. It don’t work after a
nixos-rebuild switch, but if I manually make a modprobe pcspkr then I can get the
beep command to work.
I have tried to add it to the configuration file, but I get a error or it don’t work.

Here is some output from coomends.

modinfo pcspkr

filename: /run/booted-system/kernel-modules/lib/modules/6.1.27/kernel/drivers/input/misc/pcspkr.ko.xz
alias: platform:pcspkr
license: GPL
description: PC Speaker beeper driver
author: Vojtech Pavlik vojtech@ucw.cz
depends:
retpoline: Y
intree: Y
name: pcspkr
vermagic: 6.1.27 SMP preempt mod_unload

nixos-rebuild switch

building Nix…
building the system configuration…
error: undefined variable ‘pcspkr’

   at /etc/nixos/configuration.nix:18:65:

       17|
       18|   boot.extraModulePackages = with config.boot.kernelPackages; [ pcspkr ]; #  used by beep
         |                                                                 ^
       19|

(use ‘–show-trace’ to show detailed location information)

How do I get beep to work?
How do I load the module into the kernel via the config file?
PS. I am a newbie at NixOs.

Have been trying this too but nothing works.

boot.kernelModules = [ "pcspkr" ];
  # boot.initrd.availableKernelModules = [ "pcspkr" ];  
  # boot.extraModulePackages = with config.boot.kernelPackages; [ pcspkr ]; #  used by beep
  # boot.extraModulePackages = [ config.boot.kernelPackages.pcspkr ];

boot.kernelModules = [ "pcspkr" ]; should be what you want, but note that this only gets applied on boot, not during a configuration switch / nixos-rebuild switch.

Reboot do not work.

But poking around, I found this in /etc/modprobe.d

$ ls -ltr
total 0
lrwxrwxrwx 1 root root 36 May 11 00:55 firmware.conf -> /etc/static/modprobe.d/firmware.conf
lrwxrwxrwx 1 root root 33 May 11 00:55 nixos.conf -> /etc/static/modprobe.d/nixos.conf
lrwxrwxrwx 1 root root 34 May 11 00:55 debian.conf -> /etc/static/modprobe.d/debian.conf
lrwxrwxrwx 1 root root 35 May 11 00:55 systemd.conf -> /etc/static/modprobe.d/systemd.conf
lrwxrwxrwx 1 root root 34 May 11 00:55 ubuntu.conf -> /etc/static/modprobe.d/ubuntu.conf

$ grep -r pcspk *
ubuntu.conf:blacklist pcspkr

It seem like configuration from other distributions are being dumped into the modprobe.d directory. This break the idea that all configuration should be in the nixos configuration file.

How do I get the nixos-rebuild to not putting the ubuntu.conf into the the /etc/modprobe.d/ directory?

How does one tell the build package that beep depend on the pcspkr kernel module?