-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflake.nix
More file actions
105 lines (90 loc) · 3.86 KB
/
flake.nix
File metadata and controls
105 lines (90 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
{
description = "A local-first knowledge base for your AI coding sessions";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
pp = pkgs.python3Packages;
# ── Frontend (npm build) ────────────────────────────────────
# vite.config.ts outDir = '../stackunderflow/static/react'
# We let nix build into dist/ and copy to $out.
# The npmDepsHash must be computed once; replace the placeholder
# with the real hash that nix reports on first build.
frontend = pkgs.buildNpmPackage {
pname = "stackunderflow-ui";
version = "0.3.5";
src = ./stackunderflow-ui;
npmDepsHash = "sha256-QCAlYLx7LP2702pTBwi3N8Ft4hFqP88xMCRoV+h1jls=";
installPhase = ''
# vite.config.ts outDir = '../stackunderflow/static/react'
# In the nix sandbox: source is at $PWD (e.g. /build/stackunderflow-ui/)
# vite outputs to ./../stackunderflow/static/react/ = /build/stackunderflow/static/react/
mkdir -p $out
cp -r ../stackunderflow/static/react/* $out/
'';
};
# ── Merged source tree (Python source + built frontend) ─────
# The server expects stackunderflow/static/react/index.html.
# This derivation combines the upstream source with the frontend
# build output into a single directory tree.
srcWithFrontend = pkgs.runCommand "stackunderflow-src" { } ''
cp -r ${pkgs.lib.cleanSource ./.} $out
chmod -R u+w $out
# Place built frontend where the Python server looks for it
mkdir -p $out/stackunderflow/static/react
cp -r ${frontend}/. $out/stackunderflow/static/react/
'';
# ── Python package ──────────────────────────────────────────
stackunderflow-pkg = pp.buildPythonPackage {
pname = "stackunderflow";
version = "0.3.5";
pyproject = true;
src = srcWithFrontend;
nativeBuildInputs = [ pp.hatchling pkgs.nodejs ];
propagatedBuildInputs = with pp; [
python-dotenv click fastapi uvicorn httpx
python-multipart orjson uvloop rich
mcp
];
doCheck = false; # tests use pytest separately
meta = with pkgs.lib; {
description = "A local-first knowledge base for your AI coding sessions";
homepage = "https://github.com/0bserver07/StackUnderflow";
license = licenses.mit;
mainProgram = "stackunderflow";
};
};
in
rec {
packages.default = stackunderflow-pkg;
packages.stackunderflow = stackunderflow-pkg;
packages.frontend = frontend;
# Dev shell
devShells.default = pkgs.mkShell {
packages = [
pkgs.nodejs pkgs.python3
pp.ruff pp.mypy
pp.pytest pp.pytest-asyncio
pp.pytest-cov pp.psutil
pp.types-python-dateutil pp.types-psutil
pp.mcp
pkgs.rsync
];
PYTHONPATH = "${toString ./.}";
shellHook = ''
echo ""
echo " StackUnderflow dev environment"
echo " Frontend → cd stackunderflow-ui && npm run dev"
echo " Backend → python -m stackunderflow.cli init"
echo " Tests → python -m pytest tests/stackunderflow/ -v"
echo " Lint → bash lint.sh"
echo ""
'';
};
}
);
}