-
Notifications
You must be signed in to change notification settings - Fork 300
Expand file tree
/
Copy pathflake.nix
More file actions
136 lines (116 loc) · 4.04 KB
/
flake.nix
File metadata and controls
136 lines (116 loc) · 4.04 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
{
description = "Letta Code CLI package and service modules";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
bun2nix.url = "github:nix-community/bun2nix";
bun2nix.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs, bun2nix }:
let
lib = nixpkgs.lib;
packageJson = builtins.fromJSON (builtins.readFile ./package.json);
supportedSystems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
forAllSystems = lib.genAttrs supportedSystems;
pkgsFor = system: import nixpkgs {
inherit system;
overlays = [ bun2nix.overlays.default ];
};
mkPackage = pkgs:
pkgs.stdenv.mkDerivation rec {
pname = "letta-code";
version = packageJson.version;
src = ./.;
bunDeps = pkgs.bun2nix.fetchBunDeps {
bunNix = ./bun.nix;
};
nativeBuildInputs = [
pkgs.nodejs_22
pkgs.bun
pkgs.makeWrapper
pkgs.pkg-config
pkgs.python3
pkgs.bun2nix.hook
];
bunInstallFlags = if pkgs.stdenv.hostPlatform.isDarwin then [
"--linker=hoisted"
"--backend=copyfile"
] else [
"--linker=hoisted"
];
CI = "true";
dontUseBunCheck = true;
preBuild = ''
export HOME="$TMPDIR"
substituteInPlace build.js \
--replace-fail 'await Bun.$`bunx tsc -p tsconfig.types.json`' 'true'
'';
buildPhase = ''
runHook preBuild
bun run build
runHook postBuild
'';
installPhase = ''
runHook preInstall
pack_dir="$TMPDIR/package"
mkdir -p "$pack_dir" "$out/lib/letta-code" "$out/bin"
npm pack --ignore-scripts --pack-destination "$pack_dir"
tar -xzf "$pack_dir"/letta-ai-letta-code-*.tgz \
-C "$out/lib/letta-code" \
--strip-components=1
cp -rL node_modules "$out/lib/letta-code/node_modules"
makeWrapperArgs=(
--add-flags "$out/lib/letta-code/letta.js"
--prefix PATH : ${lib.makeBinPath [ pkgs.git pkgs.ripgrep ]}
)
${lib.optionalString pkgs.stdenv.hostPlatform.isLinux ''
makeWrapperArgs+=(--prefix LD_LIBRARY_PATH : ${pkgs.stdenv.cc.cc.lib}/lib) # libstdc++.so.6 for sharp
''}
makeWrapper ${pkgs.bun}/bin/bun "$out/bin/letta" "''${makeWrapperArgs[@]}"
runHook postInstall
'';
postInstall = ''
chmod +x "$out/bin/letta"
'';
meta = {
description = packageJson.description;
homepage = "https://github.com/letta-ai/letta-code";
license = lib.licenses.asl20;
mainProgram = "letta";
maintainers = [ ];
};
};
in
{
packages = forAllSystems (system:
let pkgs = pkgsFor system;
in {
default = mkPackage pkgs;
letta-code = self.packages.${system}.default;
});
apps = forAllSystems (system: {
default = {
type = "app";
program = "${self.packages.${system}.default}/bin/letta";
};
letta = self.apps.${system}.default;
});
devShells = forAllSystems (system:
let pkgs = pkgsFor system;
in {
default = pkgs.mkShell {
packages = [ pkgs.bun pkgs.nodejs_22 pkgs.git pkgs.ripgrep ];
};
});
nixosModules.default = import ./nix/modules/nixos.nix { inherit self; };
nixosModules.letta-code = self.nixosModules.default;
homeManagerModules.default = import ./nix/modules/home-manager.nix { inherit self; };
homeManagerModules.letta-code = self.homeManagerModules.default;
homeModules.default = import ./nix/modules/home-manager.nix { inherit self; };
homeModules.letta-code = self.homeModules.default;
};
}