Skip to content

Commit

Permalink
fix locale
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Baumann committed Sep 26, 2023
1 parent da9b239 commit 432c596
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 62 deletions.
7 changes: 3 additions & 4 deletions R/detect_os.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ detect_os <- function(){
#' generate_locale_archive("Linux")
#' @noRd
generate_locale_archive <- function(os){
if(detect_os() == "Linux"){
'LOCALE_ARCHIVE = \"${pkgs.glibcLocales}/lib/locale/locale-archive\";'
} else if(detect_os() == "Darwin") {
''
os <- detect_os()
if (os == "Linux" || os == "Darwin") {
'LOCALE_ARCHIVE = if pkgs.system == \"x86_64-linux\" then \"${pkgs.glibcLocalesUtf8}/lib/locale/locale-archive\" else \"\";'
} else {
stop("Operating System unsupported")
}
Expand Down
37 changes: 26 additions & 11 deletions R/find_rev.R
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,9 @@ rPackages)

# Texlive packages
generate_tex_pkgs <- function(tex_pkgs) {

tex_pkgs <- paste(tex_pkgs, collapse = ' ')

if (!is.null(tex_pkgs)) {

tex_pkgs <- paste(tex_pkgs, collapse = ' ')

sprintf('tex = (pkgs.texlive.combine {
inherit (pkgs.texlive) scheme-small %s;
Expand Down Expand Up @@ -462,6 +461,24 @@ tex_pkgs)
',
get_system_pkgs(system_pkgs))
}

generate_locale_variables <- function() {
locale_variables <- getOption(
"rix.nix_locale_variables",
default = list(
LANG = "en_US.UTF-8",
LC_ALL = "en_US.UTF-8",
LC_TIME = "en_US.UTF-8",
LC_MONETARY = "en_US.UTF-8",
LC_PAPER = "en_US.UTF-8"
)
)
paste(
Map(function(x, nm) paste0(nm, " = ", x),
nm = names(locale_variables), x = locale_variables),
collapse = ";\n "
)
}

generate_rstudio_pkgs <- function(ide, flag_git_archive, flag_rpkgs){
if(ide == "rstudio"){
Expand All @@ -477,26 +494,24 @@ flag_rpkgs
}
}

flag_rstudio <- if(ide == "rstudio"){
"rstudio_pkgs"
} else {
""
}
flag_rstudio <- if (ide == "rstudio") "rstudio_pkgs" else ""

shell_hook <- if(!is.null(shell_hook)){
paste0("shellHook = ''\n", shell_hook, "\n'';")
}
shell_hook <- if (!is.null(shell_hook)) {
paste0('shellHook = "', shell_hook, '";')
}

# Generate the shell
generate_shell <- function(flag_git_archive,
flag_rpkgs){
sprintf('in
pkgs.mkShell {
%s
%s
buildInputs = [ %s %s %s system_packages %s ];
%s
}',
generate_locale_archive(detect_os()),
generate_locale_variables(),
flag_git_archive,
flag_rpkgs,
flag_tex_pkgs,
Expand Down
37 changes: 26 additions & 11 deletions dev/build_envs.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -495,10 +495,9 @@ rPackages)
# Texlive packages
generate_tex_pkgs <- function(tex_pkgs) {
tex_pkgs <- paste(tex_pkgs, collapse = ' ')
if (!is.null(tex_pkgs)) {
tex_pkgs <- paste(tex_pkgs, collapse = ' ')
sprintf('tex = (pkgs.texlive.combine {
inherit (pkgs.texlive) scheme-small %s;
Expand Down Expand Up @@ -546,6 +545,24 @@ tex_pkgs)
',
get_system_pkgs(system_pkgs))
}
generate_locale_variables <- function() {
locale_variables <- getOption(
"rix.nix_locale_variables",
default = list(
LANG = "en_US.UTF-8",
LC_ALL = "en_US.UTF-8",
LC_TIME = "en_US.UTF-8",
LC_MONETARY = "en_US.UTF-8",
LC_PAPER = "en_US.UTF-8"
)
)
paste(
Map(function(x, nm) paste0(nm, " = ", x),
nm = names(locale_variables), x = locale_variables),
collapse = ";\n "
)
}
generate_rstudio_pkgs <- function(ide, flag_git_archive, flag_rpkgs){
if(ide == "rstudio"){
Expand All @@ -561,26 +578,24 @@ flag_rpkgs
}
}
flag_rstudio <- if(ide == "rstudio"){
"rstudio_pkgs"
} else {
""
}
flag_rstudio <- if (ide == "rstudio") "rstudio_pkgs" else ""
shell_hook <- if(!is.null(shell_hook)){
paste0("shellHook = ''\n", shell_hook, "\n'';")
}
shell_hook <- if (!is.null(shell_hook)) {
paste0('shellHook = "', shell_hook, '";')
}
# Generate the shell
generate_shell <- function(flag_git_archive,
flag_rpkgs){
sprintf('in
pkgs.mkShell {
%s
%s
buildInputs = [ %s %s %s system_packages %s ];
%s
}',
generate_locale_archive(detect_os()),
generate_locale_variables(),
flag_git_archive,
flag_rpkgs,
flag_tex_pkgs,
Expand Down
7 changes: 3 additions & 4 deletions dev/get_os.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ This function adds deals with locale on Linux (and WSL2):
#' @examples
#' generate_locale_archive("Linux")
generate_locale_archive <- function(os){
if(detect_os() == "Linux"){
'LOCALE_ARCHIVE = \"${pkgs.glibcLocales}/lib/locale/locale-archive\";'
} else if(detect_os() == "Darwin") {
''
os <- detect_os()
if (os == "Linux" || os == "Darwin") {
'LOCALE_ARCHIVE = if pkgs.system == \"x86_64-linux\" then \"${pkgs.glibcLocalesUtf8}/lib/locale/locale-archive\" else \"\";'
} else {
stop("Operating System unsupported")
}
Expand Down
43 changes: 11 additions & 32 deletions inst/extdata/default.nix
Original file line number Diff line number Diff line change
@@ -1,47 +1,26 @@
# This file was generated by the {rix} R package v0.3.1 on 2023-09-25
# with following call:
# >rix(r_ver = "976fa3369d722e76f37c77493d99829540d43845",
# > r_pkgs = NULL,
# > system_pkgs = NULL,
# > git_pkgs = list(package_name = "rix",
# > repo_url = "https://github.com/b-rodrigues/rix/",
# > branch_name = "master",
# > commit = "ae39d2142461688b1be41db800752a949ebb3c7b"),
# > ide = "other",
# > project_path = "inst/extdata",
# > overwrite = TRUE)
# It uses nixpkgs' revision 976fa3369d722e76f37c77493d99829540d43845 for reproducibility purposes
# which will install R as it was as of nixpkgs revision: 976fa3369d722e76f37c77493d99829540d43845
# Report any issues to https://github.com/b-rodrigues/rix
let
pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/976fa3369d722e76f37c77493d99829540d43845.tar.gz") {};
git_archive_pkgs = [(pkgs.rPackages.buildRPackage {
name = "rix";
src = pkgs.fetchgit {
url = "https://github.com/b-rodrigues/rix/";
url = "https://github.com/b-rodrigues/rix";
branchName = "master";
rev = "ae39d2142461688b1be41db800752a949ebb3c7b";
sha256 = "sha256-rOhFnc01CzRE6Hl73xGvaE/bQCoX0d5tZ10jzAoqQ7g=";
rev = "b4501842723ef19391c7653e0b44a487505d89f2";
sha256 = "sha256-pQdRKxzNhDPPWW1T9oaQEtkLTdmU0+Ry0aGzEGfeYFo=";
};
propagatedBuildInputs = builtins.attrValues {
inherit (pkgs.rPackages) httr jsonlite sys;
};
}) ];
tex = (pkgs.texlive.combine {
inherit (pkgs.texlive) scheme-small ;
});
system_packages = builtins.attrValues {
inherit (pkgs) R glibcLocalesUtf8 ;
system_packages = builtins.attrValues {
inherit (pkgs) R glibcLocales nix;
};
in
pkgs.mkShell {
LOCALE_ARCHIVE = if pkgs.system == "x86_64-linux" then "${pkgs.glibcLocalesUtf8}/lib/locale/locale-archive" else "";
LANG = "en_US.UTF-8";
LC_ALL = "en_US.UTF-8";
LC_TIME = "en_US.UTF-8";
LC_MONETARY = "en_US.UTF-8";
LC_PAPER = "en_US.UTF-8";
LC_MEASUREMENT = "en_US.UTF-8";
LOCALE_ARCHIVE = if pkgs.system == "x86_64-linux" then "${pkgs.glibcLocalesUtf8}/lib/locale/locale-archive" else "";
LANG = en_US.UTF-8;
LC_ALL = en_US.UTF-8;
LC_TIME = en_US.UTF-8;
LC_MONETARY = en_US.UTF-8;
LC_PAPER = en_US.UTF-8
buildInputs = [ git_archive_pkgs system_packages ];
shellHook = "R --vanilla";
}

0 comments on commit 432c596

Please sign in to comment.