Problems with option evaluation

Hello,
I am currently working on a fork of the Combined Manager project by FlafyDev (GitHub - Noah765/combined-manager: NixOS personal configuration structure library), and encountered some errors trying to port my impermanence module to it. I have created a small reproducible flake to show off the problem:

{
  inputs.nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";

  outputs =
    inputs:
    let
      lib = inputs.nixpkgs.lib;
      combinedManagerToNixosConfig =
        config:
        config
        // {
          class = "nixos";
          options = config.options.os;
          config = config.config.os;
        };
    in
    {
      nixosConfigurations.default = combinedManagerToNixosConfig (
        lib.evalModules {
          modules = [
            (
              { options, config, ... }:
              {
                options = {
                  os = lib.mkOption {
                    type = lib.types.submoduleWith {
                      modules =
                        import "${inputs.nixpkgs}/nixos/modules/module-list.nix"
                        ++ [
                          {
                            nixpkgs.system = "x86_64-linux"; # Required for some module args
                          }
                        ]
                        ++ [
                          (
                            { config, lib, ... }:
                            {
                              options = {
                                environment.persistence = lib.mkOption {
                                  default = { };
                                  type =
                                    with lib.types;
                                    attrsOf (
                                      lib.types.submodule (
                                        { name, ... }:
                                        {
                                          options = {
                                            persistentStoragePath = lib.mkOption {
                                              type = path;
                                              default = name;
                                            };

                                            files = lib.mkOption {
                                              default = [ ];
                                              type = listOf (submodule {
                                                options = {
                                                  persistentStoragePath = lib.mkOption {
                                                    type = path;
                                                    default = config.environment.persistence.${name}.persistentStoragePath;
                                                  };
                                                  file = lib.mkOption { type = str; };
                                                };
                                              });
                                            };
                                          };
                                        }
                                      )
                                    );
                                };
                              };

                              config.systemd.services."${(lib.head config.environment.persistence."/persist/system".files)
                                .persistentStoragePath
                              }" = { };
                            }
                          )
                        ];
                    };
                  };
                };

                config = {
                  os.environment.persistence."/persist/system".files = [ { file = "/test"; } ];
                  impermanence.files = [ { file = "/etc/test"; } ];
                };

                imports = [
                  {
                    options.impermanence.files =
                      (lib.evalModules {
                        modules =
                          [ { _module.args.name = "/persist/system"; } ]
                          ++ (options.os.type.getSubOptions [ ])
                          .environment.persistence.type.nestedTypes.elemType.getSubModules;
                      }).options.files;

                    config.os.environment.persistence."/persist/system".files = config.impermanence.files;
                  }
                ];
              }
            )
          ];
        }
      );
    };
}

Trying to build the config above using nixos-rebuild build --flake .#default produces the following output:

building the system configuration...
error:
       … while calling the 'head' builtin
         at /nix/store/p8rwg1cl2d35k9yqib357n4sk67idj12-source/lib/attrsets.nix:1575:11:
         1574|         || pred here (elemAt values 1) (head values) then
         1575|           head values
             |           ^
         1576|         else

       … while evaluating the attribute 'value'
         at /nix/store/p8rwg1cl2d35k9yqib357n4sk67idj12-source/lib/modules.nix:821:9:
          820|     in warnDeprecation opt //
          821|       { value = addErrorContext "while evaluating the option `${showOption loc}':" value;
             |         ^
          822|         inherit (res.defsFinal') highestPrio;

       … while evaluating the option `os.system.build.toplevel':

       … while evaluating definitions from `/nix/store/p8rwg1cl2d35k9yqib357n4sk67idj12-source/nixos/modules/system/activation/top-level.nix':

       … while evaluating the option `os.assertions':

       … while evaluating definitions from `/nix/store/p8rwg1cl2d35k9yqib357n4sk67idj12-source/nixos/modules/system/boot/systemd.nix':

       … while evaluating the option `os.systemd.services':

       … while evaluating definitions from `<unknown-file>':

       … while evaluating the option `os.environment.persistence."/persist/system".files."[definition 1-entry 1]".persistentStoragePath':

       … while evaluating definitions from `<unknown-file>':

       … while evaluating the option `impermanence.files."[definition 1-entry 1]".persistentStoragePath':

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: attribute '"/persist/system"' missing
       at /nix/store/dhvbsrbdkzlvf40hlx3nkp0ajyv8w8nq-source/flake.nix:59:63:
           58|                                                     type = path;
           59|                                                     default = config.environment.persistence.${name}.persistentStoragePath;
             |                                                               ^
           60|                                                   };

After commenting out the impermanence.files = [ { file = "/etc/test"; } ]; at the bottom of the flake, the same command no longer produces this error (instead it complains about failed assertions, which are checked after the options are evaluated, right?)

Running nix eval .#nixosConfigurations.default.config.environment.persistence./persist/system.files instead produces [ { file = "/etc/test"; persistentStoragePath = «error: attribute '"/persist/system"' missing»; } { file = "/test"; persistentStoragePath = "/persist/system"; } ] in the error case and [ { file = "/test"; persistentStoragePath = "/persist/system"; } ] in the success case.

Can anyone tell me what is going on and maybe even how to fix it?
Any help will be greatly appreciated.

P.S. Sorry for the ‘small’ reproducible example, I could not make it any smaller while keeping the same error messages. The same impermanence.files option works fine in my normal NixOS config btw.