Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/nix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Test Nix Flake
on:
push:
branches: [main]
pull_request:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
nix-flake-check:
steps:
- uses: actions/checkout@v5
with:
submodules: recursive
- uses: cachix/install-nix-action@v31
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: nix flake check for all platforms
run: |
nix flake check --all-systems
nix-build-linux:
steps:
- uses: actions/checkout@v5
with:
submodules: recursive
- uses: cachix/install-nix-action@v31
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: nix build . for x86_64-linux
run: nix build .
nix-build-macos:
steps:
- uses: actions/checkout@v5
with:
submodules: recursive
- uses: cachix/install-nix-action@v31
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: nix build for x86_64-darwin
run: nix build .
37 changes: 25 additions & 12 deletions codex-rs/default.nix
Original file line number Diff line number Diff line change
@@ -1,40 +1,53 @@
{ pkgs, monorep-deps ? [], ... }:
let
{
pkgs,
monorepo-deps ? [],
...
}: let
lib = pkgs.lib;

env = {
PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig:$PKG_CONFIG_PATH";
};
in
rec {
in rec {
package = pkgs.rustPlatform.buildRustPackage {
inherit env;
pname = "codex-rs";
version = "0.1.0";
cargoLock.lockFile = ./Cargo.lock;
doCheck = false;
src = ./.;

cargoLock = {
lockFile = ./Cargo.lock;
# ratatui is patched via git, so we must whitelist its fixed-output hash
outputHashes = {
"ratatui-0.29.0" = "sha256-HBvT5c8GsiCxMffNjJGLmHnvG77A6cqEL+1ARurBXho=";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid this cannot be managed by dependabot or any automated system.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah its super unfortunate, and according to our mutual friend, o3, this seems like the lesser of evils...

I presume you all plan on getting your changes merged to ratatui upstream, that would definitely clean it up. But I'm also happy to help, this flake is a part of my dotfiles now, so you all can ping me whenever the action breaks, honestly I'd much prefer being pinged than the flake not work :)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Pls excuse the drive-by commenting)

If you do want to maintain this long term, you can write a small script that does something to the effect of nix-prefetch-url --unpack --type sha256 $URL and writes it into something like foo.nix then do import ./foo.nix there. Give or take some datastructure adjustments.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ya that seems like a lot of extra work for something where there hasnt been changes in 3 weeks: https://github.com/nornagon/ratatui/tree/nornagon-v0.29.0-patch I'd like to better understand the plans to upstream

};
};

doCheck = false;

nativeBuildInputs = with pkgs; [
pkg-config
openssl
];
meta = with pkgs.lib; {
description = "OpenAI Codex command‑line interface rust implementation";

meta = with lib; {
description = "OpenAI Codex command line interface rust implementation";
license = licenses.asl20;
homepage = "https://github.com/openai/codex";
};
};

devShell = pkgs.mkShell {
inherit env;
name = "codex-rs-dev";
packages = monorep-deps ++ [
pkgs.cargo
package
];
packages = monorepo-deps ++ [package];
shellHook = ''
echo "Entering development shell for codex-rs"
alias codex="cd ${package.src}/tui; cargo run; cd -"
${pkgs.rustPlatform.cargoSetupHook}
'';
};

app = {
type = "app";
program = "${package}/bin/codex";
Expand Down
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

100 changes: 61 additions & 39 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,70 @@
};
};

outputs = { nixpkgs, flake-utils, rust-overlay, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
};
pkgsWithRust = import nixpkgs {
inherit system;
overlays = [ rust-overlay.overlays.default ];
};
monorepo-deps = with pkgs; [
# for precommit hook
pnpm
husky
outputs = {
self,
nixpkgs,
flake-utils,
rust-overlay,
...
}:
flake-utils.lib.eachDefaultSystem (system: let
# Base pkgs with the Rust overlay
pkgsBase = import nixpkgs {
inherit system;
overlays = [rust-overlay.overlays.default];
};

# Use toolchain pinned in ./codex-rs/rust-toolchain.toml, fallback to stable 1.89.0
rustToolchain =
if builtins.pathExists ./codex-rs/rust-toolchain.toml
then pkgsBase.rust-bin.fromRustupToolchainFile ./codex-rs/rust-toolchain.toml
else pkgsBase.rust-bin.stable."1.89.0".default;

# Reimport pkgs and override rustPlatform to use that toolchain for builds
pkgs = import nixpkgs {
inherit system;
overlays = [
rust-overlay.overlays.default
(final: prev: {
rustPlatform = prev.makeRustPlatform {
cargo = rustToolchain;
rustc = rustToolchain;
};
})
];
codex-cli = import ./codex-cli {
inherit pkgs monorepo-deps;
};
codex-rs = import ./codex-rs {
pkgs = pkgsWithRust;
inherit monorepo-deps;
};
in
rec {
packages = {
codex-cli = codex-cli.package;
codex-rs = codex-rs.package;
};
};

devShells = {
codex-cli = codex-cli.devShell;
codex-rs = codex-rs.devShell;
};
monorepo-deps = with pkgs; [
pnpm
husky
];

codex-rs = import ./codex-rs {
inherit pkgs monorepo-deps;
};
in rec {
packages = {
codex-rs = codex-rs.package;
default = codex-rs.package;
};

apps = {
codex-rs = codex-rs.app;
default = codex-rs.app;
};

apps = {
codex-cli = codex-cli.app;
codex-rs = codex-rs.app;
devShells = {
# Dev shell includes the pinned toolchain on PATH
codex-rs = pkgs.mkShell {
packages = monorepo-deps ++ [rustToolchain codex-rs.package];
};
default = devShells.codex-rs;
};

defaultPackage = packages.codex-cli;
defaultApp = apps.codex-cli;
defaultDevShell = devShells.codex-cli;
}
);
# Optional CI hook to ensure the package builds
checks = {
codex-rs-build = packages.codex-rs;
};
});
}