summaryrefslogtreecommitdiffstatshomepage
path: root/nix/flake.nix
blob: d871ce7fde1561f233a92f2b0a55fac718430f71 (plain) (blame)
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
{
  description = "Home-Manager profiles for the Arch host and the Ubuntu remote-dev VM.";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    home-manager = {
      # Track the Home Manager branch whose release.json matches nixpkgs'
      # lib.version. nixos-unstable currently reports 26.11pre-git, while
      # home-manager's latest release branch is still 26.05, so master is the
      # matching input until release-26.11 exists.
      url = "github:nix-community/home-manager/master";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    # tuicr: TUI git-change reviewer. Upstream flake exposes
    # `packages.<system>.default`. Pulled here instead of nixpkgs because
    # it's not packaged there. The skill files under
    # `dot_claude/skills/tuicr/` rely on the `tuicr` binary being on PATH.
    tuicr = {
      url = "github:ruifm/tuicr";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    aibox = {
      url = "github:ruifm/aibox";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs =
    {
      self,
      nixpkgs,
      home-manager,
      tuicr,
      aibox,
      ...
    }:
    let
      releases = builtins.fromJSON (builtins.readFile ./releases.json);
      hermes = builtins.getFlake "github:NousResearch/hermes-agent/${releases.hermes.rev}";
      system = "x86_64-linux";
      pkgs = import nixpkgs {
        inherit system;
        overlays = [
          # Expose external flake packages so common.nix can list them next to
          # nixpkgs packages without threading inputs into every module.
          (final: prev: {
            tuicr = tuicr.packages.${system}.default;
            aibox = aibox.packages.${system}.default;
            claude-release = prev.claude-code.overrideAttrs {
              version = releases.claude.version;
              src = final.fetchurl {
                inherit (releases.claude) url hash;
              };
            };
            copilot-release = final.stdenvNoCC.mkDerivation {
              pname = "github-copilot-cli";
              version = releases.copilot.version;
              src = final.fetchurl {
                inherit (releases.copilot) url hash;
              };
              sourceRoot = ".";
              nativeBuildInputs = [
                final.autoPatchelfHook
                final.makeBinaryWrapper
              ];
              buildInputs = [
                final.glibc
                final.stdenv.cc.cc.lib
                final.glib
                final.libsecret
              ];
              runtimeDependencies = [
                final.glibc
                final.stdenv.cc.cc.lib
                final.glib
                final.libsecret
              ];
              dontStrip = true;
              installPhase = ''
                runHook preInstall
                install -Dm755 copilot "$out/libexec/copilot"
                makeWrapper "$out/libexec/copilot" "$out/bin/copilot" \
                  --add-flag --no-auto-update \
                  --set-default SSL_CERT_DIR ${final.cacert}/etc/ssl/certs \
                  --prefix PATH : ${final.lib.makeBinPath [ final.bash ]}
                runHook postInstall
              '';
              meta = {
                description = "GitHub Copilot CLI";
                homepage = "https://github.com/github/copilot-cli";
                license = final.lib.licenses.unfree;
                mainProgram = "copilot";
                platforms = [ "x86_64-linux" ];
                sourceProvenance = with final.lib.sourceTypes; [
                  binaryNativeCode
                  binaryBytecode
                  obfuscatedCode
                ];
              };
            };
            codex-release = final.stdenvNoCC.mkDerivation {
              pname = "codex";
              version = releases.codex.version;
              src = final.fetchurl {
                inherit (releases.codex) url hash;
              };
              sourceRoot = ".";
              nativeBuildInputs = [ final.autoPatchelfHook ];
              buildInputs = [
                final.glibc
                final.ncurses
              ];
              runtimeDependencies = [
                final.glibc
                final.ncurses
              ];
              installPhase = ''
                runHook preInstall
                mkdir -p "$out"
                cp -R . "$out/"
                chmod -R u+w "$out"
                runHook postInstall
              '';
              meta = {
                description = "OpenAI Codex CLI";
                homepage = "https://developers.openai.com/codex/cli";
                license = final.lib.licenses.asl20;
                mainProgram = "codex";
                platforms = [ "x86_64-linux" ];
                sourceProvenance = [ final.lib.sourceTypes.binaryNativeCode ];
              };
            };
            hermes-release = hermes.packages.${system}.minimal;
            omp-release = final.stdenvNoCC.mkDerivation {
              pname = "oh-my-pi";
              version = releases.omp.version;
              src = final.fetchurl {
                inherit (releases.omp) url hash;
              };
              dontUnpack = true;
              nativeBuildInputs = [ final.makeBinaryWrapper ];
              dontStrip = true;
              installPhase = ''
                runHook preInstall
                install -Dm755 "$src" "$out/libexec/omp"
                makeWrapper ${final.glibc}/lib/ld-linux-x86-64.so.2 "$out/bin/omp" \
                  --add-flags --library-path \
                  --add-flags ${final.glibc}/lib \
                  --add-flags "$out/libexec/omp"
                runHook postInstall
              '';
              meta = {
                description = "AI coding agent for the terminal";
                homepage = "https://github.com/can1357/oh-my-pi";
                license = final.lib.licenses.mit;
                mainProgram = "omp";
                platforms = [ "x86_64-linux" ];
                sourceProvenance = with final.lib.sourceTypes; [
                  binaryNativeCode
                  binaryBytecode
                ];
              };
            };
            opencode-release = final.stdenvNoCC.mkDerivation {
              pname = "opencode";
              version = releases.opencode.version;
              src = final.fetchurl {
                inherit (releases.opencode) url hash;
              };
              sourceRoot = ".";
              nativeBuildInputs = [
                final.autoPatchelfHook
                final.makeBinaryWrapper
              ];
              buildInputs = [ final.glibc ];
              runtimeDependencies = [ final.glibc ];
              dontStrip = true;
              installPhase = ''
                runHook preInstall
                install -Dm755 opencode "$out/bin/opencode"
                wrapProgram "$out/bin/opencode" \
                  --prefix PATH : ${final.lib.makeBinPath [ final.ripgrep ]} \
                  --set OPENCODE_DISABLE_AUTOUPDATE true
                runHook postInstall
              '';
              meta = {
                description = "AI coding agent built for the terminal";
                homepage = "https://opencode.ai";
                license = final.lib.licenses.mit;
                mainProgram = "opencode";
                platforms = [ "x86_64-linux" ];
                sourceProvenance = with final.lib.sourceTypes; [
                  binaryNativeCode
                  binaryBytecode
                ];
              };
            };
            ori-release = final.stdenvNoCC.mkDerivation {
              pname = "ori";
              version = releases.ori.version;
              src = final.fetchurl {
                inherit (releases.ori) url hash;
              };
              dontUnpack = true;
              nativeBuildInputs = [ final.makeBinaryWrapper ];
              dontStrip = true;
              installPhase = ''
                runHook preInstall
                install -Dm755 "$src" "$out/libexec/ori"
                makeWrapper ${final.glibc}/lib/ld-linux-x86-64.so.2 "$out/bin/ori" \
                  --add-flags --library-path \
                  --add-flags ${final.glibc}/lib \
                  --add-flags "$out/libexec/ori" \
                  --set ORI_NO_UPDATE_CHECK 1 \
                  --set ORI_TELEMETRY 0
                runHook postInstall
              '';
              meta = {
                description = "OpenRouter harness for local coding agents";
                homepage = "https://openrouter.ai/blog/announcements/ori-harness/";
                license = final.lib.licenses.asl20;
                mainProgram = "ori";
                platforms = [ "x86_64-linux" ];
                sourceProvenance = with final.lib.sourceTypes; [
                  binaryNativeCode
                  binaryBytecode
                ];
              };
            };
          })
        ];
        # Whitelist specific unfree packages instead of globally setting allowUnfree,
        # so a typo elsewhere can't silently pull in additional unfree
        # deps.
        config.allowUnfreePredicate =
          pkg:
          builtins.elem (nixpkgs.lib.getName pkg) [
            "claude-code"
            "github-copilot-cli"
          ];
        config.permittedInsecurePackages = [
          # Keybase requires an EOL Electron release for desktop notifications.
          "keybase-gui-6.5.1"
        ];
      };

      mkProfile =
        module:
        home-manager.lib.homeManagerConfiguration {
          inherit pkgs;
          modules = [ module ];
          # Path to the cloned dotfiles checkout — passed in so the
          # modules can symlink shared configs from the same repo.
          extraSpecialArgs = {
            dotfilesRoot = ../.;
          };
        };
    in
    {
      devShells.${system}.default = pkgs.mkShellNoCC {
        packages = with pkgs; [
          basedpyright
          just
          nixfmt
          prettier
          ruff
          selene
          shellcheck
          shfmt
          stylua
          taplo
        ];
      };

      homeConfigurations = {
        vm = mkProfile ./vm.nix;
        host = mkProfile ./host.nix;
      };
    };
}