mirror of
https://github.com/xddxdd/nix-cachyos-kernel.git
synced 2026-07-03 11:08:07 +02:00
Use alternative method to get ZFS versions
This commit is contained in:
parent
c273e8c996
commit
c73f2fdbf7
14
flake.nix
14
flake.nix
@ -56,12 +56,14 @@
|
|||||||
kernels
|
kernels
|
||||||
// packages
|
// packages
|
||||||
// {
|
// {
|
||||||
zfs-cachyos = packages.linuxPackages-cachyos-latest.callPackage ./zfs-cachyos {
|
zfs-cachyos = packages.linuxPackages-cachyos-latest.zfs_cachyos;
|
||||||
inherit inputs;
|
zfs-cachyos-lto = packages.linuxPackages-cachyos-latest-lto.zfs_cachyos;
|
||||||
};
|
zfs-cachyos-lts = packages.linuxPackages-cachyos-lts.zfs_cachyos;
|
||||||
zfs-cachyos-lto = packages.linuxPackages-cachyos-latest-lto.callPackage ./zfs-cachyos {
|
zfs-cachyos-lts-lto = packages.linuxPackages-cachyos-lts-lto.zfs_cachyos;
|
||||||
inherit inputs;
|
zfs-cachyos-hardened = packages.linuxPackages-cachyos-hardened.zfs_cachyos;
|
||||||
};
|
zfs-cachyos-hardened-lto = packages.linuxPackages-cachyos-hardened-lto.zfs_cachyos;
|
||||||
|
zfs-cachyos-rc = packages.linuxPackages-cachyos-rc.zfs_cachyos;
|
||||||
|
zfs-cachyos-rc-lto = packages.linuxPackages-cachyos-rc-lto.zfs_cachyos;
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
rec {
|
rec {
|
||||||
|
|||||||
@ -210,6 +210,7 @@ lib.makeOverridable (
|
|||||||
|
|
||||||
extraPassthru = {
|
extraPassthru = {
|
||||||
inherit cachyosConfigFile cachyosPatches;
|
inherit cachyosConfigFile cachyosPatches;
|
||||||
|
cachyosConfigVariant = configVariant;
|
||||||
}
|
}
|
||||||
// (args.extraPassthru or { });
|
// (args.extraPassthru or { });
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,10 +16,15 @@ lib.mapAttrs' (
|
|||||||
let
|
let
|
||||||
packages = kernelModuleLLVMOverride (
|
packages = kernelModuleLLVMOverride (
|
||||||
(linuxKernel.packagesFor v).extend (
|
(linuxKernel.packagesFor v).extend (
|
||||||
final: prev: {
|
final: prev:
|
||||||
zfs_cachyos = final.callPackage ../zfs-cachyos {
|
let
|
||||||
|
zfsVariant = lib.removePrefix "linux-cachyos-" v.cachyosConfigVariant;
|
||||||
|
zfsPackages = final.callPackage ../zfs-cachyos {
|
||||||
inherit inputs;
|
inherit inputs;
|
||||||
};
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
zfs_cachyos = zfsPackages."${zfsVariant}" or zfsPackages.latest;
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
@ -30,7 +30,7 @@ def get_srctag(variant: str = "latest") -> str:
|
|||||||
|
|
||||||
|
|
||||||
def nix_sha256_to_sri(hash: str) -> str:
|
def nix_sha256_to_sri(hash: str) -> str:
|
||||||
cmd = ["nix", "hash", "convert", "--hash-algo", "sha256", "--to", "sri", hash]
|
cmd = ["nix", "hash", "to-sri", "--type", "sha256", hash]
|
||||||
|
|
||||||
print(f"Running command: {' '.join(cmd)}")
|
print(f"Running command: {' '.join(cmd)}")
|
||||||
result = subprocess.run(cmd, capture_output=True, text=True, timeout=300)
|
result = subprocess.run(cmd, capture_output=True, text=True, timeout=300)
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
callPackage,
|
callPackage,
|
||||||
kernel ? null,
|
kernel ? null,
|
||||||
lib,
|
lib,
|
||||||
fetchFromGitHub,
|
fetchurl,
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
versionJson = lib.importJSON ./version.json;
|
versionJson = lib.importJSON ./version.json;
|
||||||
@ -12,24 +12,28 @@ let
|
|||||||
};
|
};
|
||||||
in
|
in
|
||||||
# https://github.com/chaotic-cx/nyx/blob/aacb796ccd42be1555196c20013b9b674b71df75/pkgs/linux-cachyos/packages-for.nix#L99
|
# https://github.com/chaotic-cx/nyx/blob/aacb796ccd42be1555196c20013b9b674b71df75/pkgs/linux-cachyos/packages-for.nix#L99
|
||||||
(zfsGeneric {
|
lib.mapAttrs (
|
||||||
kernelModuleAttribute = "zfs_cachyos";
|
variant: metadata:
|
||||||
kernelMinSupportedMajorMinor = "1.0";
|
(zfsGeneric {
|
||||||
kernelMaxSupportedMajorMinor = "99.99";
|
kernelModuleAttribute = "zfs_cachyos";
|
||||||
enableUnsupportedExperimentalKernel = true;
|
kernelMinSupportedMajorMinor = "1.0";
|
||||||
version = builtins.elemAt (lib.splitString "-" versionJson.zfs_branch) 1;
|
kernelMaxSupportedMajorMinor = "99.99";
|
||||||
tests = { };
|
enableUnsupportedExperimentalKernel = true;
|
||||||
maintainers = with lib.maintainers; [
|
version = metadata.version;
|
||||||
pedrohlc
|
tests = { };
|
||||||
];
|
maintainers = with lib.maintainers; [
|
||||||
hash = "";
|
pedrohlc
|
||||||
extraPatches = [ ];
|
];
|
||||||
}).overrideAttrs
|
hash = "";
|
||||||
(prevAttrs: {
|
extraPatches = [ ];
|
||||||
src = fetchFromGitHub {
|
}).overrideAttrs
|
||||||
owner = "cachyos";
|
(prevAttrs: {
|
||||||
repo = "zfs";
|
src = fetchurl {
|
||||||
inherit (versionJson) rev hash;
|
inherit (metadata) url hash;
|
||||||
};
|
};
|
||||||
postPatch = builtins.replaceStrings [ "grep --quiet '^Linux-M" ] [ "# " ] prevAttrs.postPatch;
|
postPatch = builtins.replaceStrings [ "grep --quiet '^Linux-M" ] [ "# " ] prevAttrs.postPatch;
|
||||||
})
|
passthru = prevAttrs.passthru // {
|
||||||
|
cachyosVariant = variant;
|
||||||
|
};
|
||||||
|
})
|
||||||
|
) versionJson
|
||||||
|
|||||||
@ -1,118 +1,96 @@
|
|||||||
#!/usr/bin/env nix-shell
|
|
||||||
#!nix-shell -i python3 -p python3 -p python3Packages.requests -p nix-prefetch-git
|
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
|
||||||
import re
|
import re
|
||||||
import subprocess
|
|
||||||
import sys
|
|
||||||
from pathlib import Path
|
|
||||||
from typing import Dict, Any, Optional
|
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
import subprocess
|
||||||
|
import tempfile
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
def get_latest_zfs_cachyos_branch() -> Optional[str]:
|
def get_zfs_commit(variant: str = "latest") -> str:
|
||||||
api_url = "https://api.github.com/repos/CachyOS/zfs/branches"
|
with tempfile.TemporaryDirectory(ignore_cleanup_errors=True) as dir:
|
||||||
all_branches = []
|
subprocess.run(
|
||||||
page = 1
|
["nix", "build", ".#cachyos-kernel-input-path", "-o", f"{dir}/result"],
|
||||||
per_page = 100 # Maximum allowed
|
check=True,
|
||||||
|
)
|
||||||
|
|
||||||
# Setup headers for GitHub API authentication if token is available
|
pkgbuild_path = f"linux-cachyos-{variant}" if variant != "latest" else "linux-cachyos"
|
||||||
headers = {}
|
|
||||||
github_token = os.environ.get("GITHUB_TOKEN")
|
|
||||||
if github_token:
|
|
||||||
headers["Authorization"] = f"token {github_token}"
|
|
||||||
|
|
||||||
while True:
|
with open(f"{dir}/result/{pkgbuild_path}/PKGBUILD") as f:
|
||||||
params = {"per_page": per_page, "page": page}
|
pkgbuild = f.read()
|
||||||
response = requests.get(api_url, params=params, headers=headers, timeout=30)
|
|
||||||
response.raise_for_status()
|
|
||||||
|
|
||||||
branches = response.json()
|
commit = re.search(r"zfs.git#commit=([0-9a-f]{40})", pkgbuild)
|
||||||
if not branches:
|
if not commit:
|
||||||
break
|
raise ValueError(f"Cannot find ZFS commit ID for {variant=}")
|
||||||
|
return commit[1]
|
||||||
all_branches.extend(branches)
|
|
||||||
page += 1
|
|
||||||
|
|
||||||
# If we got less than per_page results, we're on the last page
|
|
||||||
if len(branches) < per_page:
|
|
||||||
break
|
|
||||||
|
|
||||||
cachyos_branches = []
|
|
||||||
|
|
||||||
branch_pattern = re.compile(r"^zfs-\d+\.\d+\.\d+-cachyos$")
|
|
||||||
|
|
||||||
for branch in all_branches:
|
|
||||||
branch_name = branch.get("name", "")
|
|
||||||
if branch_pattern.match(branch_name):
|
|
||||||
cachyos_branches.append(branch_name)
|
|
||||||
|
|
||||||
if not cachyos_branches:
|
|
||||||
print("No branch found matching zfs-x.y.z-cachyos or x.y.z-cachyos pattern")
|
|
||||||
return None
|
|
||||||
|
|
||||||
cachyos_branches.sort(reverse=True)
|
|
||||||
latest_branch = cachyos_branches[0]
|
|
||||||
print(f"Found latest branch: {latest_branch}")
|
|
||||||
return latest_branch
|
|
||||||
|
|
||||||
|
|
||||||
def run_nix_prefetch_git(branch: str) -> Optional[Dict[str, Any]]:
|
def get_zfs_version(commit: str) -> str:
|
||||||
cmd = ["nix-prefetch-git", "https://github.com/CachyOS/zfs.git", "--rev", f"refs/heads/{branch}"]
|
url = f"https://raw.githubusercontent.com/CachyOS/zfs/{commit}/META"
|
||||||
|
print(f"{url=}")
|
||||||
|
metadata = requests.get(url).text
|
||||||
|
version = re.search(r"^Version:\s+([0-9\.]+)$", metadata, re.MULTILINE)
|
||||||
|
return version[1]
|
||||||
|
|
||||||
|
|
||||||
|
def nix_sha256_to_sri(hash: str) -> str:
|
||||||
|
cmd = ["nix", "hash", "to-sri", "--type", "sha256", hash]
|
||||||
|
|
||||||
print(f"Running command: {' '.join(cmd)}")
|
print(f"Running command: {' '.join(cmd)}")
|
||||||
result = subprocess.run(cmd, capture_output=True, text=True, timeout=300)
|
result = subprocess.run(cmd, capture_output=True, text=True, timeout=300)
|
||||||
|
|
||||||
if result.returncode != 0:
|
if result.returncode != 0:
|
||||||
print(f"nix-prefetch-git command failed with return code: {result.returncode}")
|
raise RuntimeError(f"nix hash command failed with return code: {result.returncode}")
|
||||||
print(f"Error output: {result.stderr}")
|
|
||||||
return None
|
|
||||||
|
|
||||||
output = result.stdout.strip()
|
output = result.stdout.strip()
|
||||||
if not output:
|
if not output:
|
||||||
print("nix-prefetch-git output is empty")
|
raise RuntimeError("nix hash output is empty")
|
||||||
return None
|
|
||||||
|
|
||||||
parsed_output = json.loads(output)
|
return output
|
||||||
return parsed_output
|
|
||||||
|
|
||||||
|
|
||||||
def save_version_info(branch: str, prefetch_data: Dict[str, Any], output_file: Path):
|
def run_nix_prefetch_url(url: str) -> str:
|
||||||
with open(output_file, "w", encoding="utf-8") as f:
|
cmd = ["nix-prefetch-url", url]
|
||||||
json.dump({"zfs_branch": branch, **prefetch_data}, f, indent=2)
|
|
||||||
|
|
||||||
print(f"Version info saved to: {output_file}")
|
print(f"Running command: {' '.join(cmd)}")
|
||||||
|
result = subprocess.run(cmd, capture_output=True, text=True, timeout=300)
|
||||||
|
|
||||||
|
if result.returncode != 0:
|
||||||
|
raise RuntimeError(f"nix-prefetch-url command failed with return code: {result.returncode}")
|
||||||
|
|
||||||
|
output = result.stdout.strip()
|
||||||
|
if not output:
|
||||||
|
raise RuntimeError("nix-prefetch-url output is empty")
|
||||||
|
|
||||||
|
return output
|
||||||
|
|
||||||
|
|
||||||
def main() -> int:
|
if __name__ == "__main__":
|
||||||
print("Starting ZFS CachyOS version update...")
|
versions = {}
|
||||||
|
for variant in ["latest", "lts", "rc", "hardened"]:
|
||||||
|
print(f"{variant=}")
|
||||||
|
commit = get_zfs_commit(variant)
|
||||||
|
print(f"{commit=}")
|
||||||
|
version = get_zfs_version(commit)
|
||||||
|
print(f"{version=}")
|
||||||
|
|
||||||
latest_branch = get_latest_zfs_cachyos_branch()
|
url = f"https://github.com/CachyOS/zfs/archive/{commit}.tar.gz"
|
||||||
if not latest_branch:
|
print(f"{url=}")
|
||||||
print("Failed to get latest branch, exiting")
|
hash = run_nix_prefetch_url(url)
|
||||||
return 1
|
hash = nix_sha256_to_sri(hash)
|
||||||
|
print(f"{hash=}")
|
||||||
prefetch_data = run_nix_prefetch_git(latest_branch)
|
versions[variant] = {
|
||||||
if not prefetch_data:
|
"commit": commit,
|
||||||
print("nix-prefetch-git execution failed, exiting")
|
"version": version,
|
||||||
return 1
|
"url": url,
|
||||||
|
"hash": hash,
|
||||||
|
}
|
||||||
|
|
||||||
current = Path.cwd()
|
current = Path.cwd()
|
||||||
while not (current / "flake.lock").exists():
|
while not (current / "flake.lock").exists():
|
||||||
if current == current.parent:
|
if current == current.parent:
|
||||||
print("Could not find flake.lock in any parent directory, exiting")
|
raise RuntimeError("Could not find flake.lock in any parent directory, exiting")
|
||||||
return 1
|
|
||||||
current = current.parent
|
current = current.parent
|
||||||
|
|
||||||
output_file = current / "zfs-cachyos" / "version.json"
|
output_file = current / "zfs-cachyos" / "version.json"
|
||||||
|
with open(output_file, "w", encoding="utf-8") as f:
|
||||||
save_version_info(latest_branch, prefetch_data, output_file)
|
json.dump(versions, f, indent=2)
|
||||||
|
|
||||||
print("ZFS CachyOS version info update completed!")
|
|
||||||
return 0
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
sys.exit(main())
|
|
||||||
|
|||||||
@ -1,15 +1,26 @@
|
|||||||
{
|
{
|
||||||
"zfs_branch": "zfs-2.4.1-cachyos",
|
"latest": {
|
||||||
"url": "https://github.com/CachyOS/zfs.git",
|
"commit": "1c702dda346a59e05cfd3029569bbb1d5d91c54b",
|
||||||
"rev": "6132f5bc08f2b3f86677ac9f3a12a688eb984d11",
|
"version": "2.4.1",
|
||||||
"date": "2026-04-04T11:51:55+02:00",
|
"url": "https://github.com/CachyOS/zfs/archive/1c702dda346a59e05cfd3029569bbb1d5d91c54b.tar.gz",
|
||||||
"path": "/nix/store/c7r3s6xdqv4msig9d34jffsfy44wbkvg-zfs",
|
"hash": "sha256-wu+yhK06AAVEvaTmnh3OvGKi1mi3LIR9FqS9Fa1/k9w="
|
||||||
"sha256": "1wlmyyczcm8fhcirjgb580vh7rh1n21493gyblrrrk4c39fvf524",
|
},
|
||||||
"hash": "sha256-RBS3XRqMzJwzXf6NRIKwAeYDN0BlPZkjgw5V9pn3lfI=",
|
"lts": {
|
||||||
"fetchLFS": false,
|
"commit": "1c702dda346a59e05cfd3029569bbb1d5d91c54b",
|
||||||
"fetchSubmodules": false,
|
"version": "2.4.1",
|
||||||
"deepClone": false,
|
"url": "https://github.com/CachyOS/zfs/archive/1c702dda346a59e05cfd3029569bbb1d5d91c54b.tar.gz",
|
||||||
"fetchTags": false,
|
"hash": "sha256-wu+yhK06AAVEvaTmnh3OvGKi1mi3LIR9FqS9Fa1/k9w="
|
||||||
"leaveDotGit": false,
|
},
|
||||||
"rootDir": ""
|
"rc": {
|
||||||
|
"commit": "0829cf892b5d7b3a0e8aa76cc7aca02b84f62557",
|
||||||
|
"version": "2.4.1",
|
||||||
|
"url": "https://github.com/CachyOS/zfs/archive/0829cf892b5d7b3a0e8aa76cc7aca02b84f62557.tar.gz",
|
||||||
|
"hash": "sha256-39nZNnXeGrUhyt7Qa8hkQusLepAfctsBLRbMcENVrvU="
|
||||||
|
},
|
||||||
|
"hardened": {
|
||||||
|
"commit": "1c702dda346a59e05cfd3029569bbb1d5d91c54b",
|
||||||
|
"version": "2.4.1",
|
||||||
|
"url": "https://github.com/CachyOS/zfs/archive/1c702dda346a59e05cfd3029569bbb1d5d91c54b.tar.gz",
|
||||||
|
"hash": "sha256-wu+yhK06AAVEvaTmnh3OvGKi1mi3LIR9FqS9Fa1/k9w="
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user