Skip to content

Commit

Permalink
chore(nix): speed up nix-shell usage dramatically
Browse files Browse the repository at this point in the history
The issue is that any nix flake related command copies the whole
source tree under `/nix/store`  again and again for every file
modification. This behavior needs a proper fix from upstream[^1].

Fortunately it can be worked around by removing unblob build from the
shell environment dependencies, and using the legacy `shell.nix`
entrypoint. Here we can prefilter the source tree before involving
`flake.nix` in the picture. Copying will still happen, but much less
frequently, as source and tests files will be filtered out.

As all our dependencies well behaving now, we can easily use poetry
inside a nix-shell env, no workarounds for build quirks needed.

[^1]: NixOS/nix#3121
  • Loading branch information
vlaci authored and László Vaskó committed Jun 7, 2023
1 parent 199b533 commit fd996a2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 19 deletions.
20 changes: 17 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,23 @@
checks = forAllSystems (system: nixpkgsFor.${system}.unblob.tests);

devShells = forAllSystems
(system: {
default = import ./shell.nix { pkgs = nixpkgsFor.${system}; };
});
(system:
with nixpkgsFor.${system}; {
default = mkShell {
packages = [
unblob.runtimeDeps
ruff
pyright
python3Packages.pytest
python3Packages.pytest-cov
poetry

nvfetcher
];

env.LD_LIBRARY_PATH = lib.makeLibraryPath [ file ];
};
});

legacyPackages = forAllSystems (system: nixpkgsFor.${system});
};
Expand Down
36 changes: 20 additions & 16 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
# This file is to let "legacy" nix-shell command work in addition to `nix develop`
let
flake = builtins.getFlake (toString ./.);
flakePkgs = flake.legacyPackages.${builtins.currentSystem};
in
{ pkgs ? flakePkgs }:
flakeManifest = [
./flake.lock
./flake.nix
./overlay.nix
./nix
];

with pkgs; mkShell {
packages = [
unblob
unblob.runtimeDeps
ruff
pyright
python3Packages.pytest
python3Packages.pytest-cov
poetry
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
flake-compat = fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
};

nvfetcher
];
}
startsWith = pref: str: with builtins; substring 0 (stringLength pref) str == pref;

src = builtins.path {
path = ./.;
name = "source";
filter = path: type: builtins.any (x: startsWith (toString x) path) flakeManifest;
};
in
(import flake-compat { inherit src; }).shellNix.default

0 comments on commit fd996a2

Please sign in to comment.