mirror of
https://github.com/0xrsydn/idx-cli.git
synced 2026-11-07 01:35:36 +00:00
Addresses review on #29: - drop errtrace: a failure inside $(...) printed two RESULT lines - explicit failures go through fail(), which always prints RESULT: FAILED stage=...; idx check gets its own `preflight` stage; the never-failing published-manifest read is no longer a stage - validate the built latest_as_of_date (`// empty` + date regex) so a corrupt manifest cannot compare as "newer" - freshness: validate --now (exit 2) and latest_as_of_date (exit 3) before calling date - flake: package an explicit script list instead of scripts/*.sh - docs: GH_TOKEN prerequisite for the packaged publisher Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017a5Cv5Z1NzdYKgKnTiAF4E
130 lines
4.3 KiB
Nix
130 lines
4.3 KiB
Nix
{
|
|
description = "idx-cli — CLI tool for Indonesian stock market (IDX) analysis";
|
|
|
|
inputs = {
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
rust-overlay = {
|
|
url = "github:oxalica/rust-overlay";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
};
|
|
|
|
outputs = { self, nixpkgs, flake-utils, rust-overlay }:
|
|
flake-utils.lib.eachDefaultSystem (system:
|
|
let
|
|
overlays = [ (import rust-overlay) ];
|
|
pkgs = import nixpkgs { inherit system overlays; };
|
|
lib = pkgs.lib;
|
|
cargoManifest = builtins.fromTOML (builtins.readFile ./Cargo.toml);
|
|
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
|
|
extensions = [ "rust-src" "rust-analyzer" ];
|
|
};
|
|
rustPlatform = pkgs.makeRustPlatform {
|
|
cargo = rustToolchain;
|
|
rustc = rustToolchain;
|
|
};
|
|
runtimeDeps = with pkgs; [
|
|
curl-impersonate
|
|
mupdf
|
|
];
|
|
idxPackage = rustPlatform.buildRustPackage {
|
|
pname = cargoManifest.package.name;
|
|
version = cargoManifest.package.version;
|
|
src = lib.cleanSource ./.;
|
|
cargoLock = {
|
|
lockFile = ./Cargo.lock;
|
|
};
|
|
doCheck = false;
|
|
nativeBuildInputs = with pkgs; [
|
|
makeWrapper
|
|
pkg-config
|
|
];
|
|
buildInputs = with pkgs; [
|
|
openssl
|
|
];
|
|
postInstall = ''
|
|
wrapProgram "$out/bin/idx" \
|
|
--prefix PATH : "${lib.makeBinPath runtimeDeps}"
|
|
'';
|
|
};
|
|
# Self-contained ownership snapshot publisher for scheduled hosts
|
|
# (e.g. a NixOS systemd timer): no checkout, `nix develop` or cargo
|
|
# build at run time. Wraps the repo scripts with a pinned `idx`.
|
|
publisherTools = with pkgs; [
|
|
bash
|
|
coreutils
|
|
curl
|
|
gawk
|
|
gh
|
|
gnugrep
|
|
gnused
|
|
jq
|
|
sqlite
|
|
];
|
|
publisherScripts = [
|
|
./scripts/build-ownership-snapshot.sh
|
|
./scripts/build-latest-ownership-snapshot.sh
|
|
./scripts/publish-ownership-snapshot.sh
|
|
./scripts/check-ownership-snapshot-freshness.sh
|
|
];
|
|
ownershipPublisher = pkgs.stdenvNoCC.mkDerivation {
|
|
pname = "idx-ownership-publisher";
|
|
version = cargoManifest.package.version;
|
|
src = lib.fileset.toSource {
|
|
root = ./.;
|
|
fileset = lib.fileset.unions publisherScripts;
|
|
};
|
|
nativeBuildInputs = [ pkgs.makeWrapper ];
|
|
dontBuild = true;
|
|
installPhase = ''
|
|
runHook preInstall
|
|
mkdir -p "$out/libexec/idx-ownership" "$out/bin"
|
|
cp ${lib.concatMapStringsSep " " (script: "scripts/${baseNameOf script}") publisherScripts} \
|
|
"$out/libexec/idx-ownership/"
|
|
chmod +x "$out"/libexec/idx-ownership/*.sh
|
|
patchShebangs "$out/libexec/idx-ownership"
|
|
|
|
makeWrapper "$out/libexec/idx-ownership/publish-ownership-snapshot.sh" \
|
|
"$out/bin/idx-ownership-publish" \
|
|
--prefix PATH : "${lib.makeBinPath ([ idxPackage ] ++ publisherTools)}" \
|
|
--add-flags "--idx-bin ${idxPackage}/bin/idx"
|
|
makeWrapper "$out/libexec/idx-ownership/check-ownership-snapshot-freshness.sh" \
|
|
"$out/bin/idx-ownership-freshness" \
|
|
--prefix PATH : "${lib.makeBinPath publisherTools}"
|
|
runHook postInstall
|
|
'';
|
|
meta.mainProgram = "idx-ownership-publish";
|
|
};
|
|
in
|
|
{
|
|
packages.default = idxPackage;
|
|
packages.ownership-publisher = ownershipPublisher;
|
|
apps.default = {
|
|
type = "app";
|
|
program = "${idxPackage}/bin/idx";
|
|
};
|
|
checks.default = idxPackage;
|
|
checks.ownership-publisher = ownershipPublisher;
|
|
|
|
devShells.default = pkgs.mkShell {
|
|
inputsFrom = [ idxPackage ];
|
|
packages = with pkgs; [
|
|
rustToolchain
|
|
nodejs_22
|
|
cargo-watch
|
|
cargo-nextest
|
|
prek
|
|
] ++ runtimeDeps;
|
|
|
|
shellHook = ''
|
|
export PATH="$PWD/target/debug:$PATH"
|
|
'';
|
|
|
|
env = {
|
|
RUST_BACKTRACE = "1";
|
|
};
|
|
};
|
|
}
|
|
);
|
|
}
|