How do I fetch various github repos as I would git clone them?

Fairly new to NixOS and have installed it as my main OS since December. I have one issue which is bugging me where I have a number of repos, private and public that I would like to pull into my home directory or into directories under home, and also a ~/code directory which is used as a workspace for projects, etc.

In many ways what I’m asking is just to create a file structure using home-manager which would use a variant of fetchGit that would be able determine if there is a repo at that path, if there is, do nothing and leave as is, if there nothing clone the repository like you would manually. e.g

home.file.".code/repo".source = (builtins.fetchGitIfNotAlreadyPresent {
  url = "ssh://git@github.com/owner/repo.git";
  ref = "master" # maybe automatically pulls in default branch
  leaveDotGit = true; # useful from pkgs.fetchgit, maybe default as true
})

However as I understand this breaks the paradigm of “functional purity” as it’s a side effect. I can somewhat do this already using fetchGit but I have to pass an --impure flag. However it’s not suitable as the repo is contained within the nix-store and only symlinked from the home directory location.
Maybe there is already a solution to this but it would be nice to be able structure my home-directory in a declarative model using the specificity of home-manager as to some uglier bash script

How about a systemd service that runs on a FileExists condition?