Skip to content

Commit

Permalink
WIP updater
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiskae committed Sep 29, 2023
1 parent 5042673 commit b477d66
Show file tree
Hide file tree
Showing 31 changed files with 799 additions and 33 deletions.
67 changes: 60 additions & 7 deletions dev/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 21 additions & 17 deletions dev/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,32 @@

treefmt-nix.url = "github:numtide/treefmt-nix";
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";

flake-parts.url = "github:hercules-ci/flake-parts";
flake-root.url = "github:srid/flake-root";
};

outputs = {
self,
nixpkgs,
outputs = inputs @ {
flake-parts,
systems,
treefmt-nix,
...
}: let
# Small tool to iterate over each systems
eachSystem = f: nixpkgs.lib.genAttrs (import systems) (system: f nixpkgs.legacyPackages.${system});

# Eval the treefmt modules from ./treefmt.nix
treefmtEval = eachSystem (pkgs: treefmt-nix.lib.evalModule pkgs ./treefmt.nix);
in {
# for `nix fmt`
formatter = eachSystem (pkgs: treefmtEval.${pkgs.system}.config.build.wrapper);
# for `nix flake check`
checks = eachSystem (pkgs: {
formatting = treefmtEval.${pkgs.sytem}.config.build.check self;
}:
flake-parts.lib.mkFlake {inherit inputs;} ({self, ...}: {
flake = {
inherit (inputs.flake) nixosModules overlays;
};
debug = true;
systems = import systems;
imports = [
./treefmt.nix
./updater/module.nix
];
perSystem = {pkgs, ...}: {
packages = let
nvPkgs = (pkgs.extend self.overlays.default).nvidiaPackages;
in {driver = nvPkgs.driver.test;};
};
});
};

/*
Expand Down
35 changes: 28 additions & 7 deletions dev/treefmt.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
{pkgs, ...}: {
projectRootFile = ".git/config";
programs.alejandra.enable = true;
programs.black.enable = true;
programs.isort = {
enable = true;
profile = "black";
{
lib,
inputs,
...
}: {
imports = [
inputs.treefmt-nix.flakeModule
];

perSystem = {
pkgs,
config,
...
}: {
treefmt = {
inherit (config.flake-root) projectRootFile;

# Nix
programs.alejandra.enable = true;
programs.statix.enable = true;

# Python
programs.black.enable = true;
programs.isort = {
enable = true;
profile = "black";
};
};
};
}
103 changes: 103 additions & 0 deletions dev/updater/module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{inputs, ...}: {
imports = [
inputs.flake-root.flakeModule
];

perSystem = {
pkgs,
config,
...
}: {
flake-root.projectRootFile = "pkgs/overlay.nix";

devShells.update = let
inherit (pkgs) lib python3 formats;

pytools = python3.withPackages (ps: [
ps.nvchecker
ps.lxml
]);

extra_sources = lib.fileset.toSource {
root = ./.;
fileset = ./nvchecker_source;
};

configFormat = formats.toml {};
configFile = configFormat.generate "nvchecker.toml" {
"__config__" = {
"oldver" = "\${FLAKE_ROOT}/pkgs/refs.json";
#"newver" = "\${FLAKE_ROOT}/dev/current-versions.json";
};
"driver.vulkan-dev" = {
source = "htmlparser";
prefix = "Linux ";
include_regex = "^Linux [.0-9]+$";
url = "https://developer.nvidia.com/vulkan-driver";
xpath = ''//*[@id="content"]/div/section/h3'';
};
"driver.display" = {
source = "unix_drivers";
known = lib.mapAttrsToList (match: data:
{
inherit match;
}
// data) {
"Production Branch Version" = {
maturity = "long-lived-branch-release";
};
"New Feature Branch Version" = {};
"Beta Version" = {
maturity = "beta";
};
"Legacy GPU version (470.xx series)" = {
branch = "R470_00";
};
"Legacy GPU version (390.xx series)" = {
branch = "R390_00";
};
"Legacy GPU version (340.xx series)" = {
branch = "R340_00";
};
"Legacy GPU version (304.xx series)" = {
branch = "R304_00";
};
"Legacy GPU Version (71.86.xx series)" = {
branch = "L7160";
};
"Legacy GPU Version (96.43.xx series)" = {
branch = "L9622";
};
"Legacy GPU Version (173.14.xx series)" = {
branch = "R173_14";
};
};
};
"driver.tesla" = {
source = "tesla_releases";
url = "https://docs.nvidia.com/datacenter/tesla/drivers/releases.json";
from_pattern = ''(?:[^-]+-)*(.+)'';
to_pattern = ''\1'';
};
};
in
pkgs.mkShell {
packages = [pytools pkgs.jq];

inputsFrom = [config.flake-root.devShell];

env = {
PYTHONPATH = toString extra_sources;
NVCHECKER_CONFIG = toString configFile;
};

shellHook = ''
export SCRATCHDIR=$(mktemp -d)
nvchecker -c ''${NVCHECKER_CONFIG}
exit
'';
};
};
}
27 changes: 27 additions & 0 deletions dev/updater/nvchecker_source/tesla_releases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import asyncio

from nvchecker.api import AsyncCache, BaseWorker, RawResult


class Worker(BaseWorker):
async def run(self) -> None:
self.cache = AsyncCache()
await asyncio.gather(
*[self._run_entry(name, entry) for (name, entry) in self.tasks]
)

async def _run_entry(self, name, entry):
async with self.task_sem:
data = await self.cache.get_json(entry["url"])
for branch, data in data.items():
versions = [
f"{r['release_date']}-{r['release_version']}"
for r in data["driver_info"]
]
await self.result_q.put(
RawResult(
f"{name}.r{branch}",
versions,
entry,
)
)
61 changes: 61 additions & 0 deletions dev/updater/nvchecker_source/unix_drivers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import re

from nvchecker.api import BaseWorker, RawResult, session

PATTERN = re.compile(rb"Latest (?P<label>[^:]+)[^>]+>\s*(?P<version>[^<]+)</a>")


class Worker(BaseWorker):
async def get_data(self, url):
for match in PATTERN.finditer(res.body):
yield match.groupdict()

async def get_unix_results(self, url):
results = {}
res = await session.get(url)

for match in PATTERN.finditer(res.body):
label = match["label"].lower()
versions = results.get(label) or set()
versions.add(match["version"].decode("UTF-8"))
if label not in results:
results[label] = versions

return results

def match_label(self, label: str, known_entries):
for known in known_entries:
if known["match"].lower() in label:
return (
known.get("branch", "current"),
known.get("maturity", "official"),
)

return (None, None)

async def run(self) -> None:
results = None
async with self.task_sem:
results = await self.get_unix_results(
"https://www.nvidia.com/en-us/drivers/unix/"
)

for name, entry in self.tasks:
known_entries = entry.get("known")

async with self.task_sem:
for label, versions in results.items():
label_str = label.decode("UTF-8")
(branch, maturity) = self.match_label(label_str, known_entries)

new_name = f"{name}.unknown.{label_str}"
if branch:
new_name = f"{name}.{branch}.{maturity}"

await self.result_q.put(
RawResult(
new_name,
list(versions),
entry,
)
)
Loading

0 comments on commit b477d66

Please sign in to comment.