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
|
||||
// packages
|
||||
// {
|
||||
zfs-cachyos = packages.linuxPackages-cachyos-latest.callPackage ./zfs-cachyos {
|
||||
inherit inputs;
|
||||
};
|
||||
zfs-cachyos-lto = packages.linuxPackages-cachyos-latest-lto.callPackage ./zfs-cachyos {
|
||||
inherit inputs;
|
||||
};
|
||||
zfs-cachyos = packages.linuxPackages-cachyos-latest.zfs_cachyos;
|
||||
zfs-cachyos-lto = packages.linuxPackages-cachyos-latest-lto.zfs_cachyos;
|
||||
zfs-cachyos-lts = packages.linuxPackages-cachyos-lts.zfs_cachyos;
|
||||
zfs-cachyos-lts-lto = packages.linuxPackages-cachyos-lts-lto.zfs_cachyos;
|
||||
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
|
||||
rec {
|
||||
|
||||
@ -210,6 +210,7 @@ lib.makeOverridable (
|
||||
|
||||
extraPassthru = {
|
||||
inherit cachyosConfigFile cachyosPatches;
|
||||
cachyosConfigVariant = configVariant;
|
||||
}
|
||||
// (args.extraPassthru or { });
|
||||
}
|
||||
|
||||
@ -16,10 +16,15 @@ lib.mapAttrs' (
|
||||
let
|
||||
packages = kernelModuleLLVMOverride (
|
||||
(linuxKernel.packagesFor v).extend (
|
||||
final: prev: {
|
||||
zfs_cachyos = final.callPackage ../zfs-cachyos {
|
||||
final: prev:
|
||||
let
|
||||
zfsVariant = lib.removePrefix "linux-cachyos-" v.cachyosConfigVariant;
|
||||
zfsPackages = final.callPackage ../zfs-cachyos {
|
||||
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:
|
||||
cmd = ["nix", "hash", "convert", "--hash-algo", "sha256", "--to", "sri", hash]
|
||||
cmd = ["nix", "hash", "to-sri", "--type", "sha256", hash]
|
||||
|
||||
print(f"Running command: {' '.join(cmd)}")
|
||||
result = subprocess.run(cmd, capture_output=True, text=True, timeout=300)
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
callPackage,
|
||||
kernel ? null,
|
||||
lib,
|
||||
fetchFromGitHub,
|
||||
fetchurl,
|
||||
}:
|
||||
let
|
||||
versionJson = lib.importJSON ./version.json;
|
||||
@ -12,12 +12,14 @@ let
|
||||
};
|
||||
in
|
||||
# https://github.com/chaotic-cx/nyx/blob/aacb796ccd42be1555196c20013b9b674b71df75/pkgs/linux-cachyos/packages-for.nix#L99
|
||||
lib.mapAttrs (
|
||||
variant: metadata:
|
||||
(zfsGeneric {
|
||||
kernelModuleAttribute = "zfs_cachyos";
|
||||
kernelMinSupportedMajorMinor = "1.0";
|
||||
kernelMaxSupportedMajorMinor = "99.99";
|
||||
enableUnsupportedExperimentalKernel = true;
|
||||
version = builtins.elemAt (lib.splitString "-" versionJson.zfs_branch) 1;
|
||||
version = metadata.version;
|
||||
tests = { };
|
||||
maintainers = with lib.maintainers; [
|
||||
pedrohlc
|
||||
@ -26,10 +28,12 @@ in
|
||||
extraPatches = [ ];
|
||||
}).overrideAttrs
|
||||
(prevAttrs: {
|
||||
src = fetchFromGitHub {
|
||||
owner = "cachyos";
|
||||
repo = "zfs";
|
||||
inherit (versionJson) rev hash;
|
||||
src = fetchurl {
|
||||
inherit (metadata) url hash;
|
||||
};
|
||||
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 os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Dict, Any, Optional
|
||||
|
||||
import requests
|
||||
import subprocess
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def get_latest_zfs_cachyos_branch() -> Optional[str]:
|
||||
api_url = "https://api.github.com/repos/CachyOS/zfs/branches"
|
||||
all_branches = []
|
||||
page = 1
|
||||
per_page = 100 # Maximum allowed
|
||||
def get_zfs_commit(variant: str = "latest") -> str:
|
||||
with tempfile.TemporaryDirectory(ignore_cleanup_errors=True) as dir:
|
||||
subprocess.run(
|
||||
["nix", "build", ".#cachyos-kernel-input-path", "-o", f"{dir}/result"],
|
||||
check=True,
|
||||
)
|
||||
|
||||
# Setup headers for GitHub API authentication if token is available
|
||||
headers = {}
|
||||
github_token = os.environ.get("GITHUB_TOKEN")
|
||||
if github_token:
|
||||
headers["Authorization"] = f"token {github_token}"
|
||||
pkgbuild_path = f"linux-cachyos-{variant}" if variant != "latest" else "linux-cachyos"
|
||||
|
||||
while True:
|
||||
params = {"per_page": per_page, "page": page}
|
||||
response = requests.get(api_url, params=params, headers=headers, timeout=30)
|
||||
response.raise_for_status()
|
||||
with open(f"{dir}/result/{pkgbuild_path}/PKGBUILD") as f:
|
||||
pkgbuild = f.read()
|
||||
|
||||
branches = response.json()
|
||||
if not branches:
|
||||
break
|
||||
|
||||
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
|
||||
commit = re.search(r"zfs.git#commit=([0-9a-f]{40})", pkgbuild)
|
||||
if not commit:
|
||||
raise ValueError(f"Cannot find ZFS commit ID for {variant=}")
|
||||
return commit[1]
|
||||
|
||||
|
||||
def run_nix_prefetch_git(branch: str) -> Optional[Dict[str, Any]]:
|
||||
cmd = ["nix-prefetch-git", "https://github.com/CachyOS/zfs.git", "--rev", f"refs/heads/{branch}"]
|
||||
def get_zfs_version(commit: str) -> str:
|
||||
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)}")
|
||||
result = subprocess.run(cmd, capture_output=True, text=True, timeout=300)
|
||||
|
||||
if result.returncode != 0:
|
||||
print(f"nix-prefetch-git command failed with return code: {result.returncode}")
|
||||
print(f"Error output: {result.stderr}")
|
||||
return None
|
||||
raise RuntimeError(f"nix hash command failed with return code: {result.returncode}")
|
||||
|
||||
output = result.stdout.strip()
|
||||
if not output:
|
||||
print("nix-prefetch-git output is empty")
|
||||
return None
|
||||
raise RuntimeError("nix hash output is empty")
|
||||
|
||||
parsed_output = json.loads(output)
|
||||
return parsed_output
|
||||
return output
|
||||
|
||||
|
||||
def save_version_info(branch: str, prefetch_data: Dict[str, Any], output_file: Path):
|
||||
with open(output_file, "w", encoding="utf-8") as f:
|
||||
json.dump({"zfs_branch": branch, **prefetch_data}, f, indent=2)
|
||||
def run_nix_prefetch_url(url: str) -> str:
|
||||
cmd = ["nix-prefetch-url", url]
|
||||
|
||||
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:
|
||||
print("Starting ZFS CachyOS version update...")
|
||||
if __name__ == "__main__":
|
||||
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()
|
||||
if not latest_branch:
|
||||
print("Failed to get latest branch, exiting")
|
||||
return 1
|
||||
|
||||
prefetch_data = run_nix_prefetch_git(latest_branch)
|
||||
if not prefetch_data:
|
||||
print("nix-prefetch-git execution failed, exiting")
|
||||
return 1
|
||||
url = f"https://github.com/CachyOS/zfs/archive/{commit}.tar.gz"
|
||||
print(f"{url=}")
|
||||
hash = run_nix_prefetch_url(url)
|
||||
hash = nix_sha256_to_sri(hash)
|
||||
print(f"{hash=}")
|
||||
versions[variant] = {
|
||||
"commit": commit,
|
||||
"version": version,
|
||||
"url": url,
|
||||
"hash": hash,
|
||||
}
|
||||
|
||||
current = Path.cwd()
|
||||
while not (current / "flake.lock").exists():
|
||||
if current == current.parent:
|
||||
print("Could not find flake.lock in any parent directory, exiting")
|
||||
return 1
|
||||
raise RuntimeError("Could not find flake.lock in any parent directory, exiting")
|
||||
current = current.parent
|
||||
|
||||
output_file = current / "zfs-cachyos" / "version.json"
|
||||
|
||||
save_version_info(latest_branch, prefetch_data, output_file)
|
||||
|
||||
print("ZFS CachyOS version info update completed!")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
with open(output_file, "w", encoding="utf-8") as f:
|
||||
json.dump(versions, f, indent=2)
|
||||
|
||||
@ -1,15 +1,26 @@
|
||||
{
|
||||
"zfs_branch": "zfs-2.4.1-cachyos",
|
||||
"url": "https://github.com/CachyOS/zfs.git",
|
||||
"rev": "6132f5bc08f2b3f86677ac9f3a12a688eb984d11",
|
||||
"date": "2026-04-04T11:51:55+02:00",
|
||||
"path": "/nix/store/c7r3s6xdqv4msig9d34jffsfy44wbkvg-zfs",
|
||||
"sha256": "1wlmyyczcm8fhcirjgb580vh7rh1n21493gyblrrrk4c39fvf524",
|
||||
"hash": "sha256-RBS3XRqMzJwzXf6NRIKwAeYDN0BlPZkjgw5V9pn3lfI=",
|
||||
"fetchLFS": false,
|
||||
"fetchSubmodules": false,
|
||||
"deepClone": false,
|
||||
"fetchTags": false,
|
||||
"leaveDotGit": false,
|
||||
"rootDir": ""
|
||||
"latest": {
|
||||
"commit": "1c702dda346a59e05cfd3029569bbb1d5d91c54b",
|
||||
"version": "2.4.1",
|
||||
"url": "https://github.com/CachyOS/zfs/archive/1c702dda346a59e05cfd3029569bbb1d5d91c54b.tar.gz",
|
||||
"hash": "sha256-wu+yhK06AAVEvaTmnh3OvGKi1mi3LIR9FqS9Fa1/k9w="
|
||||
},
|
||||
"lts": {
|
||||
"commit": "1c702dda346a59e05cfd3029569bbb1d5d91c54b",
|
||||
"version": "2.4.1",
|
||||
"url": "https://github.com/CachyOS/zfs/archive/1c702dda346a59e05cfd3029569bbb1d5d91c54b.tar.gz",
|
||||
"hash": "sha256-wu+yhK06AAVEvaTmnh3OvGKi1mi3LIR9FqS9Fa1/k9w="
|
||||
},
|
||||
"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