├── .gitignore ├── .github ├── dependabot.yml └── workflows │ └── test.yml ├── test ├── simple.nix ├── latex.nix └── julia.nix ├── LICENSE ├── README.md ├── action.yml └── src └── core.sh /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "github-actions" 4 | directory: "/" 5 | schedule: 6 | interval: "weekly" 7 | -------------------------------------------------------------------------------- /test/simple.nix: -------------------------------------------------------------------------------- 1 | let 2 | # Pinning explicitly to 20.03 to avoid issues with an outdated cache. 3 | rev = "5272327b81ed355bbed5659b8d303cf2979b6953"; 4 | nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz"; 5 | pkgs = import nixpkgs {}; 6 | in with pkgs; [ 7 | hello 8 | ] 9 | -------------------------------------------------------------------------------- /test/latex.nix: -------------------------------------------------------------------------------- 1 | let 2 | # Pinning explicitly to 20.03. 3 | rev = "5272327b81ed355bbed5659b8d303cf2979b6953"; 4 | nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz"; 5 | pkgs = import nixpkgs {}; 6 | myTex = with pkgs; texlive.combine { 7 | inherit (texlive) scheme-minimal pdfcrop; 8 | }; 9 | in [ 10 | myTex 11 | ] 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2020 nix-actions and contributors 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cache install Nix packages 2 | 3 | This actions allows caching of installations done via the [Nix package manager](https://nixos.org) to improve workflow execution time. 4 | 5 | [![][tests-img]][tests-url] 6 | 7 | Installing packages via the Nix package manager is generally quite quick. 8 | However, sometimes the packages take a long time to compile or to download from their original sources. 9 | For example, this occurs with R packages and LaTeX which are downloaded from respectively `CRAN` and `math.utah.edu`. 10 | This GitHub Action speeds up the installation by simply caching the Nix store and the symlinks to the packages in the store in the [GitHub Actions cache](https://github.com/actions/cache). 11 | So, the installed packages are restored from the cache by copying back `/nix/store`, the symlinks to `/nix/store/*` and some paths for the PATH environment variable. 12 | 13 | ## Inputs 14 | 15 | - `key` - An explicit key for restoring and saving the cache. 16 | - `restore-keys` - An ordered list of keys to use for restoring the cache if no cache hit occurred for key. 17 | - `nix_version` - Nix version, defaults to `nixos-unstable`. 18 | - `nix_file` - Nix file, defaults to `default.nix`. 19 | - `nix_install_url` - Install URL for the Nix package manager; obtain newest via https://nixos.org/nix/install. 20 | 21 | ## Outputs 22 | 23 | - `cache-hit` - A boolean value to indicate an exact match was found for the primary key. 24 | 25 | ## Example workflow 26 | 27 | ```yml 28 | name: latex 29 | 30 | on: push 31 | 32 | jobs: 33 | build: 34 | runs-on: ubuntu-latest 35 | 36 | steps: 37 | - uses: actions/checkout@v4 38 | 39 | - name: Cache install Nix packages 40 | uses: rikhuijzer/cache-install@v1 41 | with: 42 | key: nix-${{ hashFiles('mypackages.nix') }} 43 | nix_file: 'mypackages.nix' 44 | 45 | - name: Calculate some things 46 | run: julia -e 'using MyPackage; MyPackage.calculate()' 47 | 48 | - name: Build LaTeX 49 | run: latexmk -f -pdf example.tex 50 | 51 | - name: Build website 52 | run: hugo --gc --minify 53 | ``` 54 | 55 | where the file `mypackages.nix` contains 56 | 57 | ```nix 58 | let 59 | # Pinning explicitly to 20.03. 60 | rev = "5272327b81ed355bbed5659b8d303cf2979b6953"; 61 | nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz"; 62 | pkgs = import nixpkgs {}; 63 | myTex = with pkgs; texlive.combine { 64 | inherit (texlive) scheme-medium pdfcrop; 65 | }; 66 | in with pkgs; [ 67 | hugo 68 | julia 69 | myTex 70 | ] 71 | ``` 72 | 73 | [tests-img]: https://github.com/rikhuijzer/cache-install/workflows/test/badge.svg 74 | [tests-url]: https://github.com/rikhuijzer/cache-install/actions 75 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: 'Cache install Nix packages' 2 | description: 'Use the GitHub Actions cache for Nix packages' 3 | author: 'Rik Huijzer' 4 | branding: 5 | icon: 'arrow-down' 6 | color: 'blue' 7 | 8 | inputs: 9 | key: 10 | description: 'An explicit key for restoring and saving the cache' 11 | required: true 12 | restore-keys: 13 | description: 'An ordered list of keys to use for restoring the cache if no cache hit occurred for key' 14 | required: false 15 | nix_version: 16 | description: 'Nix version, defaults to `nixos-unstable`.' 17 | default: 'nixos-unstable' 18 | nix_file: 19 | description: 'Nix file, defaults to `default.nix`.' 20 | default: 'default.nix' 21 | nix_install_url: 22 | description: 'Install URL for the Nix package manager; obtain newest via https://nixos.org/nix/install.' 23 | default: 'https://releases.nixos.org/nix/nix-2.19.1/install' 24 | 25 | outputs: 26 | cache-hit: 27 | description: 'A boolean value to indicate an exact match was found for the primary key' 28 | value: ${{ steps.hit.outputs.cache-hit }} 29 | 30 | runs: 31 | using: 'composite' 32 | steps: 33 | - name: Prepare for restoring cache 34 | shell: bash 35 | run: $GITHUB_ACTION_PATH/src/core.sh "prepare-restore" 36 | 37 | - name: Pass USER to GitHub Action 38 | id: user 39 | shell: bash 40 | run: echo "USER=$USER" >> $GITHUB_ENV 41 | 42 | - name: Restore cache 43 | id: cache 44 | uses: actions/cache/restore@v4 45 | with: 46 | path: | 47 | /nix/store/ 48 | /nix/var/nix/db/db.sqlite 49 | /nix/var/nix/db/schema 50 | /nix/var/nix/profiles/per-user/${{ env.USER }}/profile/bin/ 51 | /nix/var/nix/profiles/default/bin/ 52 | /nix/var/nix/profiles/per-user/root/channels/ 53 | /home/${{ env.USER }}/.nix-profile/bin/ 54 | key: ${{ inputs.key }} 55 | restore-keys: ${{ inputs.restore-keys }} 56 | 57 | - name: Install with cache 58 | if: steps.cache.outputs.cache-hit == 'true' 59 | shell: bash 60 | run: $GITHUB_ACTION_PATH/src/core.sh "install-from-cache" 61 | 62 | - name: Install without cache 63 | # Use `!= 'true'` because `cache-hit` is not set if no cache was restored. 64 | if: steps.cache.outputs.cache-hit != 'true' 65 | shell: bash 66 | run: | 67 | $GITHUB_ACTION_PATH/src/core.sh "install-with-nix" 68 | $GITHUB_ACTION_PATH/src/core.sh "prepare-save" 69 | env: 70 | INPUT_NIX_FILE: ${{ inputs.nix_file }} 71 | INPUT_NIX_VERSION: ${{ inputs.nix_version }} 72 | INPUT_NIX_INSTALL_URL: ${{ inputs.nix_install_url }} 73 | 74 | - name: Save cache 75 | if: steps.cache.outputs.cache-hit != 'true' 76 | uses: actions/cache/save@v4 77 | with: 78 | path: | 79 | /nix/store/ 80 | /nix/var/nix/db/db.sqlite 81 | /nix/var/nix/db/schema 82 | /nix/var/nix/profiles/per-user/${{ env.USER }}/profile/bin/ 83 | /nix/var/nix/profiles/default/bin/ 84 | /nix/var/nix/profiles/per-user/root/channels/ 85 | /home/${{ env.USER }}/.nix-profile/bin/ 86 | key: ${{ inputs.key }} 87 | 88 | - name: Set cache-hit output 89 | id: hit 90 | shell: bash 91 | run: echo "cache-hit=${{ steps.cache.outputs.cache-hit }}" >> $GITHUB_OUTPUT 92 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: test 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | workflow_dispatch: 9 | schedule: 10 | - cron: '00 04 * * 6' 11 | 12 | jobs: 13 | 14 | test-save-simple: 15 | runs-on: ubuntu-latest 16 | steps: 17 | - name: Checkout 18 | uses: actions/checkout@v6 19 | 20 | - name: Save cache 21 | uses: ./ 22 | with: 23 | key: Test-Simple-${{ runner.os }}-${{ github.run_id }} 24 | nix_file: 'test/simple.nix' 25 | 26 | - name: Test whether simple.nix is installed 27 | run: which hello 28 | 29 | test-restore-simple: 30 | needs: test-save-simple 31 | runs-on: ubuntu-latest 32 | steps: 33 | - name: Checkout 34 | uses: actions/checkout@v6 35 | 36 | - name: Restore cache 37 | id: cache 38 | uses: ./ 39 | with: 40 | key: Test-Simple-${{ runner.os }}-${{ github.run_id }} 41 | nix_file: 'test/simple.nix' 42 | 43 | - name: Test whether output is set 44 | shell: bash 45 | run: | 46 | if [[ "${{ steps.cache.outputs.cache-hit }}" = "true" ]]; then 47 | echo "Output is set correctly" 48 | else 49 | echo "Output is not set correctly" 50 | exit 1 51 | fi 52 | 53 | - name: Test whether simple.nix is installed 54 | run: | 55 | nix-store --gc # Remove invalid store paths 56 | hello 57 | 58 | 59 | 60 | test-save-latex: 61 | runs-on: ubuntu-latest 62 | steps: 63 | - name: Checkout 64 | uses: actions/checkout@v6 65 | 66 | - name: Save cache 67 | uses: ./ 68 | with: 69 | key: Test-LaTeX-${{ runner.os }}-${{ github.run_id }} 70 | nix_file: 'test/latex.nix' 71 | 72 | - name: Test whether latex.nix is installed 73 | run: which pdfcrop 74 | 75 | test-restore-latex: 76 | needs: test-save-latex 77 | runs-on: ubuntu-latest 78 | steps: 79 | - name: Checkout 80 | uses: actions/checkout@v6 81 | 82 | - name: Restore cache 83 | uses: ./ 84 | with: 85 | key: Test-LaTeX-${{ runner.os }}-${{ github.run_id }} 86 | nix_file: 'test/latex.nix' 87 | 88 | - name: Test whether latex.nix is installed 89 | run: | 90 | nix-store --gc # Remove invalid store paths 91 | which pdfcrop 92 | 93 | 94 | 95 | test-save-restore-keys: 96 | runs-on: ubuntu-latest 97 | steps: 98 | - name: Checkout 99 | uses: actions/checkout@v6 100 | 101 | - name: Save cache 102 | uses: ./ 103 | with: 104 | key: Test-Restore-Keys-${{ runner.os }}-${{ github.run_id }}-foo 105 | nix_file: 'test/simple.nix' 106 | 107 | - name: Test whether simple.nix is installed 108 | run: which hello 109 | 110 | test-restore-restore-keys: 111 | needs: test-save-restore-keys 112 | runs-on: ubuntu-latest 113 | steps: 114 | - name: Checkout 115 | uses: actions/checkout@v6 116 | 117 | - name: Restore cache 118 | uses: ./ 119 | with: 120 | key: Test-Restore-Keys-${{ runner.os }}-${{ github.run_id }}-bar 121 | restore-keys: | 122 | Test-Restore-Keys-${{ runner.os }}-${{ github.run_id }}- 123 | nix_file: 'test/simple.nix' 124 | 125 | - name: Test whether simple.nix is installed 126 | run: | 127 | nix-store --gc # Remove invalid store paths 128 | hello 129 | -------------------------------------------------------------------------------- /src/core.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | function install_nix { 6 | echo "Running install_nix from core.sh" 7 | # Source: https://github.com/cachix/install-nix-action/blob/master/lib/install-nix.sh 8 | if [ -d "/nix/store" ]; then 9 | echo "The folder /nix/store exists; assuming Nix was restored from cache" 10 | export CACHE_HIT=true 11 | export PATH=$PATH:/run/current-system/sw/bin 12 | set_paths 13 | exit 0 14 | fi 15 | 16 | add_config() { 17 | echo "$1" | sudo tee -a /tmp/nix.conf >/dev/null 18 | } 19 | add_config "max-jobs = auto" 20 | # Allow binary caches for runner user. 21 | add_config "trusted-users = root $USER" 22 | 23 | installer_options=( 24 | --daemon 25 | --daemon-user-count 4 26 | --darwin-use-unencrypted-nix-store-volume 27 | --nix-extra-conf-file /tmp/nix.conf 28 | ) 29 | 30 | INPUT_NIX_PATH="nixpkgs=channel:$INPUT_NIX_VERSION" 31 | if [[ "$INPUT_NIX_PATH" != "" ]]; then 32 | installer_options+=(--no-channel-add) 33 | else 34 | INPUT_NIX_PATH="/nix/var/nix/profiles/per-user/root/channels" 35 | fi 36 | 37 | sh <(curl --silent --retry 5 --retry-connrefused -L "${INPUT_NIX_INSTALL_URL}") \ 38 | "${installer_options[@]}" 39 | 40 | # Create the user profile 41 | sudo mkdir "/nix/var/nix/profiles/per-user/$USER" 42 | sudo chown $USER "/nix/var/nix/profiles/per-user/$USER" 43 | 44 | if [[ $OSTYPE =~ darwin ]]; then 45 | # Disable spotlight indexing of /nix to speed up performance 46 | sudo mdutil -i off /nix 47 | 48 | # macOS needs certificates hints 49 | cert_file=/nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt 50 | echo "NIX_SSL_CERT_FILE=$cert_file" >> $GITHUB_ENV 51 | export NIX_SSL_CERT_FILE=$cert_file 52 | sudo launchctl setenv NIX_SSL_CERT_FILE "$cert_file" 53 | fi 54 | } 55 | 56 | function install_via_nix { 57 | echo "Running install_via_nix from core.sh" 58 | 59 | if [[ -f "$INPUT_NIX_FILE" ]]; then 60 | # Path is set correctly by set_paths but that is only available outside of this Action. 61 | PATH=/nix/var/nix/profiles/default/bin/:$PATH 62 | nix-env --install --file "$INPUT_NIX_FILE" 63 | else 64 | echo "File at nix_file does not exist" 65 | exit 1 66 | fi 67 | } 68 | 69 | function set_paths { 70 | echo "Running set_paths from core.sh" 71 | 72 | echo "/nix/var/nix/profiles/per-user/$USER/profile/bin" >> $GITHUB_PATH 73 | echo "/nix/var/nix/profiles/default/bin" >> $GITHUB_PATH 74 | echo "/home/$USER/.nix-profile/bin" >> $GITHUB_PATH 75 | } 76 | 77 | function set_nix_profile_symlink { 78 | echo "Running set_nix_profile_symlink from core.sh" 79 | 80 | NIX_PROFILE_DIR="/home/$USER/.nix-profile" 81 | if [ -d "$NIX_PROFILE_DIR" ]; then 82 | sudo rm -rf "$NIX_PROFILE_DIR" 83 | fi 84 | ln -v -s "/nix/var/nix/profiles/per-user/$USER/profile" "$NIX_PROFILE_DIR" 85 | } 86 | 87 | function set_nix_path { 88 | echo "Running set_nix_path from core.sh" 89 | 90 | INPUT_NIX_PATH="nixpkgs=channel:$INPUT_NIX_VERSION" 91 | if [[ "$INPUT_NIX_PATH" != "" ]]; then 92 | installer_options+=(--no-channel-add) 93 | else 94 | INPUT_NIX_PATH="/nix/var/nix/profiles/per-user/root/channels" 95 | fi 96 | echo "NIX_PATH=${INPUT_NIX_PATH}" >> $GITHUB_ENV 97 | } 98 | 99 | function prepare { 100 | echo "Running prepare from core.sh" 101 | 102 | sudo mkdir -p --verbose /nix 103 | sudo chown --verbose "$USER:" /nix 104 | } 105 | 106 | function undo_prepare { 107 | echo "Running undo_prepare from core.sh" 108 | 109 | sudo rm -rf /nix 110 | } 111 | 112 | function clean_nix_store { 113 | PATH=/nix/var/nix/profiles/default/bin/:$PATH 114 | 115 | nix-store --gc 116 | nix-store --optimise 117 | } 118 | 119 | TASK="$1" 120 | if [ "$TASK" == "prepare-restore" ]; then 121 | prepare 122 | elif [ "$TASK" == "install-with-nix" ]; then 123 | undo_prepare 124 | set_nix_path 125 | install_nix 126 | set_paths 127 | set_nix_profile_symlink 128 | install_via_nix 129 | elif [ "$TASK" == "install-from-cache" ]; then 130 | set_nix_path 131 | set_paths 132 | set_nix_profile_symlink 133 | elif [ "$TASK" == "prepare-save" ]; then 134 | prepare 135 | clean_nix_store 136 | else 137 | echo "Unknown argument given to core.sh: $TASK" 138 | exit 1 139 | fi 140 | -------------------------------------------------------------------------------- /test/julia.nix: -------------------------------------------------------------------------------- 1 | let 2 | # Pinning explicitly to 20.03 to avoid issues with an outdated cache. 3 | rev = "5272327b81ed355bbed5659b8d303cf2979b6953"; 4 | nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz"; 5 | pkgs = import nixpkgs { 6 | inherit config; 7 | }; 8 | 9 | config = { 10 | allowBroken = true; 11 | }; 12 | 13 | papajaBuildInputs = with pkgs.rPackages; [ 14 | afex 15 | base64enc 16 | beeswarm 17 | bookdown 18 | broom 19 | knitr 20 | rlang 21 | rmarkdown 22 | rmdfiltr 23 | yaml 24 | ]; 25 | papaja = with pkgs.rPackages; buildRPackage { 26 | name = "papaja"; 27 | src = pkgs.fetchFromGitHub { 28 | owner = "crsh"; 29 | repo = "papaja"; 30 | rev = "b0a224a5e67e1afff084c46c2854ac6f82b12179"; 31 | sha256 = "14pxnlgg7pzazpyx0hbv9mlvqdylylpb7p4yhh4w2wlcw6sn3rwj"; 32 | }; 33 | # Do not add propagatedBuildInputs = papajaBuildInputs since 34 | # it might cause a buffer overflow when calling `devtools::document`. 35 | nativeBuildInputs = papajaBuildInputs; 36 | }; 37 | my-r-packages = with pkgs.rPackages; [ 38 | ggplot2 39 | ]; 40 | R-with-my-packages = pkgs.rWrapper.override{ 41 | packages = my-r-packages; 42 | }; 43 | 44 | julia_15 = pkgs.stdenv.mkDerivation { 45 | name = "julia_15"; 46 | src = pkgs.fetchurl { 47 | url = "https://julialang-s3.julialang.org/bin/linux/x64/1.5/julia-1.5.2-linux-x86_64.tar.gz"; 48 | sha256 = "0c26b11qy4csws6vvi27lsl0nmqszaf7lk1ya0jrg8zgvkx099vd"; 49 | }; 50 | installPhase = '' 51 | mkdir $out 52 | cp -R * $out/ 53 | 54 | # Patch for https://github.com/JuliaInterop/RCall.jl/issues/339. 55 | 56 | echo "patching $out" 57 | cp -L ${pkgs.stdenv.cc.cc.lib}/lib/libstdc++.so.6 $out/lib/julia/ 58 | ''; 59 | dontStrip = true; 60 | ldLibraryPath = with pkgs; stdenv.lib.makeLibraryPath [ 61 | stdenv.cc.cc 62 | zlib 63 | glib 64 | xorg.libXi 65 | xorg.libxcb 66 | xorg.libXrender 67 | xorg.libX11 68 | xorg.libSM 69 | xorg.libICE 70 | xorg.libXext 71 | dbus 72 | fontconfig 73 | freetype 74 | libGL 75 | ]; 76 | }; 77 | targetPkgs = pkgs: with pkgs; [ 78 | autoconf 79 | curl 80 | gnumake 81 | utillinux 82 | m4 83 | gperf 84 | unzip 85 | stdenv.cc 86 | clang 87 | binutils 88 | which 89 | gmp 90 | libxml2 91 | cmake 92 | 93 | fontconfig 94 | openssl 95 | which 96 | ncurses 97 | gtk2-x11 98 | atk 99 | gdk_pixbuf 100 | cairo 101 | xorg.libX11 102 | xorg.xorgproto 103 | xorg.libXcursor 104 | xorg.libXrandr 105 | xorg.libXext 106 | xorg.libSM 107 | xorg.libICE 108 | xorg.libX11 109 | xorg.libXrandr 110 | xorg.libXdamage 111 | xorg.libXrender 112 | xorg.libXfixes 113 | xorg.libXcomposite 114 | xorg.libXcursor 115 | xorg.libxcb 116 | xorg.libXi 117 | xorg.libXScrnSaver 118 | xorg.libXtst 119 | xorg.libXt 120 | xorg.libXxf86vm 121 | xorg.libXinerama 122 | nspr 123 | pdf2svg 124 | 125 | # Nvidia note: may need to change cudnn to match cudatoolkit version 126 | # cudatoolkit_10_0 127 | # cudnn_cudatoolkit_10_0 128 | # linuxPackages.nvidia_x11 129 | 130 | julia_15 131 | 132 | # Arpack.jl 133 | arpack 134 | gfortran.cc 135 | (pkgs.runCommand "openblas64_" {} '' 136 | mkdir -p "$out"/lib/ 137 | ln -s ${openblasCompat}/lib/libopenblas.so "$out"/lib/libopenblas64_.so.0 138 | '') 139 | 140 | # Cairo.jl 141 | cairo 142 | gettext 143 | pango.out 144 | glib.out 145 | # Gtk.jl 146 | gtk3 147 | gtk2 148 | fontconfig 149 | gdk_pixbuf 150 | # GR.jl # Runs even without Xrender and Xext, but cannot save files, so those are required 151 | qt4 152 | glfw 153 | freetype 154 | 155 | conda 156 | 157 | #misc 158 | xorg.libXxf86vm 159 | xorg.libSM 160 | xorg.libXtst 161 | libpng 162 | expat 163 | gnome2.GConf 164 | nss 165 | 166 | ]; 167 | 168 | env_vars = '' 169 | export EXTRA_CCFLAGS="-I/usr/include" 170 | 171 | # Points RCall to `libR.so`. 172 | export LD_LIBRARY_PATH="${pkgs.R}/lib/R/lib:$LD_LIBRARY_PATH" 173 | # Ensure that RCall uses the same R version as used by `libR.so`. 174 | # export R_HOME="${pkgs.R}/bin" 175 | 176 | # This does not add dependencies (recursively)! 177 | # Leaving the code since it was an interesting approach. 178 | # export R_LIBS_USER="$ 179 | # (lib.concatMapStringsSep ":" (path: path + "/library") my-r-packages) 180 | # }" 181 | # export R_LIBS_USER=$R_LIBS_USER:$(R -e 'paste(.libPaths(), collapse=":")') 182 | 183 | # This seems to run after nixos-rebuild-switch, so R knows all the packages. 184 | # Do not set `R_LIBS_USER` since `using RCall` will overwrite it. 185 | LIBRARIES=$(Rscript -e 'paste(.libPaths(), collapse=":")') 186 | export R_LIBS_SITE="$(echo $LIBRARIES | cut -c6- | rev | cut -c2- | rev)" 187 | ''; 188 | extraOutputsToInstall = ["man" "dev"]; 189 | multiPkgs = pkgs: with pkgs; [ zlib ]; 190 | 191 | julia-debug = pkgs.buildFHSUserEnv { 192 | targetPkgs = targetPkgs; 193 | name = "julia-debug"; # Name used to start this UserEnv 194 | multiPkgs = multiPkgs; 195 | runScript = "bash"; 196 | extraOutputsToInstall = extraOutputsToInstall; 197 | profile = env_vars; 198 | }; 199 | 200 | julia-fhs = pkgs.buildFHSUserEnv { 201 | targetPkgs = targetPkgs; 202 | name = "julia"; # Name used to start this UserEnv 203 | multiPkgs = multiPkgs; 204 | runScript = "julia"; 205 | extraOutputsToInstall = extraOutputsToInstall; 206 | profile = env_vars; 207 | }; 208 | in with pkgs; [ 209 | julia-fhs 210 | R-with-my-packages 211 | ] 212 | --------------------------------------------------------------------------------