Skip to content

Commit

Permalink
nix: use devenv to create a shell environment
Browse files Browse the repository at this point in the history
Devenv[^1] is tool to create easily composable development
environments for nix.

Hooking it in to our nix flake gives us the following improvements:
 - more declarative python environment config
 - avoid the `patchElf` hack to pull in native dependencies
 - python packages updates won't undo the effect of `patchElf`
 - due to a long-standing bug[^2], a patched `devenv` version is needed

The `.devenv` directory is pre-created because of a quirk: it needs to
be present in the `src` derivation of `shell.nix`, otherwise it is
unable to create it due to a permission error.

[^1]: https://devenv.sh/
[^2]: cachix/devenv-nixpkgs#2
  • Loading branch information
vlaci committed Oct 4, 2024
1 parent ea27c4e commit c6c412c
Show file tree
Hide file tree
Showing 8 changed files with 678 additions and 52 deletions.
Empty file added .devenv/.gitkeep
Empty file.
4 changes: 4 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
watch_file flake.nix flake.lock devenv.nix
use nix \
--option extra-substituters "https://unblob.cachix.org" \
--option extra-trusted-public-keys "unblob.cachix.org-1:5kWA6DwOg176rSqU8TOTBXWxsDB4LoCMfGfTgL5qCAE="
2 changes: 1 addition & 1 deletion .github/workflows/build-nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ jobs:
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
extraPullNames: pyperscan
- run: |
nix flake check -L --option system ${{ matrix.arch }} --extra-platforms ${{ matrix.arch }}
nix flake check -L --impure --option system ${{ matrix.arch }} --extra-platforms ${{ matrix.arch }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ build/
.coverage*
/.venv/
unblob.log
/.devenv
/.direnv
24 changes: 24 additions & 0 deletions devenv.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{ pkgs, ... }:

# https://devenv.sh/reference/options/
{
languages.python = {
enable = true;
libraries = with pkgs; [
file # python-magic
];
poetry = {
enable = true;
activate.enable = true;
install.enable = true;
install = {
groups = [ "dev" ];
installRootPackage = true;
};
};
};

packages = with pkgs; [
nvfetcher
] ++ unblob.runtimeDeps;
}
Loading

0 comments on commit c6c412c

Please sign in to comment.