Skip to content

Commit dac099a

Browse files
feat(nix): overhaul nix flake and packages (anomalyco#9032)
1 parent 5009f10 commit dac099a

File tree

10 files changed

+212
-653
lines changed

10 files changed

+212
-653
lines changed

.github/workflows/update-nix-hashes.yml

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -19,84 +19,7 @@ on:
1919
- ".github/workflows/update-nix-hashes.yml"
2020

2121
jobs:
22-
update-flake:
23-
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
24-
runs-on: blacksmith-4vcpu-ubuntu-2404
25-
env:
26-
TITLE: flake.lock
27-
28-
steps:
29-
- name: Checkout repository
30-
uses: actions/checkout@v6
31-
with:
32-
token: ${{ secrets.GITHUB_TOKEN }}
33-
fetch-depth: 0
34-
ref: ${{ github.head_ref || github.ref_name }}
35-
repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
36-
37-
- name: Setup Nix
38-
uses: nixbuild/nix-quick-install-action@v34
39-
40-
- name: Configure git
41-
run: |
42-
git config --global user.email "action@github.com"
43-
git config --global user.name "Github Action"
44-
45-
- name: Update ${{ env.TITLE }}
46-
run: |
47-
set -euo pipefail
48-
echo "Updating $TITLE..."
49-
nix flake update
50-
echo "$TITLE updated successfully"
51-
52-
- name: Commit ${{ env.TITLE }} changes
53-
env:
54-
TARGET_BRANCH: ${{ github.head_ref || github.ref_name }}
55-
run: |
56-
set -euo pipefail
57-
58-
echo "Checking for changes in tracked files..."
59-
60-
summarize() {
61-
local status="$1"
62-
{
63-
echo "### Nix $TITLE"
64-
echo ""
65-
echo "- ref: ${GITHUB_REF_NAME}"
66-
echo "- status: ${status}"
67-
} >> "$GITHUB_STEP_SUMMARY"
68-
if [ -n "${GITHUB_SERVER_URL:-}" ] && [ -n "${GITHUB_REPOSITORY:-}" ] && [ -n "${GITHUB_RUN_ID:-}" ]; then
69-
echo "- run: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" >> "$GITHUB_STEP_SUMMARY"
70-
fi
71-
echo "" >> "$GITHUB_STEP_SUMMARY"
72-
}
73-
FILES=(flake.lock flake.nix)
74-
STATUS="$(git status --short -- "${FILES[@]}" || true)"
75-
if [ -z "$STATUS" ]; then
76-
echo "No changes detected."
77-
summarize "no changes"
78-
exit 0
79-
fi
80-
81-
echo "Changes detected:"
82-
echo "$STATUS"
83-
echo "Staging files..."
84-
git add "${FILES[@]}"
85-
echo "Committing changes..."
86-
git commit -m "Update $TITLE"
87-
echo "Changes committed"
88-
89-
BRANCH="${TARGET_BRANCH:-${GITHUB_REF_NAME}}"
90-
echo "Pulling latest from branch: $BRANCH"
91-
git pull --rebase --autostash origin "$BRANCH"
92-
echo "Pushing changes to branch: $BRANCH"
93-
git push origin HEAD:"$BRANCH"
94-
echo "Changes pushed successfully"
95-
96-
summarize "committed $(git rev-parse --short HEAD)"
97-
9822
compute-node-modules-hash:
99-
needs: update-flake
10023
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
10124
strategy:
10225
fail-fast: false

flake.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 21 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -6,111 +6,43 @@
66
};
77

88
outputs =
9-
{
10-
self,
11-
nixpkgs,
12-
...
13-
}:
9+
{ self, nixpkgs, ... }:
1410
let
1511
systems = [
1612
"aarch64-linux"
1713
"x86_64-linux"
1814
"aarch64-darwin"
1915
"x86_64-darwin"
2016
];
21-
inherit (nixpkgs) lib;
22-
forEachSystem = lib.genAttrs systems;
23-
pkgsFor = system: nixpkgs.legacyPackages.${system};
24-
packageJson = builtins.fromJSON (builtins.readFile ./packages/opencode/package.json);
25-
bunTarget = {
26-
"aarch64-linux" = "bun-linux-arm64";
27-
"x86_64-linux" = "bun-linux-x64";
28-
"aarch64-darwin" = "bun-darwin-arm64";
29-
"x86_64-darwin" = "bun-darwin-x64";
30-
};
31-
32-
# Parse "bun-{os}-{cpu}" to {os, cpu}
33-
parseBunTarget =
34-
target:
35-
let
36-
parts = lib.splitString "-" target;
37-
in
38-
{
39-
os = builtins.elemAt parts 1;
40-
cpu = builtins.elemAt parts 2;
41-
};
42-
43-
hashesFile = "${./nix}/hashes.json";
44-
hashesData =
45-
if builtins.pathExists hashesFile then builtins.fromJSON (builtins.readFile hashesFile) else { };
46-
# Lookup hash: supports per-system ({system: hash}) or legacy single hash
47-
nodeModulesHashFor =
48-
system:
49-
if builtins.isAttrs hashesData.nodeModules then
50-
hashesData.nodeModules.${system}
51-
else
52-
hashesData.nodeModules;
53-
modelsDev = forEachSystem (
54-
system:
55-
let
56-
pkgs = pkgsFor system;
57-
in
58-
pkgs."models-dev"
59-
);
17+
forEachSystem = f: nixpkgs.lib.genAttrs systems (system: f nixpkgs.legacyPackages.${system});
18+
rev = self.shortRev or self.dirtyShortRev or "dirty";
6019
in
6120
{
62-
devShells = forEachSystem (
63-
system:
64-
let
65-
pkgs = pkgsFor system;
66-
in
67-
{
68-
default = pkgs.mkShell {
69-
packages = with pkgs; [
70-
bun
71-
nodejs_20
72-
pkg-config
73-
openssl
74-
git
75-
];
76-
};
77-
}
78-
);
21+
devShells = forEachSystem (pkgs: {
22+
default = pkgs.mkShell {
23+
packages = with pkgs; [
24+
bun
25+
nodejs_20
26+
pkg-config
27+
openssl
28+
git
29+
];
30+
};
31+
});
7932

8033
packages = forEachSystem (
81-
system:
34+
pkgs:
8235
let
83-
pkgs = pkgsFor system;
84-
bunPlatform = parseBunTarget bunTarget.${system};
85-
mkNodeModules = pkgs.callPackage ./nix/node-modules.nix {
86-
hash = nodeModulesHashFor system;
87-
bunCpu = bunPlatform.cpu;
88-
bunOs = bunPlatform.os;
36+
opencode = pkgs.callPackage ./nix/opencode.nix {
37+
inherit rev;
8938
};
90-
mkOpencode = pkgs.callPackage ./nix/opencode.nix { };
91-
mkDesktop = pkgs.callPackage ./nix/desktop.nix { };
92-
93-
opencodePkg = mkOpencode {
94-
inherit (packageJson) version;
95-
src = ./.;
96-
scripts = ./nix/scripts;
97-
target = bunTarget.${system};
98-
modelsDev = "${modelsDev.${system}}/dist/_api.json";
99-
inherit mkNodeModules;
100-
};
101-
102-
desktopPkg = mkDesktop {
103-
inherit (packageJson) version;
104-
src = ./.;
105-
scripts = ./nix/scripts;
106-
mkNodeModules = mkNodeModules;
107-
opencode = opencodePkg;
39+
desktop = pkgs.callPackage ./nix/desktop.nix {
40+
inherit opencode;
10841
};
10942
in
11043
{
111-
default = self.packages.${system}.opencode;
112-
opencode = opencodePkg;
113-
desktop = desktopPkg;
44+
default = opencode;
45+
inherit opencode desktop;
11446
}
11547
);
11648
};

nix/bundle.ts

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)