Skip to content

Commit 2aa3031

Browse files
authored
Add Nix flake for ergonomic NixOS development (#253)
1 parent 91cf8aa commit 2aa3031

6 files changed

Lines changed: 127 additions & 1 deletion

File tree

‎.envrc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ test_data
1414
CHANGELOG.md
1515
*.ipynb
1616
/site
17+
.direnv

‎.python-version‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.11
1+
3.12

‎CONTRIBUTING.md‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,25 @@ We use [uv](https://docs.astral.sh/uv/) to manage the project. This project
1616
also contains a Rust extension (built with [maturin](https://www.maturin.rs/)),
1717
so a Rust toolchain is required.
1818

19+
<details>
20+
<summary>NixOS user?</summary>
21+
22+
This repo ships a `flake.nix` that provides uv, a matching Python
23+
interpreter, and a Rust toolchain, plus the shared libraries that compiled
24+
Python wheels (pyarrow, duckdb, polars, ...) expect to find at runtime —
25+
none of which NixOS provides by default. It's scoped to this project only;
26+
it doesn't touch anything outside this directory.
27+
28+
- With [direnv](https://direnv.net/) installed, run `direnv allow` once in
29+
the project root and the shell loads automatically whenever you `cd` in
30+
(and unloads when you leave).
31+
- Without direnv, run `nix develop` manually to enter the shell.
32+
33+
Either way, once you're in the shell, skip steps 0-1 below (Rust and uv are
34+
already on `PATH`) and start at step 2.
35+
36+
</details>
37+
1938
0. Install Rust: https://rustup.rs/
2039
1. Install uv: https://docs.astral.sh/uv/getting-started/installation/
2140
2. Clone the repository (bonus: [via SSH](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account))

‎flake.lock‎

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎flake.nix‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
description = "xarray-sql development environment";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
flake-utils.url = "github:numtide/flake-utils";
7+
};
8+
9+
outputs = { self, nixpkgs, flake-utils }:
10+
flake-utils.lib.eachDefaultSystem (system:
11+
let
12+
pkgs = import nixpkgs { inherit system; };
13+
14+
# Shared libraries that manylinux wheels (pyarrow, duckdb, polars,
15+
# numpy, ...) expect to find via the dynamic linker at runtime.
16+
# NixOS doesn't put these on a standard FHS path, so we point
17+
# LD_LIBRARY_PATH at the nix store paths that provide them.
18+
runtimeLibs = with pkgs; [
19+
stdenv.cc.cc
20+
zlib
21+
openssl
22+
];
23+
in
24+
{
25+
devShells.default = pkgs.mkShell {
26+
packages = with pkgs; [
27+
uv
28+
python312
29+
rustc
30+
cargo
31+
pkg-config
32+
];
33+
34+
# Use the Nix-provided interpreter above instead of having uv
35+
# download its own Python build.
36+
UV_PYTHON_PREFERENCE = "only-system";
37+
38+
shellHook = ''
39+
export LD_LIBRARY_PATH="${pkgs.lib.makeLibraryPath runtimeLibs}''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
40+
echo "xarray-sql dev shell: $(python3 --version), $(rustc --version)"
41+
'';
42+
};
43+
});
44+
}

0 commit comments

Comments
 (0)