How to import a function from another NixOS module?

Hi, so I made this function that fills a list with the workspaces I want for a monitor in kanshi/sway:

monitor_workspace = begin: end: monitor:
      size = end - begin + 1;
      lib.lists.imap1 (i: v: "${pkgs.sway}/bin/swaymsg workspace ${toString (i + begin - 1)}, move workspace to output \'\"${monitor}\"\'") (lib.lists.replicate size "");

I have my home-manager machine configuration in a hostname.nix file, which has sway.nix in it’s imports list, so I’d like to define the above function in sway.nix and call it from hostname.nix. Is that possible?