flake.nix 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. {
  2. description = "OpenCode development flake";
  3. inputs = {
  4. nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
  5. };
  6. outputs =
  7. { self, nixpkgs, ... }:
  8. let
  9. systems = [
  10. "aarch64-linux"
  11. "x86_64-linux"
  12. "aarch64-darwin"
  13. "x86_64-darwin"
  14. ];
  15. forEachSystem = f: nixpkgs.lib.genAttrs systems (system: f nixpkgs.legacyPackages.${system});
  16. rev = self.shortRev or self.dirtyShortRev or "dirty";
  17. in
  18. {
  19. devShells = forEachSystem (pkgs: {
  20. default = pkgs.mkShell {
  21. packages = with pkgs; [
  22. bun
  23. nodejs_20
  24. pkg-config
  25. openssl
  26. git
  27. ];
  28. };
  29. });
  30. packages = forEachSystem (
  31. pkgs:
  32. let
  33. node_modules = pkgs.callPackage ./nix/node_modules.nix {
  34. inherit rev;
  35. };
  36. opencode = pkgs.callPackage ./nix/opencode.nix {
  37. inherit node_modules;
  38. };
  39. desktop = pkgs.callPackage ./nix/desktop.nix {
  40. inherit opencode;
  41. };
  42. # nixpkgs cpu naming to bun cpu naming
  43. cpuMap = { x86_64 = "x64"; aarch64 = "arm64"; };
  44. # matrix of node_modules builds - these will always fail due to fakeHash usage
  45. # but allow computation of the correct hash from any build machine for any cpu/os
  46. # see the update-nix-hashes workflow for usage
  47. moduleUpdaters = pkgs.lib.listToAttrs (
  48. pkgs.lib.concatMap (cpu:
  49. map (os: {
  50. name = "${cpu}_${os}_node_modules";
  51. value = node_modules.override {
  52. bunCpu = cpuMap.${cpu};
  53. bunOs = os;
  54. hash = pkgs.lib.fakeHash;
  55. };
  56. }) [ "linux" "darwin" ]
  57. ) [ "x86_64" "aarch64" ]
  58. );
  59. in
  60. {
  61. default = opencode;
  62. inherit opencode desktop;
  63. } // moduleUpdaters
  64. );
  65. };
  66. }