Repository: spack/spack

Issue:
Linux-headers needed for glibc can not be found
### Steps to reproduce

```console
> spack mirror create -D linux-headers

==> Concretizing input specs
==> Adding package linux-headers@6.5.2 to mirror
==> Cannot find version 6.5.2 in url_list
==> Cannot find version 6.5.2 in url_list
==> Cannot find version 6.5.2 in url_list
==> Warning: Error while fetching linux-headers@6.5.2
  All fetchers failed for spack-stage-linux-headers-6.5.2-eszwuyhocl5xnqeklqf7wpx7yfce4yzd
```

### Error message

_No response_

### Information on your system

> spack debug report
* **Spack:** 0.21.0.dev0 (931fce2c24a79eec0ec20c388d949ee088a82e28)
* **Python:** 3.6.12
* **Platform:** linux-sles15-haswell
* **Concretizer:** clingo

### General information

- [X] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [ ] I have searched the issues of this repo and believe this is not a duplicate
- [ ] I have run the failing commands in debug mode and reported the output


Discussion:
@haampie 
Confirmed the issue on:

* **Spack:** 0.21.0.dev0 (aa7dfdb5c77c9a0d290d3486699cc6011b37afbf)
* **Python:** 3.11.5
* **Platform:** linux-ubuntu20.04-icelake
* **Concretizer:** clingo

Here's a sample of what I get:

```console
$ spack -d mirror create  -n 1 -d /tmp/mirror linux-headers 
==> [2023-10-12-17:48:53.038683] Imported mirror from built-in commands
==> [2023-10-12-17:48:53.041164] Imported mirror from built-in commands
==> [2023-10-12-17:48:53.041603] Concretizing input specs
==> [2023-10-12-17:48:53.042350] Reading config from file /home/culpo/PycharmProjects/spack/etc/spack/defaults/config.yaml
==> [2023-10-12-17:48:53.060176] Reading config from file /home/culpo/.spack/config.yaml
==> [2023-10-12-17:48:53.064242] DATABASE LOCK TIMEOUT: 60s
==> [2023-10-12-17:48:53.064301] PACKAGE LOCK TIMEOUT: No timeout
==> [2023-10-12-17:48:53.064480] Reading config from file /home/culpo/PycharmProjects/spack/etc/spack/defaults/bootstrap.yaml
==> [2023-10-12-17:48:53.072242] Reading config from file /home/culpo/PycharmProjects/spack/etc/spack/defaults/repos.yaml
==> [2023-10-12-17:48:53.074933] [BOOTSTRAP CONFIG SCOPE] name=_builtin
==> [2023-10-12-17:48:53.075267] Reading config from file /home/culpo/PycharmProjects/spack/etc/spack/defaults/bootstrap.yaml
==> [2023-10-12-17:48:53.081921] [BOOTSTRAP CONFIG SCOPE] name=defaults, path=/home/culpo/PycharmProjects/spack/etc/spack/defaults
==> [2023-10-12-17:48:53.081963] [BOOTSTRAP CONFIG SCOPE] name=defaults/linux, path=/home/culpo/PycharmProjects/spack/etc/spack/defaults/linux
==> [2023-10-12-17:48:53.081989] [BOOTSTRAP CONFIG SCOPE] name=bootstrap, path=/home/culpo/.spack/bootstrap/config
==> [2023-10-12-17:48:53.082007] [BOOTSTRAP CONFIG SCOPE] name=bootstrap/linux, path=/home/culpo/.spack/bootstrap/config/linux
==> [2023-10-12-17:48:53.082789] Reading config from file /home/culpo/PycharmProjects/spack/etc/spack/defaults/config.yaml
==> [2023-10-12-17:48:53.110503] Reading config from file /home/culpo/.spack/bootstrap/config/linux/config.yaml
==> [2023-10-12-17:48:53.119755] DATABASE LOCK TIMEOUT: 60s
==> [2023-10-12-17:48:53.119817] PACKAGE LOCK TIMEOUT: No timeout
==> [2023-10-12-17:48:53.120018] Reading config from file /home/culpo/.spack/bootstrap/config/linux/compilers.yaml
==> [2023-10-12-17:48:53.142162] [BOOTSTRAP ROOT SPEC] patchelf@0.13.1: %gcc target=x86_64
==> [2023-10-12-17:48:53.142658] Reading config from file /home/culpo/PycharmProjects/spack/etc/spack/defaults/bootstrap.yaml
==> [2023-10-12-17:48:53.152412] [BOOTSTRAP EXECUTABLES patchelf] Try installed specs with query 'patchelf@0.13.1: %gcc target=x86_64'
==> [2023-10-12-17:48:53.250908] Reading config from file /home/culpo/PycharmProjects/spack/etc/spack/defaults/modules.yaml
==> [2023-10-12-17:48:53.261853] Reading config from file /home/culpo/PycharmProjects/spack/etc/spack/defaults/linux/modules.yaml
==> [2023-10-12-17:48:53.328566] Reading config from file /home/culpo/PycharmProjects/spack/etc/spack/defaults/packages.yaml
==> [2023-10-12-17:48:53.357466] Reading config from file /home/culpo/.spack/bootstrap/config/packages.yaml
==> [2023-10-12-17:48:53.364881] [BOOTSTRAP ROOT SPEC] gnupg@2.3: %gcc target=x86_64
==> [2023-10-12-17:48:53.366321] [BOOTSTRAP ROOT SPEC] clingo-bootstrap@spack+python %gcc target=x86_64
==> [2023-10-12-17:48:53.366362] [BOOTSTRAP MODULE clingo] Try importing from Python
==> [2023-10-12-17:48:53.388832] [BOOTSTRAP MODULE clingo] The installed spec "clingo-bootstrap@spack+python %gcc target=x86_64 ^python@3.11/55qeu52pkt5shpwd7ulugv7wzt5j7vqd" provides the "clingo" Python module
==> [2023-10-12-17:48:53.389262] Reading config from file /home/culpo/PycharmProjects/spack/etc/spack/defaults/concretizer.yaml
==> [2023-10-12-17:48:53.395566] Reading config from file /home/culpo/PycharmProjects/spack/etc/spack/defaults/repos.yaml
==> [2023-10-12-17:48:53.439146] Reading config from file /home/culpo/PycharmProjects/spack/etc/spack/defaults/packages.yaml
==> [2023-10-12-17:48:53.468386] Reading config from file /home/culpo/PycharmProjects/spack/etc/spack/defaults/config.yaml
==> [2023-10-12-17:48:53.484178] Reading config from file /home/culpo/.spack/config.yaml
==> [2023-10-12-17:48:53.485802] Reading config from file /home/culpo/PycharmProjects/spack/etc/spack/defaults/mirrors.yaml
==> [2023-10-12-17:48:53.487457] Reading config from file /home/culpo/.spack/mirrors.yaml
==> [2023-10-12-17:48:53.489167] Reading config from file /home/culpo/.spack/linux/compilers.yaml
==> [2023-10-12-17:48:53.594832] Adding package linux-headers@6.5.2 to mirror
==> [2023-10-12-17:48:53.605556] Checking existence of https://mirror.spack.io/_source-cache/archive/20/2027e14057d568ad3ddc100dadf4c8853a49b031270478a61d88f6011572650f.tar.xz
==> [2023-10-12-17:48:54.335786] Failure reading URL: HEAD https://mirror.spack.io/_source-cache/archive/20/2027e14057d568ad3ddc100dadf4c8853a49b031270478a61d88f6011572650f.tar.xz returned 404: Not Found
==> [2023-10-12-17:48:54.336186] URL does not exist: https://mirror.spack.io/_source-cache/archive/20/2027e14057d568ad3ddc100dadf4c8853a49b031270478a61d88f6011572650f.tar.xz
==> [2023-10-12-17:48:54.336515] FailedDownloadError: Failed to fetch file from URL: https://mirror.spack.io/_source-cache/archive/20/2027e14057d568ad3ddc100dadf4c8853a49b031270478a61d88f6011572650f.tar.xz
==> [2023-10-12-17:48:54.336702] Checking existence of https://mirror.spack.io/linux-headers/linux-headers-6.5.2.tar.xz
==> [2023-10-12-17:48:55.053323] Failure reading URL: HEAD https://mirror.spack.io/linux-headers/linux-headers-6.5.2.tar.xz returned 404: Not Found
==> [2023-10-12-17:48:55.053823] URL does not exist: https://mirror.spack.io/linux-headers/linux-headers-6.5.2.tar.xz
==> [2023-10-12-17:48:55.054249] FailedDownloadError: Failed to fetch file from URL: https://mirror.spack.io/linux-headers/linux-headers-6.5.2.tar.xz
==> [2023-10-12-17:48:55.054504] Checking existence of https://www.kernel.org/pub/linux/kernel/v4.x/linux-6.5.2.tar.xz
==> [2023-10-12-17:48:55.255173] Failure reading URL: GET https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/linux-6.5.2.tar.xz returned 404: Not Found
==> [2023-10-12-17:48:55.255549] URL does not exist: https://www.kernel.org/pub/linux/kernel/v4.x/linux-6.5.2.tar.xz
==> [2023-10-12-17:48:55.255852] FailedDownloadError: Failed to fetch file from URL: https://www.kernel.org/pub/linux/kernel/v4.x/linux-6.5.2.tar.xz
==> [2023-10-12-17:48:55.261950] SPIDER: [depth=0, max_depth=2, urls=4]
==> [2023-10-12-17:48:55.527003] SPIDER: [url=ParseResult(scheme='https', netloc='www.kernel.org', path='/pub/linux/kernel/', params='', query='', fragment='')]
==> [2023-10-12-17:48:56.474188] SPIDER: [url=ParseResult(scheme='https', netloc='www.kernel.org', path='/pub/linux/kernel', params='', query='', fragment='')]
==> [2023-10-12-17:48:58.066214] SPIDER: [url=ParseResult(scheme='https', netloc='www.kernel.org', path='/pub/linux/kernel/v4.x/', params='', query='', fragment='')]
==> [2023-10-12-17:48:58.246657] SPIDER: [url=ParseResult(scheme='https', netloc='www.kernel.org', path='/pub/linux/kernel/v4.x', params='', query='', fragment='')]
==> [2023-10-12-17:48:58.302831] SPIDER: [depth=1, max_depth=2, urls=8412]
==> [2023-10-12-17:48:58.674989] SPIDER: [url=https://mirrors.edge.kernel.org/pub/linux/kernel/v6.x]
==> [2023-10-12-17:48:58.760078] SPIDER: [url=https://mirrors.edge.kernel.org/pub/linux/kernel/v2.4]
==> [2023-10-12-17:48:58.776722] SPIDER: [url=https://mirrors.edge.kernel.org/pub/linux/kernel/v2.6]
==> [2023-10-12-17:48:58.786674] SPIDER: [url=https://mirrors.edge.kernel.org/pub/linux/kernel/v2.5]
==> [2023-10-12-17:48:59.004107] SPIDER: [url=https://mirrors.edge.kernel.org/pub/linux/kernel/v2.2]
==> [2023-10-12-17:48:59.019138] SPIDER: [url=https://mirrors.edge.kernel.org/pub/linux/kernel/v2.3]
==> [2023-10-12-17:48:59.101995] SPIDER: [url=https://mirrors.edge.kernel.org/pub/linux/kernel/v2.0]
==> [2023-10-12-17:48:59.262970] SPIDER: [url=https://mirrors.edge.kernel.org/pub/linux/kernel/v2.1]
==> [2023-10-12-17:48:59.274510] SPIDER: [url=https://mirrors.edge.kernel.org/pub/linux/kernel/v1.2]
==> [2023-10-12-17:48:59.399089] SPIDER: [url=https://mirrors.edge.kernel.org/pub/linux/kernel/v5.x]
==> [2023-10-12-17:48:59.431101] SPIDER: [url=https://mirrors.edge.kernel.org/pub/linux/kernel/v1.1]
==> [2023-10-12-17:48:59.440714] SPIDER: [url=https://mirrors.edge.kernel.org/pub/linux/kernel/v1.3]
==> [2023-10-12-17:48:59.466659] SPIDER: [url=https://mirrors.edge.kernel.org/pub/linux/kernel/v1.0]
==> [2023-10-12-17:48:59.477043] SPIDER: [url=https://mirrors.edge.kernel.org/pub/linux/kernel/uemacs]
==> [2023-10-12-17:48:59.601272] SPIDER: [url=https://mirrors.edge.kernel.org/pub/linux/kernel/tools]
==> [2023-10-12-17:48:59.630836] SPIDER: [url=https://mirrors.edge.kernel.org/pub/linux/kernel/testing]
==> [2023-10-12-17:48:59.633600] SPIDER: [url=https://mirrors.edge.kernel.org/pub/linux/kernel/projects]
==> [2023-10-12-17:48:59.686615] SPIDER: [url=https://mirrors.edge.kernel.org/pub/linux/kernel/ports]
==> [2023-10-12-17:48:59.785551] SPIDER: [url=https://mirrors.edge.kernel.org/pub/linux/kernel/people]
==> [2023-10-12-17:48:59.855315] SPIDER: [url=https://mirrors.edge.kernel.org/pub/linux/kernel/crypto]
==> [2023-10-12-17:48:59.890501] SPIDER: [url=https://mirrors.edge.kernel.org/pub/linux/kernel/SillySounds]
==> [2023-10-12-17:48:59.893449] SPIDER: [url=https://mirrors.edge.kernel.org/pub/linux/kernel/firmware]
==> [2023-10-12-17:48:59.986555] SPIDER: [url=https://mirrors.edge.kernel.org/pub/linux/kernel/Historic]
==> [2023-10-12-17:48:59.999173] ignoring page https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/patch-4.9.sign with content type text/plain
==> [2023-10-12-17:48:59.999379] SPIDER: [url=https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/patch-4.9.sign]
==> [2023-10-12-17:49:00.003118] ignoring page https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/sha256sums.asc with content type text/plain
==> [2023-10-12-17:49:00.003341] SPIDER: [url=https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/sha256sums.asc]
==> [2023-10-12-17:49:00.007522] SPIDER: [url=https://mirrors.edge.kernel.org/pub/linux/kernel/v3.x]
==> [2023-10-12-17:49:00.055845] SPIDER: [url=https://mirrors.edge.kernel.org/pub/linux]
==> [2023-10-12-17:49:00.085189] ignoring page https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/patch-4.9.99.sign with content type text/plain
==> [2023-10-12-17:49:00.085385] SPIDER: [url=https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/patch-4.9.99.sign]
==> [2023-10-12-17:49:00.087989] SPIDER: [url=https://mirrors.edge.kernel.org/pub/linux/kernel/v3.0]
[ ... endless spidering ... ]
```

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/linux-headers/package.py b/var/spack/repos/builtin/packages/linux-headers/package.py
--- a/var/spack/repos/builtin/packages/linux-headers/package.py
+++ b/var/spack/repos/builtin/packages/linux-headers/package.py
@@ -20,6 +20,10 @@ class LinuxHeaders(Package):
     version("6.2.8", sha256="fed0ad87d42f83a70ce019ff2800bc30a855e672e72bf6d54a014d98d344f665")
     version("4.9.10", sha256="bd6e05476fd8d9ea4945e11598d87bc97806bbc8d03556abbaaf809707661525")
 
+    def url_for_version(self, version):
+        url = "https://www.kernel.org/pub/linux/kernel/v{0}.x/linux-{1}.tar.xz"
+        return url.format(version.up_to(1), version)
+
     def setup_build_environment(self, env):
         # This variable is used in the Makefile. If it is defined on the
         # system, it can break the build if there is no build recipe for


Test patch: