This is my flakeless configuration for macOS using nix
{ pkgs, ... }:

{
  launchd = {
    enable = true;
    agents = {
      "com.weethet.capsremap" = {
        enable = true;
        config = {
          RunAtLoad = true;
          ProgramArguments = [
            "/usr/bin/hidutil"
            "property"
            "--set"
            ''
              {
                            "UserKeyMapping": [
                              {
                                "HIDKeyboardModifierMappingSrc": 0x700000039,
                                "HIDKeyboardModifierMappingDst": 0x70000002A
                              },
                            ]
                          }''
          ];
        };
      };
    };
  };
}