Custom systemd unit in configuration.nix not added to system

NixOS 25.11: I tried to create a systemd oneshot unit with an associated timer. My unit is more complex, but even this simplified version, put directly in configuration.nix, doesn’t seem to install any unit files (systemctl list-unit-files doesn’t show them):

  systemd.services.my-task = {
    enable = true;
    description = "My periodic task";
    path = [ pkgs.coreutils pkgs.bash ];  # ensure required binaries are on PATH
    serviceConfig = {
      Type = "oneshot";
      ExecStart = "${myScript}";
      User = "root";
    };
    wantedBy = [ "multi-user.target" ];  # optional; ensures it can be started manually or on boot
  };

  systemd.timers.my-task = {
    enable = true;
    description = "Timer for my periodic task";
    wantedBy = [ "timers.target" ];
    timerConfig = {
      OnUnitActiveSec = "5min";
      Unit = "my-task.service";
      AccuracySec = "10s";
    };
  };

All looks good. I have similar stuff and I verified it on my system. Look:

❯ systemctl cat my-task.service
# /etc/systemd/system/my-task.service -> /nix/store/wqcjcsc2w716291igrp2y12d4a945vww-unit-my-task.service/my-task.service
[Unit]
Description=My periodic task

[Service]
Environment="LOCALE_ARCHIVE=/nix/store/9vmxdn26pggj3glazmb68vhcf4smflvz-glibc-locales-2.40-66/lib/locale/locale-archive"
Environment="PATH=/nix/store/imad8dvhp77h0pjbckp6wvmnyhp8dpgg-coreutils-9.8/bin:/nix/store/35yc81pz0q5yba14lxhn5r3jx5yg6c3l>
Environment="TZDIR=/nix/store/xaa75rd44q62nc9mrbvym9d1m6gy0fj8-tzdata-2025b/share/zoneinfo"
ExecStart=/nix/store/2bcv91i8fahqghn8dmyr791iaycbsjdd-hello-2.12.2
Type=oneshot
User=root

[Install]
WantedBy=multi-user.target

❯ systemctl list-timers my-task.timer
NEXT                            LEFT LAST PASSED UNIT          ACTIVATES
Tue 2025-12-09 00:17:08 CET 4min 32s -         - my-task.timer my-task.service

1 timers listed.
Pass --all to see loaded but inactive timers, too.

I think there must be something else wrong with your configuration.

Remove the enable = trues they do nothing.
Did you rebuild and switch after editing? Any errors?

Seems like the issue was due to a bad activation script. Specifically
the following:

system.activationScripts.check-default-profile-empty = ''
  set -eu -o pipefail
  nix_profile_list=$(${pkgs.nix}/bin/nix profile list --profile /nix/var/nix/profiles/default 2>/dev/null)
  # Exit 0 if default profile empty; exit 1 (error) otherwise
  if printf '%s' "$nix_profile_list" | grep -q "Store paths:"; then
    printf "ERROR: /nix/var/nix/profiles/default is non-empty — manual packages installed:\n%s\n" \
      "$nix_profile_list" >&2
    exit 1
  fi
  exit 0
'';

Turns out that grep might not be included on the default PATH. But
somehow it was still activating a profile (but only the most recent
working profile, not the one I wanted). I need to include the full path
to grep:

system.activationScripts.check-default-profile-empty = ''
  set -eu -o pipefail
  nix_profile_list=$(${pkgs.nix}/bin/nix profile list --profile /nix/var/nix/profiles/default 2>/dev/null)
  if printf '%s' "$nix_profile_list" | ${pkgs.gnugrep}/bin/grep -q "Store paths:"; then
    printf "ERROR: /nix/var/nix/profiles/default is non-empty — manual packages installed:\n%s\n" \
      "$nix_profile_list" >&2
    exit 1
  fi
'';

After making that change, the new systemd unit is successfully being installed into the active system configuration.