Skip to content

Commit 3d722e4

Browse files
Copilotncrmro
andcommitted
Fix Nix flake package to include Python with deepwork in PYTHONPATH
Co-authored-by: ncrmro <8276365+ncrmro@users.noreply.github.com>
1 parent e24cea8 commit 3d722e4

2 files changed

Lines changed: 115 additions & 22 deletions

File tree

doc/nix-flake.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,51 @@ If you get an error about flakes not being recognized:
321321
echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf
322322
```
323323

324+
### Hooks Not Finding DeepWork Module
325+
326+
When using DeepWork from a Nix flake in your project, hooks may fail with "No module named 'deepwork'" because they run outside of `nix develop`. The flake package includes wrapper scripts that solve this:
327+
328+
**Solution:**
329+
330+
Instead of using `python -m deepwork.hooks.rules_check` directly in hooks, use the provided wrapper commands:
331+
332+
- For Claude Code: Use `deepwork-python -m deepwork.hooks.rules_check`
333+
- For Gemini CLI: Use `deepwork-python -m deepwork.hooks.rules_check`
334+
335+
Or use the dedicated hook wrappers:
336+
- `deepwork-claude-hook deepwork.hooks.rules_check`
337+
- `deepwork-gemini-hook deepwork.hooks.rules_check`
338+
339+
These wrappers ensure the Python environment has access to the deepwork module even when running outside of the Nix development shell.
340+
341+
**In your flake.nix:**
342+
343+
```nix
344+
{
345+
inputs = {
346+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
347+
deepwork.url = "github:Unsupervisedcom/deepwork";
348+
};
349+
350+
outputs = { self, nixpkgs, deepwork }:
351+
let
352+
system = "x86_64-linux";
353+
pkgs = import nixpkgs { inherit system; };
354+
in {
355+
devShells.${system}.default = pkgs.mkShell {
356+
buildInputs = [
357+
deepwork.packages.${system}.default
358+
];
359+
360+
# Optional: Add deepwork binaries to PATH for easier hook usage
361+
shellHook = ''
362+
export PATH="${deepwork.packages.${system}.default}/bin:$PATH"
363+
'';
364+
};
365+
};
366+
}
367+
```
368+
324369
### direnv Not Working
325370

326371
1. Make sure direnv is installed:

flake.nix

Lines changed: 70 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,83 @@
1111
let
1212
pkgs = import nixpkgs {
1313
inherit system;
14-
# Allow unfree packages to support the Business Source License 1.1
15-
config.allowUnfree = true;
1614
};
17-
deepwork = pkgs.python311Packages.buildPythonPackage {
18-
pname = "deepwork";
19-
version = "0.3.0";
15+
16+
# Create a wrapped Python environment with deepwork available
17+
pythonWithDeepwork = pkgs.python311.withPackages (ps: [
18+
(ps.buildPythonPackage {
19+
pname = "deepwork";
20+
version = "0.3.0";
21+
src = ./.;
22+
format = "pyproject";
23+
24+
nativeBuildInputs = with ps; [
25+
hatchling
26+
];
27+
28+
propagatedBuildInputs = with ps; [
29+
jinja2
30+
pyyaml
31+
gitpython
32+
click
33+
rich
34+
jsonschema
35+
];
36+
37+
# Skip tests during build (they can be run in devShell)
38+
doCheck = false;
39+
40+
meta = with pkgs.lib; {
41+
description = "Framework for enabling AI agents to perform complex, multi-step work tasks";
42+
homepage = "https://github.com/Unsupervisedcom/deepwork";
43+
# Business Source License 1.1 - not OSI approved
44+
license = {
45+
fullName = "Business Source License 1.1";
46+
url = "https://github.com/Unsupervisedcom/deepwork/blob/main/LICENSE.md";
47+
free = false;
48+
};
49+
};
50+
})
51+
]);
52+
53+
# Create the main deepwork package with proper wrappers
54+
deepwork = pkgs.stdenv.mkDerivation {
55+
name = "deepwork-0.3.0";
2056
src = ./.;
21-
format = "pyproject";
22-
23-
nativeBuildInputs = with pkgs.python311Packages; [
24-
hatchling
25-
];
26-
27-
propagatedBuildInputs = with pkgs.python311Packages; [
28-
jinja2
29-
pyyaml
30-
gitpython
31-
click
32-
rich
33-
jsonschema
34-
];
3557

36-
# Skip tests during build (they can be run in devShell)
37-
doCheck = false;
58+
nativeBuildInputs = [ pkgs.makeWrapper ];
59+
60+
buildPhase = ''
61+
# Nothing to build, we just need to wrap the Python package
62+
'';
63+
64+
installPhase = ''
65+
mkdir -p $out/bin
66+
67+
# Create wrapper for deepwork CLI
68+
makeWrapper ${pythonWithDeepwork}/bin/deepwork $out/bin/deepwork \
69+
--set PYTHONPATH "${pythonWithDeepwork}/${pythonWithDeepwork.sitePackages}"
70+
71+
# Create wrapper scripts for claude hook
72+
makeWrapper ${pythonWithDeepwork}/bin/python $out/bin/deepwork-claude-hook \
73+
--add-flags "-m" \
74+
--set PYTHONPATH "${pythonWithDeepwork}/${pythonWithDeepwork.sitePackages}" \
75+
--set DEEPWORK_HOOK_PLATFORM "claude"
76+
77+
# Create wrapper scripts for gemini hook
78+
makeWrapper ${pythonWithDeepwork}/bin/python $out/bin/deepwork-gemini-hook \
79+
--add-flags "-m" \
80+
--set PYTHONPATH "${pythonWithDeepwork}/${pythonWithDeepwork.sitePackages}" \
81+
--set DEEPWORK_HOOK_PLATFORM "gemini"
82+
83+
# Also create a python wrapper that has deepwork in PYTHONPATH
84+
makeWrapper ${pythonWithDeepwork}/bin/python $out/bin/deepwork-python \
85+
--set PYTHONPATH "${pythonWithDeepwork}/${pythonWithDeepwork.sitePackages}"
86+
'';
3887

3988
meta = with pkgs.lib; {
4089
description = "Framework for enabling AI agents to perform complex, multi-step work tasks";
4190
homepage = "https://github.com/Unsupervisedcom/deepwork";
42-
# Business Source License 1.1 - not OSI approved
4391
license = {
4492
fullName = "Business Source License 1.1";
4593
url = "https://github.com/Unsupervisedcom/deepwork/blob/main/LICENSE.md";

0 commit comments

Comments
 (0)