Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Nix config files #27

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 13 additions & 29 deletions .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,34 @@ jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]
fail-fast: false

steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v4

- name: Upgrade pip
run: python -m pip install --upgrade pip
- name: Run the Magic Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@v2

# =====================================================
# Install dependencies
# Build
# =====================================================
- name: Check out submodules
- name: Build dev environment
# Running `nix develop` the first time will cause it to download/build all
# the needed Nix packages.
run: |
make submodules
nix develop -c echo "Finished setting up 'nix develop' environment"

- name: Install R
uses: r-lib/actions/setup-r@v2
- uses: r-lib/actions/setup-r-dependencies@v2
with:
packages: |
any::knitr
any::rmarkdown
any::reticulate

- name: Install build dependencies
- name: Check out submodules
run: |
make deps

# =====================================================
# Build
# =====================================================
- uses: quarto-dev/quarto-actions/setup@v2
with:
version: 1.3.340
nix develop -c \
make submodules

- name: Build site
run: |
nix develop -c \
make all

# =====================================================
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ VENV = venv
PYBIN = $(VENV)/bin


## Build everything
## Build everything (except pulling in submodules)
all: deps quartodoc site

# Any targets that depend on $(VENV) or $(PYBIN) will cause the venv to be
Expand Down
29 changes: 21 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,25 @@ This repository contains the sources for the Shiny for Python web site.

## Setup and build

Install Quarto. Because Quarto is under rapid development, it's best to install by cloning the Quarto git repository and running a setup script; after that, just doing `git pull` will make the latest version available, without needing to run an installer each time. [Instructions here](https://github.com/quarto-dev/quarto-cli#development-version).

**Prerequisites:** Make sure you have the following installed. (Note that if you have Nix installed on your system, you do not need to install these manually because Nix can provide them automatically.)

- Quarto 1.3.x
- Python
- R

Clone this repository:

```bash
git clone https://github.com/rstudio/pyshiny-site.git
cd pyshiny-site
git clone https://github.com/posit-dev/py-shiny-site.git
cd py-shiny-site
```

**Optional:** If you are using Nix, you can get a working development environment with all of the prerequisites by simply running `nix develop`. This will enter a shell with correct versions of the dependencies already installed.

```bash
# Optional, if you have Nix installed
nix develop
```

Set up git submodules:
Expand Down Expand Up @@ -36,14 +48,15 @@ $ make
all Build everything
submodules Update git submodules to commits referenced in this repository
submodules-pull Pull latest commits in git submodules
build_pkgs Build and install htmltools and shiny
shinylive Build JS components for shinylive
pypi Create a local pypi repository with htmltools and shiny
api_docs Build shiny API documentation
quarto-exts Update Quarto extensions
deps Install build dependencies
quartodoc Build qmd files for Shiny API docs
site Build website
serve Build website and serve
clean Remove Quarto website build files
distclean Remove all build files (packages, API docs, shinylive, Quarto website)
clean-exts Remove Quarto extensions
clean-venv Remove venv files
distclean Remove all build files (Quarto website, quarto extensions, venv)
```


Expand Down
44 changes: 44 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

114 changes: 114 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
{
description = "py-shiny-site";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11";
# Pin to this release of nixpkgs to use Quarto 1.3. (This is currently the same as
# nixpkgs above but they may change independently in the future.)
nixpkgs-quarto.url = "github:NixOS/nixpkgs/nixos-23.11";
};

outputs = { self, nixpkgs, nixpkgs-quarto }:
let
allSystems =
[ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];

# Helper to provide system-specific attributes
forAllSystems = f:
nixpkgs.lib.genAttrs allSystems (system:
f rec {
quartoOverlay = final: prev: {
# Modifications to Quarto from:
# https://github.com/quarto-dev/quarto-cli/blob/fee994d5476fd1a23c37b8a700c027cdb4267688/src/resources/schema/cell-attributes.yml
quarto = (prev.quarto.overrideAttrs (oldAttrs: {
# The original preFixup also set QUARTO_R and QUARTO_PYTHON. Setting the
# latter seems to make Quarto ignore virtualenvs. I think that with
# those vars set, Quarto would always use those copies of R and Python
# instead of the versions of R and Python we've installed ourselves.
preFixup = ''
wrapProgram $out/bin/quarto \
--prefix PATH : ${prev.lib.makeBinPath [ prev.deno ]} \
--prefix QUARTO_DENO : ${prev.deno}/bin/deno \
--prefix QUARTO_PANDOC : ${prev.pandoc}/bin/pandoc \
--prefix QUARTO_ESBUILD : ${prev.esbuild}/bin/esbuild \
--prefix QUARTO_DART_SASS : ${prev.dart-sass}/bin/dart-sass \
'';

})) //
# Additional modifications to quarto, for Mac only.
(nixpkgs.lib.attrsets.optionalAttrs pkgs.stdenv.isDarwin {
# The previous recipe always fetched the Linux build. On Mac, fetch the
# Mac build.
src = prev.fetchurl {
url =
"https://github.com/quarto-dev/quarto-cli/releases/download/v${prev.oldAttrs.version}/quarto-${prev.oldAttrs.version}-macos.tar.gz";
sha256 =
"sha256-w9pqJr1Y8H4Yqqd+YhVzKGtKEntz4CP4nqeVZ6MKoFw=";
};

# The Linux tarball has /quarto-x.xx.x/, which contains a bin/ and
# share/ directory, but the Mac tarball just has /bin/ and /share/. This
# causes the unpackPhase to fail -- Nix complains about multiple files
# in the directory. To work around this, we set sourceRoot to "." and
# then after unpacking, create a directory quarto/, and move bin/ and
# share/ into it.
sourceRoot = ".";

postUnpack = ''
mkdir quarto
mv bin share quarto
sourceRoot=quarto
'';

});
};

pkgs = import nixpkgs { inherit system; };

pkgs-quarto = import nixpkgs-quarto {
inherit system;
overlays = [ quartoOverlay ];
};

inherit system;
});

in {
# Development environment output
devShells = forAllSystems ({ pkgs, pkgs-quarto, system, ... }: {
default = pkgs.mkShell {
packages = with pkgs; [
git
which
rsync
(with rPackages; [ R rmarkdown reticulate ])
python311
pkgs-quarto.quarto
# Quarto uses `rmarkdown::pandoc_available()` when running rmd files, which
# in turn calls `find_pandoc()` -> `find_program("pandoc")`, and on Linux,
# this calls `Sys.which("pandoc")` (it does something a bit different on
# Mac). This means that pandoc needs to be in the PATH. So we'll explicitly
# add it here, making sure that that it comes from pkgs-quarto, so it's
# the same copy that quarto would find anyway.
# https://github.com/quarto-dev/quarto-cli/blob/fee994d5/src/resources/rmd/rmd.R#L219C12-L228
pkgs-quarto.pandoc
sysctl # Needed by Quarto to detect system
];
# Need to set LD_LIBRARY_PATH to load some Python packages on Linux (like zmq,
# which is used by jupyter_client).
# https://discourse.nixos.org/t/how-to-solve-libstdc-not-found-in-shell-nix/25458
#
# For some reason, the rmarkdown package on Linux requires HOME to be set when
# running pandoc. When running with `nix develop -i`, there is no HOME;
# however, `~` will expand to the user's home directory, so we set HOME to ~.
# https://github.com/rstudio/rmarkdown/issues/31#issuecomment-41218736
shellHook = pkgs.lib.strings.optionalString (!pkgs.stdenv.isDarwin) ''
export LD_LIBRARY_PATH=${pkgs.stdenv.cc.cc.lib}/lib/
if [ -z "$HOME" ]; then
export HOME=~
fi
'';
};
});
};
}