Skip to content

Commit fd996a2

Browse files
vlaciLászló Vaskó
authored andcommitted
chore(nix): speed up nix-shell usage dramatically
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
1 parent 199b533 commit fd996a2

File tree

2 files changed

+37
-19
lines changed

2 files changed

+37
-19
lines changed

flake.nix

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,23 @@
5252
checks = forAllSystems (system: nixpkgsFor.${system}.unblob.tests);
5353

5454
devShells = forAllSystems
55-
(system: {
56-
default = import ./shell.nix { pkgs = nixpkgsFor.${system}; };
57-
});
55+
(system:
56+
with nixpkgsFor.${system}; {
57+
default = mkShell {
58+
packages = [
59+
unblob.runtimeDeps
60+
ruff
61+
pyright
62+
python3Packages.pytest
63+
python3Packages.pytest-cov
64+
poetry
65+
66+
nvfetcher
67+
];
68+
69+
env.LD_LIBRARY_PATH = lib.makeLibraryPath [ file ];
70+
};
71+
});
5872

5973
legacyPackages = forAllSystems (system: nixpkgsFor.${system});
6074
};

shell.nix

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
# This file is to let "legacy" nix-shell command work in addition to `nix develop`
22
let
3-
flake = builtins.getFlake (toString ./.);
4-
flakePkgs = flake.legacyPackages.${builtins.currentSystem};
5-
in
6-
{ pkgs ? flakePkgs }:
3+
flakeManifest = [
4+
./flake.lock
5+
./flake.nix
6+
./overlay.nix
7+
./nix
8+
];
79

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

18-
nvfetcher
19-
];
20-
}
16+
startsWith = pref: str: with builtins; substring 0 (stringLength pref) str == pref;
17+
18+
src = builtins.path {
19+
path = ./.;
20+
name = "source";
21+
filter = path: type: builtins.any (x: startsWith (toString x) path) flakeManifest;
22+
};
23+
in
24+
(import flake-compat { inherit src; }).shellNix.default

0 commit comments

Comments
 (0)