downloading modules now actually works
This commit is contained in:
12
lib.nix
12
lib.nix
@@ -363,13 +363,15 @@ rec {
|
|||||||
|
|
||||||
mkModulesInstallPhase = modules: pkgs.lib.concatStringsSep "\n" (map mkModuleInstallPhase modules);
|
mkModulesInstallPhase = modules: pkgs.lib.concatStringsSep "\n" (map mkModuleInstallPhase modules);
|
||||||
|
|
||||||
mkModuleInstallPhase = module: ''
|
mkModuleInstallPhase = module: let
|
||||||
|
hash = builtins.substring 0 32 (builtins.hashString "sha256" module.selector_string);
|
||||||
|
in ''
|
||||||
echo got module: ${module.name}
|
echo got module: ${module.name}
|
||||||
echo out: $out
|
echo out: $out
|
||||||
hash=$(echo ${module.selector_string} | sha256sum | cut -c -32)
|
echo hash: ${hash}
|
||||||
cp --no-preserve=mode,ownership -r ${module}/* $out/mize/dist/$hash-${module.modName}
|
cp --no-preserve=mode,ownership -r ${module}/* $out/mize/dist/${hash}-${module.modName}
|
||||||
${pkgs.gnutar}/bin/tar -czf $out/mize/dist/$hash-${module.modName}.tar.gz -C ${module} .
|
${pkgs.gnutar}/bin/tar -czf $out/mize/dist/${hash}-${module.modName}.tar.gz -C ${module} .
|
||||||
echo '${module.selector_string}' > $out/mize/dist/$hash-${module.modName}/selector
|
echo '${module.selector_string}' > $out/mize/dist/${hash}-${module.modName}/selector
|
||||||
'';
|
'';
|
||||||
|
|
||||||
webfiles = systems: stdenv.mkDerivation {
|
webfiles = systems: stdenv.mkDerivation {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use clap::ArgMatches;
|
|||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::time::UNIX_EPOCH;
|
use std::time::UNIX_EPOCH;
|
||||||
use sha2::{Sha256, Sha512, Digest};
|
use sha2::{Sha256, Sha512, Digest};
|
||||||
use flate2::read::GzDecoder;
|
use flate2::bufread::GzDecoder;
|
||||||
use tar::Archive;
|
use tar::Archive;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::copy;
|
use std::io::copy;
|
||||||
@@ -177,7 +177,11 @@ pub fn get_module_hash(instance: &mut Instance, name: &str, mut options: ItemDat
|
|||||||
|
|
||||||
fn fetch_module(instance: &mut Instance, store_path: &str, module_url: &str, module_hash: &str, module_name: &str, module_selector: &str) -> MizeResult<()> {
|
fn fetch_module(instance: &mut Instance, store_path: &str, module_url: &str, module_hash: &str, module_name: &str, module_selector: &str) -> MizeResult<()> {
|
||||||
|
|
||||||
|
|
||||||
let tmp_file_path_gz = format!("{}/{}.tar.gz", store_path, module_hash);
|
let tmp_file_path_gz = format!("{}/{}.tar.gz", store_path, module_hash);
|
||||||
|
|
||||||
|
let tmp_gz_file = if !PathBuf::from(tmp_file_path_gz.clone()).exists() {
|
||||||
|
|
||||||
let mut tmp_gz_file = File::create(&tmp_file_path_gz)?;
|
let mut tmp_gz_file = File::create(&tmp_file_path_gz)?;
|
||||||
|
|
||||||
debug!("fetching module '{}' with hash: {}", module_name, module_hash);
|
debug!("fetching module '{}' with hash: {}", module_name, module_hash);
|
||||||
@@ -189,7 +193,12 @@ fn fetch_module(instance: &mut Instance, store_path: &str, module_url: &str, mod
|
|||||||
return Err(mize_err!("failed to get module '{}' with hash '{}' and selector: {}", module_name, module_hash, module_selector).msg(format!("the http request to fetch the module returned a status code of: {}", code)));
|
return Err(mize_err!("failed to get module '{}' with hash '{}' and selector: {}", module_name, module_hash, module_selector).msg(format!("the http request to fetch the module returned a status code of: {}", code)));
|
||||||
}
|
}
|
||||||
|
|
||||||
let tar = GzDecoder::new(tmp_gz_file);
|
tmp_gz_file
|
||||||
|
} else {
|
||||||
|
std::fs::File::open(tmp_file_path_gz.clone())?
|
||||||
|
};
|
||||||
|
|
||||||
|
let tar = GzDecoder::new(std::io::BufReader::new(tmp_gz_file));
|
||||||
let mut archive = Archive::new(tar);
|
let mut archive = Archive::new(tar);
|
||||||
|
|
||||||
//archive.set_mask(umask::Mode::parse("rwxrwxrwx")?.into());
|
//archive.set_mask(umask::Mode::parse("rwxrwxrwx")?.into());
|
||||||
@@ -218,7 +227,9 @@ pub fn load_module(instance: &mut Instance, module_name: &str, path: Option<Path
|
|||||||
|
|
||||||
let (module_hash, module_selector) = get_module_hash(instance, module_name, ItemData::new())?;
|
let (module_hash, module_selector) = get_module_hash(instance, module_name, ItemData::new())?;
|
||||||
|
|
||||||
if !PathBuf::from(format!("{}/modules/{}", store_path, module_hash.as_str())).exists() {
|
if !PathBuf::from(format!("{}/modules/{}", store_path, module_hash.as_str())).exists()
|
||||||
|
|| !PathBuf::from(format!("{}/modules/{}/lib/libmize_module_{}.so", store_path.as_str(), module_hash.as_str(), module_name)).exists()
|
||||||
|
{
|
||||||
// fetch module if it does not exist
|
// fetch module if it does not exist
|
||||||
fetch_module(instance, store_path.as_str(), module_url.as_str(), module_hash.as_str(), module_name, module_selector.as_str())?;
|
fetch_module(instance, store_path.as_str(), module_url.as_str(), module_hash.as_str(), module_name, module_selector.as_str())?;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user