-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript_fix_hashes.R
61 lines (48 loc) · 2.28 KB
/
script_fix_hashes.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
library(data.table)
library(parallel)
cl <- makeCluster(6)
readFormatted <- as.data.table(read.table(skip=8, sep='"', text=head(readLines("../nixpkgs/pkgs/development/r-modules/cran-packages.nix"), -1)))
nixPrefetch <- function(name, version) {
url <- paste0(mirrorUrl, name, "_", version, ".tar.gz")
tmp <- tempfile(pattern=paste0(name, "_", version), fileext=".tar.gz")
cmd <- paste0("wget -q -O '", tmp, "' '", url, "'")
archiveUrl <- paste0(mirrorUrl, "Archive/", name, "/", name, "_", version, ".tar.gz")
cmd <- paste0(cmd, " || wget -q -O '", tmp, "' '", archiveUrl, "'")
cmd <- paste0(cmd, " && nix-hash --type sha256 --base32 --flat '", tmp, "'")
cmd <- paste0(cmd, " && echo >&2 ' added ", name, " v", version, "'")
cmd <- paste0(cmd, " ; rm -rf '", tmp, "'")
system(cmd, intern=TRUE)
}
mirrorType <- "cran"
# Probably no need to ever update biocVersion since
# I'm only checking CRAN packages
biocVersion <- "3.8"
mirrorUrls <- list( bioc=paste0("http://bioconductor.org/packages/",
biocVersion, "/bioc/src/contrib/") ,
"bioc-annotation"=paste0("http://bioconductor.org/packages/",
biocVersion, "/data/annotation/src/contrib/") ,
"bioc-experiment"=paste0("http://bioconductor.org/packages/",
biocVersion, "/data/experiment/src/contrib/") ,
cran="https://cran.r-project.org/src/contrib/"
)
mirrorUrl <- mirrorUrls[mirrorType][[1]]
clusterExport(cl, c("nixPrefetch","readFormatted", "mirrorUrl", "mirrorType"))
readFormatted$V6 <- parApply(cl, readFormatted, 1,
function(p) nixPrefetch(p[2], p[4]))
output_file <- "../nixpkgs/pkgs/development/r-modules/cran-packages.nix"
output <- c(
"# This file is generated from generate-r-packages.R. DO NOT EDIT.",
"# Execute the following command to update the file.",
"#",
paste("# Rscript generate-r-packages.R", mirrorType, ">new && mv new cran-packages.nix"),
"",
"{ self, derive }:",
"let derive2 = derive { };",
"in with self; {",
apply(readFormatted, 1, paste0, collapse = "\""),
"}\n"
)
writeLines(output, output_file)
system(paste0("cd ../nixpkgs/",
" && git add . && git commit -m 'updated hashes'",
" && git push origin 2021-02-26"))