move license store cache to its own derivation

This commit is contained in:
figsoda 2023-03-12 12:27:55 -04:00
parent aa023a73a7
commit a0a06da5e2
8 changed files with 88 additions and 33 deletions

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
/cache
/data
/result
/result-*
/target

7
Cargo.lock generated
View File

@ -1459,6 +1459,13 @@ dependencies = [
"vcpkg",
]
[[package]]
name = "license-store-cache"
version = "0.1.1"
dependencies = [
"askalono",
]
[[package]]
name = "link-cplusplus"
version = "1.0.8"

View File

@ -1,19 +1,32 @@
[package]
name = "nix-init"
[workspace]
members = ["license-store-cache"]
[workspace.package]
version = "0.1.1"
authors = ["figsoda <figsoda@pm.me>"]
edition = "2021"
license = "MPL-2.0"
[workspace.dependencies]
askalono = "0.4.6"
[package]
name = "nix-init"
version.workspace = true
authors.workspace = true
edition.workspace = true
description = "Generate Nix packages from URLs with hash prefetching, dependency inference, license detection, and more"
readme = "README.md"
homepage = "https://github.com/nix-community/nix-init"
repository = "https://github.com/nix-community/nix-init"
license = "MPL-2.0"
license.workspace = true
keywords = ["cli", "interactive", "generate", "nix", "package"]
categories = ["command-line-utilities"]
include = ["data", "src", "Cargo.lock", "Cargo.toml", "build.rs"]
[dependencies]
anyhow = "1.0.69"
askalono = "0.4.6"
askalono.workspace = true
bstr = "1.2.0"
cargo = "0.68.0"
chumsky = "1.0.0-alpha.3"
@ -64,7 +77,6 @@ version = "1.26.0"
features = ["macros", "process", "rt-multi-thread"]
[build-dependencies]
askalono = "0.4.6"
clap = { version = "4.1.8", features = ["derive"] }
clap_complete = "4.1.4"
clap_mangen = "0.2.9"

View File

@ -1,4 +1,3 @@
use askalono::Store;
use clap::{CommandFactory, ValueEnum};
use clap_complete::{generate_to, Shell};
use clap_mangen::Man;
@ -12,25 +11,10 @@ use std::{
include!("src/cli.rs");
fn main() {
println!("cargo:rerun-if-changed=cache/askalono-cache.zstd");
println!("cargo:rerun-if-changed=data/license-store-cache.zstd");
println!("cargo:rerun-if-env-changed=GEN_ARTIFACTS");
println!("cargo:rerun-if-env-changed=SPDX_LICENSE_LIST_DATA");
// by default, the cache will not be rebuilt
// remove the file to rebuild the cache
let cache = Path::new("cache/askalono-cache.zstd");
if !cache.is_file() {
create_dir_all("cache").unwrap();
let mut store = Store::new();
store
.load_spdx(
env::var_os("SPDX_LICENSE_LIST_DATA").unwrap().as_ref(),
false,
)
.unwrap();
store.to_cache(File::create(cache).unwrap()).unwrap();
}
if let Some(dir) = env::var_os("GEN_ARTIFACTS") {
let out = &Path::new(&dir);
create_dir_all(out).unwrap();

View File

@ -57,16 +57,35 @@
sourceByRegex
;
src = sourceByRegex self [
"(license-store-cache|src)(/.*)?"
"Cargo\\.(toml|lock)"
"build.rs"
"rustfmt.toml"
];
license-store-cache = buildPackage {
pname = "license-store-cache";
inherit src;
doCheck = false;
cargoArtifacts = null;
cargoExtraArgs = "-p license-store-cache";
postInstall = ''
cache=$(mktemp)
$out/bin/license-store-cache $cache ${spdx-license-list-data.json}/json/details
rm -rf $out
mv $cache $out
'';
};
GET_NIX_LICENSE = callPackage ./src/get_nix_license.nix { };
SPDX_LICENSE_LIST_DATA = "${spdx-license-list-data.json}/json/details";
args = {
src = sourceByRegex self [
"src(/.*)?"
"Cargo\\.(toml|lock)"
"build.rs"
"rustfmt.toml"
];
inherit src;
nativeBuildInputs = [
curl
@ -91,7 +110,12 @@
cargoArtifacts = buildDepsOnly args;
cargoExtraArgs = "--no-default-features --features=reqwest/rustls-tls";
inherit GET_NIX_LICENSE SPDX_LICENSE_LIST_DATA;
postPatch = ''
mkdir -p data
ln -s ${license-store-cache} data/license-store-cache.zstd
'';
inherit GET_NIX_LICENSE;
GEN_ARTIFACTS = "artifacts";
ZSTD_SYS_USE_PKG_CONFIG = true;
@ -112,9 +136,14 @@
};
devShells.default = mkShell {
inherit GET_NIX_LICENSE SPDX_LICENSE_LIST_DATA;
inherit GET_NIX_LICENSE;
NIX_INIT_LOG = "nix_init=trace";
RUST_BACKTRACE = true;
shellHook = ''
mkdir -p data
ln -sf ${license-store-cache} data/license-store-cache.zstd
'';
};
formatter = nixpkgs-fmt;

View File

@ -0,0 +1,9 @@
[package]
name = "license-store-cache"
version.workspace = true
authors.workspace = true
edition.workspace = true
license.workspace = true
[dependencies]
askalono.workspace = true

View File

@ -0,0 +1,14 @@
use askalono::Store;
use std::{env::args_os, fs::File};
fn main() {
let mut args = args_os();
args.next().unwrap();
let cache = File::create(args.next().unwrap()).unwrap();
let mut store = Store::new();
store
.load_spdx(args.next().unwrap().as_ref(), false)
.unwrap();
store.to_cache(cache).unwrap();
}

View File

@ -6,7 +6,7 @@ use tracing::debug;
use crate::utils::ResultExt;
pub static LICENSE_STORE: Lazy<Option<Store>> = Lazy::new(|| {
Store::from_cache(include_bytes!("../cache/askalono-cache.zstd") as &[_]).ok_warn()
Store::from_cache(include_bytes!("../data/license-store-cache.zstd") as &[_]).ok_warn()
});
include!(env!("GET_NIX_LICENSE"));