# Buggy code
def install_centos_new(
    args: CommandLineArguments, root: str, epel_release: int
) -> List[str]:
    # Repos for CentOS 8 and later

    gpgpath = "/etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial"
    gpgurl = "https://www.centos.org/keys/RPM-GPG-KEY-CentOS-Official"
    epel_gpgpath = f"/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-{epel_release}"
    epel_gpgurl = (
        f"https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-{epel_release}"
    )

    if args.mirror:
        appstream_url = (
            f"baseurl={args.mirror}/centos/{args.release}/AppStream/x86_64/os"
        )
        baseos_url = f"baseurl={args.mirror}/centos/{args.release}/BaseOS/x86_64/os"
        extras_url = f"baseurl={args.mirror}/centos/{args.release}/extras/x86_64/os"
        centosplus_url = (
            f"baseurl={args.mirror}/centos/{args.release}/centosplus/x86_64/os"
        )
        epel_url = f"baseurl={args.mirror}/epel/{epel_release}/Everything/x86_64/os"
    else:
        appstream_url = f"mirrorlist=http://mirrorlist.centos.org/?release={args.release}&arch=x86_64&repo=AppStream"
        baseos_url = f"mirrorlist=http://mirrorlist.centos.org/?release={args.release}&arch=x86_64&repo=BaseOS"
        extras_url = f"mirrorlist=http://mirrorlist.centos.org/?release={args.release}&arch=x86_64&repo=extras"
        centosplus_url = f"mirrorlist=http://mirrorlist.centos.org/?release={args.release}&arch=x86_64&repo=centosplus"
        epel_url = f"mirrorlist=https://mirrors.fedoraproject.org/mirrorlist?repo=epel-{epel_release}&arch=x86_64"

    setup_dnf(
        args,
        root,
        repos=[
            Repo(
                "AppStream",
                f"CentOS-{args.release} - AppStream",
                appstream_url,
                gpgpath,
                gpgurl,
            ),
            Repo(
                "BaseOS", f"CentOS-{args.release} - Base", baseos_url, gpgpath, gpgurl
            ),
            Repo(
                "extras", f"CentOS-{args.release} - Extras", extras_url, gpgpath, gpgurl
            ),
            Repo(
                "centosplus",
                f"CentOS-{args.release} - Plus",
                centosplus_url,
                gpgpath,
                gpgurl,
            ),
            Repo(
                "epel",
                f"name=Extra Packages for Enterprise Linux {epel_release} - $basearch",
                epel_url,
                epel_gpgpath,
                epel_gpgurl,
            ),
        ],
    )

    return ["AppStream", "BaseOS", "extras", "centosplus"]


# Traceback (subprocess.CalledProcessError)
...
‣ Mounting API VFS...
‣ Mounting API VFS complete.
CentOS-8 - AppStream                                                                                                       8.3 MB/s | 6.2 MB     00:00
CentOS-8 - Base                                                                                                            3.1 MB/s | 2.3 MB     00:00
CentOS-8 - Extras                                                                                                           19 kB/s | 8.1 kB     00:00
CentOS-8 - Plus                                                                                                            949 kB/s | 593 kB     00:00
name=Extra Packages for Enterprise Linux 8 - x86_64                                                                        718  B/s | 249  B     00:00
Errors during downloading metadata for repository 'epel':
- Status code: 404 for https://download-cc-rdu01.fedoraproject.org/pub/epel/8/Everything/x86_64/os/repodata/repomd.xml (IP: 8.43.85.72)
Error: Failed to download metadata for repo 'epel': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried
‣ Unmounting API VFS...
‣ Unmounting API VFS complete.
‣ Unmounting Package Cache...
‣ Unmounting Package Cache complete.
‣ Unmounting image...
‣ Unmounting image complete.
‣ Detaching image file...
‣ Detaching image file complete.
Traceback (most recent call last):
File "/usr/lib64/python3.8/runpy.py", line 192, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib64/python3.8/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/root/.local/lib/python3.8/site-packages/mkosi/__main__.py", line 28, in <module>
main()
File "/root/.local/lib/python3.8/site-packages/mkosi/__main__.py", line 22, in main
run_verb(a)
File "/root/.local/lib/python3.8/site-packages/mkosi/__init__.py", line 5497, in run_verb
build_stuff(args)
File "/root/.local/lib/python3.8/site-packages/mkosi/__init__.py", line 5310, in build_stuff
raw, tar, root_hash = build_image(args, root, do_run_build_script=False, cleanup=True)
File "/root/.local/lib/python3.8/site-packages/mkosi/__init__.py", line 5128, in build_image
install_distribution(args, root, do_run_build_script=do_run_build_script, cached=cached_tree)
File "/root/.local/lib/python3.8/site-packages/mkosi/__init__.py", line 2681, in install_distribution
install[args.distribution](args, root, do_run_build_script)
File "/usr/lib64/python3.8/contextlib.py", line 75, in inner
return func(*args, **kwds)
File "/root/.local/lib/python3.8/site-packages/mkosi/__init__.py", line 2122, in install_centos
invoke_dnf_or_yum(args, root, repos, packages)
File "/root/.local/lib/python3.8/site-packages/mkosi/__init__.py", line 2010, in invoke_dnf_or_yum
invoke_dnf(args, root, repositories, packages)
File "/root/.local/lib/python3.8/site-packages/mkosi/__init__.py", line 1698, in invoke_dnf
run(cmdline)
File "/root/.local/lib/python3.8/site-packages/mkosi/__init__.py", line 194, in run
return subprocess.run(cmdline, check=check, **kwargs)
File "/usr/lib64/python3.8/subprocess.py", line 512, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['dnf', '-y', '--config=/var/tmp/mkosi-a1tay8dv/dnf.conf', '--best', '--allowerasing', '--releasever=8', '--installroot=/var/tmp/mkosi-a1tay8dv/root', '--disablerepo=*', '--enablerepo=AppStream', '--enablerepo=BaseOS', '--enablerepo=extras', '--enablerepo=centosplus', '--enablerepo=epel', '--setopt=keepcache=1', '--setopt=install_weak_deps=0', '--nodocs', 'install', 'centos-release', 'systemd', 'epel-release']' returned non-zero exit status 1.

# Fixed code
def install_centos_new(
    args: CommandLineArguments, root: str, epel_release: int
) -> List[str]:
    # Repos for CentOS 8 and later

    gpgpath = "/etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial"
    gpgurl = "https://www.centos.org/keys/RPM-GPG-KEY-CentOS-Official"
    epel_gpgpath = f"/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-{epel_release}"
    epel_gpgurl = (
        f"https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-{epel_release}"
    )

    if args.mirror:
        appstream_url = (
            f"baseurl={args.mirror}/centos/{args.release}/AppStream/x86_64/os"
        )
        baseos_url = f"baseurl={args.mirror}/centos/{args.release}/BaseOS/x86_64/os"
        extras_url = f"baseurl={args.mirror}/centos/{args.release}/extras/x86_64/os"
        centosplus_url = (
            f"baseurl={args.mirror}/centos/{args.release}/centosplus/x86_64/os"
        )
        epel_url = f"baseurl={args.mirror}/epel/{epel_release}/Everything/x86_64"
    else:
        appstream_url = f"mirrorlist=http://mirrorlist.centos.org/?release={args.release}&arch=x86_64&repo=AppStream"
        baseos_url = f"mirrorlist=http://mirrorlist.centos.org/?release={args.release}&arch=x86_64&repo=BaseOS"
        extras_url = f"mirrorlist=http://mirrorlist.centos.org/?release={args.release}&arch=x86_64&repo=extras"
        centosplus_url = f"mirrorlist=http://mirrorlist.centos.org/?release={args.release}&arch=x86_64&repo=centosplus"
        epel_url = f"mirrorlist=https://mirrors.fedoraproject.org/mirrorlist?repo=epel-{epel_release}&arch=x86_64"

    setup_dnf(
        args,
        root,
        repos=[
            Repo(
                "AppStream",
                f"CentOS-{args.release} - AppStream",
                appstream_url,
                gpgpath,
                gpgurl,
            ),
            Repo(
                "BaseOS", f"CentOS-{args.release} - Base", baseos_url, gpgpath, gpgurl
            ),
            Repo(
                "extras", f"CentOS-{args.release} - Extras", extras_url, gpgpath, gpgurl
            ),
            Repo(
                "centosplus",
                f"CentOS-{args.release} - Plus",
                centosplus_url,
                gpgpath,
                gpgurl,
            ),
            Repo(
                "epel",
                f"name=Extra Packages for Enterprise Linux {epel_release} - $basearch",
                epel_url,
                epel_gpgpath,
                epel_gpgurl,
            ),
        ],
    )

    return ["AppStream", "BaseOS", "extras", "centosplus"]