summaryrefslogtreecommitdiffhomepage
path: root/flake.nix
diff options
context:
space:
mode:
authorCaleb Norton <[email protected]>2026-01-18 11:14:13 -0600
committerGitHub <[email protected]>2026-01-18 11:14:13 -0600
commitdac099a4892689d11abedb0fcc1098b50e0958c8 (patch)
treeb47a7a4bae294e0d4222fac21605a380d54b3341 /flake.nix
parent5009f10406c15c4b69c04fa626756ee7bf81b300 (diff)
downloadopencode-dac099a4892689d11abedb0fcc1098b50e0958c8.tar.gz
opencode-dac099a4892689d11abedb0fcc1098b50e0958c8.zip
feat(nix): overhaul nix flake and packages (#9032)
Diffstat (limited to 'flake.nix')
-rw-r--r--flake.nix110
1 files changed, 21 insertions, 89 deletions
diff --git a/flake.nix b/flake.nix
index 32614640a..20833fc49 100644
--- a/flake.nix
+++ b/flake.nix
@@ -6,11 +6,7 @@
};
outputs =
- {
- self,
- nixpkgs,
- ...
- }:
+ { self, nixpkgs, ... }:
let
systems = [
"aarch64-linux"
@@ -18,99 +14,35 @@
"aarch64-darwin"
"x86_64-darwin"
];
- inherit (nixpkgs) lib;
- forEachSystem = lib.genAttrs systems;
- pkgsFor = system: nixpkgs.legacyPackages.${system};
- packageJson = builtins.fromJSON (builtins.readFile ./packages/opencode/package.json);
- bunTarget = {
- "aarch64-linux" = "bun-linux-arm64";
- "x86_64-linux" = "bun-linux-x64";
- "aarch64-darwin" = "bun-darwin-arm64";
- "x86_64-darwin" = "bun-darwin-x64";
- };
-
- # Parse "bun-{os}-{cpu}" to {os, cpu}
- parseBunTarget =
- target:
- let
- parts = lib.splitString "-" target;
- in
- {
- os = builtins.elemAt parts 1;
- cpu = builtins.elemAt parts 2;
- };
-
- hashesFile = "${./nix}/hashes.json";
- hashesData =
- if builtins.pathExists hashesFile then builtins.fromJSON (builtins.readFile hashesFile) else { };
- # Lookup hash: supports per-system ({system: hash}) or legacy single hash
- nodeModulesHashFor =
- system:
- if builtins.isAttrs hashesData.nodeModules then
- hashesData.nodeModules.${system}
- else
- hashesData.nodeModules;
- modelsDev = forEachSystem (
- system:
- let
- pkgs = pkgsFor system;
- in
- pkgs."models-dev"
- );
+ forEachSystem = f: nixpkgs.lib.genAttrs systems (system: f nixpkgs.legacyPackages.${system});
+ rev = self.shortRev or self.dirtyShortRev or "dirty";
in
{
- devShells = forEachSystem (
- system:
- let
- pkgs = pkgsFor system;
- in
- {
- default = pkgs.mkShell {
- packages = with pkgs; [
- bun
- nodejs_20
- pkg-config
- openssl
- git
- ];
- };
- }
- );
+ devShells = forEachSystem (pkgs: {
+ default = pkgs.mkShell {
+ packages = with pkgs; [
+ bun
+ nodejs_20
+ pkg-config
+ openssl
+ git
+ ];
+ };
+ });
packages = forEachSystem (
- system:
+ pkgs:
let
- pkgs = pkgsFor system;
- bunPlatform = parseBunTarget bunTarget.${system};
- mkNodeModules = pkgs.callPackage ./nix/node-modules.nix {
- hash = nodeModulesHashFor system;
- bunCpu = bunPlatform.cpu;
- bunOs = bunPlatform.os;
+ opencode = pkgs.callPackage ./nix/opencode.nix {
+ inherit rev;
};
- mkOpencode = pkgs.callPackage ./nix/opencode.nix { };
- mkDesktop = pkgs.callPackage ./nix/desktop.nix { };
-
- opencodePkg = mkOpencode {
- inherit (packageJson) version;
- src = ./.;
- scripts = ./nix/scripts;
- target = bunTarget.${system};
- modelsDev = "${modelsDev.${system}}/dist/_api.json";
- inherit mkNodeModules;
- };
-
- desktopPkg = mkDesktop {
- inherit (packageJson) version;
- src = ./.;
- scripts = ./nix/scripts;
- mkNodeModules = mkNodeModules;
- opencode = opencodePkg;
+ desktop = pkgs.callPackage ./nix/desktop.nix {
+ inherit opencode;
};
in
{
- default = self.packages.${system}.opencode;
- opencode = opencodePkg;
- desktop = desktopPkg;
+ default = opencode;
+ inherit opencode desktop;
}
);
};