check upstream cache
This commit is contained in:
parent
05bfb4c491
commit
073755deeb
5 changed files with 1595 additions and 30 deletions
1494
Cargo.lock
generated
1494
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -6,5 +6,7 @@ edition = "2024"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
env_logger = "0.11.7"
|
env_logger = "0.11.7"
|
||||||
log = "0.4.27"
|
log = "0.4.27"
|
||||||
|
reqwest = "0.12.15"
|
||||||
serde = { version = "1.0.219", features = [ "derive" ]}
|
serde = { version = "1.0.219", features = [ "derive" ]}
|
||||||
serde_json = "1.0.140"
|
serde_json = "1.0.140"
|
||||||
|
tokio = { version = "1.44.1", features = [ "full" ]}
|
||||||
|
|
61
flake.lock
generated
Normal file
61
flake.lock
generated
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"flake-parts": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs-lib": "nixpkgs-lib"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1741352980,
|
||||||
|
"narHash": "sha256-+u2UunDA4Cl5Fci3m7S643HzKmIDAe+fiXrLqYsR2fs=",
|
||||||
|
"owner": "hercules-ci",
|
||||||
|
"repo": "flake-parts",
|
||||||
|
"rev": "f4330d22f1c5d2ba72d3d22df5597d123fdb60a9",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "hercules-ci",
|
||||||
|
"repo": "flake-parts",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1743315132,
|
||||||
|
"narHash": "sha256-6hl6L/tRnwubHcA4pfUUtk542wn2Om+D4UnDhlDW9BE=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "52faf482a3889b7619003c0daec593a1912fddc1",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixos-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs-lib": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1740877520,
|
||||||
|
"narHash": "sha256-oiwv/ZK/2FhGxrCkQkB83i7GnWXPPLzoqFHpDD3uYpk=",
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "nixpkgs.lib",
|
||||||
|
"rev": "147dee35aab2193b174e4c0868bd80ead5ce755c",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "nixpkgs.lib",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-parts": "flake-parts",
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
23
flake.nix
Normal file
23
flake.nix
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
{
|
||||||
|
description = "Description for the project";
|
||||||
|
|
||||||
|
inputs = {
|
||||||
|
flake-parts.url = "github:hercules-ci/flake-parts";
|
||||||
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = inputs@{ flake-parts, ... }:
|
||||||
|
flake-parts.lib.mkFlake { inherit inputs; } {
|
||||||
|
systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ];
|
||||||
|
perSystem = { config, self', inputs', pkgs, system, ... }: {
|
||||||
|
devShells.default = pkgs.mkShell {
|
||||||
|
nativeBuildInputs = with pkgs; [
|
||||||
|
pkg-config
|
||||||
|
];
|
||||||
|
buildInputs = with pkgs; [
|
||||||
|
openssl
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
45
src/main.rs
45
src/main.rs
|
@ -1,12 +1,10 @@
|
||||||
#![feature(string_from_utf8_lossy_owned)]
|
|
||||||
|
|
||||||
use std::{env, path::Path};
|
use std::{env, path::Path};
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json;
|
use serde_json;
|
||||||
use log::debug;
|
use log::debug;
|
||||||
|
use tokio;
|
||||||
|
|
||||||
const UPSTREAM_CACHES: &'static [&'static str] = &[
|
const UPSTREAM_CACHES: &'static [&'static str] = &[
|
||||||
"https://cache.nixos.org",
|
"https://cache.nixos.org",
|
||||||
|
@ -28,6 +26,21 @@ struct PathInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PathInfo {
|
impl PathInfo {
|
||||||
|
// find derivations related to package
|
||||||
|
fn from_package(package: &str) -> Vec<Self> {
|
||||||
|
let path_infos = Command::new("nix")
|
||||||
|
.arg("path-info")
|
||||||
|
.arg("--derivation")
|
||||||
|
.arg("--json")
|
||||||
|
.arg(package)
|
||||||
|
.output()
|
||||||
|
.expect("path-info failed");
|
||||||
|
|
||||||
|
let path_infos: Vec<PathInfo> = serde_json::from_slice(&path_infos.stdout).unwrap();
|
||||||
|
debug!("PathInfo's from nix path-info: {:#?}", path_infos);
|
||||||
|
path_infos
|
||||||
|
}
|
||||||
|
|
||||||
// find store paths related to derivation
|
// find store paths related to derivation
|
||||||
fn get_store_paths(&self) -> Vec<String> {
|
fn get_store_paths(&self) -> Vec<String> {
|
||||||
let mut store_paths: Vec<String> = Vec::new();
|
let mut store_paths: Vec<String> = Vec::new();
|
||||||
|
@ -47,30 +60,24 @@ impl PathInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
#[tokio::main]
|
||||||
|
async fn main() {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
let args: Vec<String> = env::args().collect();
|
let args: Vec<String> = env::args().collect();
|
||||||
let package = &args[1];
|
let package = &args[1];
|
||||||
println!("package: {}", package);
|
debug!("package: {}", package);
|
||||||
|
let path_infos = PathInfo::from_package(package);
|
||||||
// find derivations related to package
|
|
||||||
let path_infos = Command::new("nix")
|
|
||||||
.arg("path-info")
|
|
||||||
.arg("--derivation")
|
|
||||||
.arg("--json")
|
|
||||||
.arg(package)
|
|
||||||
.output()
|
|
||||||
.expect("path-info failed");
|
|
||||||
|
|
||||||
let path_infos: Vec<PathInfo> = serde_json::from_slice(&path_infos.stdout).unwrap();
|
|
||||||
debug!("PathInfo's from nix path-info: {:#?}", path_infos);
|
|
||||||
|
|
||||||
|
|
||||||
// filter out store paths that exist in upstream caches
|
// filter out store paths that exist in upstream caches
|
||||||
let store_paths = path_infos[0].get_store_paths();
|
let store_paths = path_infos[0].get_store_paths();
|
||||||
for store_path in store_paths {
|
for store_path in store_paths {
|
||||||
let basename = Path::new(&store_path).file_name().unwrap().to_str().unwrap().to_string();
|
let basename = Path::new(&store_path).file_name().unwrap().to_str().unwrap().to_string();
|
||||||
let hash = basename.split("-").nth(0).unwrap();
|
let hash = basename.split("-").nth(0).unwrap();
|
||||||
println!("hash: {}", hash);
|
for upstream in UPSTREAM_CACHES {
|
||||||
|
let mut uri = String::from(*upstream);
|
||||||
|
uri.push_str(format!("/{}.narinfo", hash).as_str());
|
||||||
|
let res_status = reqwest::Client::new().head(uri).send().await.unwrap().status();
|
||||||
|
println!("{} responded with {}", *upstream, res_status);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue