{
  options,
  config,
  lib,
  inputs,
  ...
}:
with lib;
with lib.frajul;
let
  cfg = config.modules.nixos.home;
in
{
  imports = with inputs; [
    home-manager.nixosModules.home-manager
    nix-colors.homeManagerModules.default
    prism.homeModules.prism
  ];

  options.modules.nixos.home = with types; {
    enable = mkBoolOpt false "Enable or disable nixos home";
  };

  options.home = with types; {
    file = mkOpt attrs { } "A set of files to be managed by home-manager's <option>home.file</option>.";
    configFile =
      mkOpt attrs { }
        "A set of files to be managed by home-manager's <option>xdg.configFile</option>.";
    programs = mkOpt attrs { } "Programs to be managed by home-manager.";
    extraOptions = mkOpt attrs { } "Options to pass directly to home-manager.";

    persist = mkOpt attrs { } "Files and directories to persist in the home";
  };

  config = mkIf cfg.enable {
    home.extraOptions = {
      home.stateVersion = config.system.stateVersion;
      home.file = mkAliasDefinitions options.home.file;
      xdg.enable = true;
      xdg.configFile = mkAliasDefinitions options.home.configFile;
      programs = mkAliasDefinitions options.home.programs;
    };

    home-manager = {
      useUserPackages = true;

      users.${config.user.name} = mkAliasDefinitions options.home.extraOptions;
    };

    environment.persistence."/persist".users.${config.user.name} = mkIf options.impermanence.enable.value (
      mkAliasDefinitions options.home.persist
    );
  };
}
