1+ {
2+ description = "Godon CLI - Nim-based CLI for Godon API" ;
3+
4+ inputs = {
5+ nixpkgs . url = "github:NixOS/nixpkgs/nixos-25.11" ;
6+ flake-utils . url = "github:numtide/flake-utils" ;
7+ } ;
8+
9+ outputs = { self , nixpkgs , flake-utils } :
10+ flake-utils . lib . eachDefaultSystem ( system :
11+ let
12+ pkgs = nixpkgs . legacyPackages . ${ system } ;
13+
14+ # Build using nimble following the godon-api pattern
15+ godon-cli = { version ? "DEV_BUILD" } : pkgs . stdenv . mkDerivation {
16+ pname = "godon-cli" ;
17+ inherit version ;
18+ src = ./. ;
19+
20+ nativeBuildInputs = with pkgs ; [
21+ cacert
22+ nim2
23+ nimble
24+ git
25+ openssl . dev
26+ ] ;
27+
28+ env = {
29+ SSL_CERT_FILE = "${ pkgs . cacert } /etc/ssl/certs/ca-bundle.crt" ;
30+ NIX_SSL_CERT_FILE = "${ pkgs . cacert } /etc/ssl/certs/ca-bundle.crt" ;
31+ CURL_CA_BUNDLE = "${ pkgs . cacert } /etc/ssl/certs/ca-bundle.crt" ;
32+ } ;
33+
34+ configurePhase = ''
35+ export HOME=$TMPDIR
36+ echo "Building godon-cli"
37+ echo "SSL_CERT_FILE: $SSL_CERT_FILE"
38+ echo "Certificate exists: $([ -f "$SSL_CERT_FILE" ] && echo "YES" || echo "NO")"
39+ '' ;
40+
41+ buildPhase = ''
42+ echo "Using documentation-based SSL setup..."
43+ echo "Certificate file: $SSL_CERT_FILE"
44+ echo "Nim version: $(nim --version | head -n1)"
45+ echo "Building version: ${ version } "
46+
47+ # Refresh package list and build
48+ nimble refresh
49+ nimble build --verbose -d:release -d:VERSION="${ version } "
50+ '' ;
51+
52+ installPhase = ''
53+ mkdir -p $out/bin
54+
55+ echo "Looking for compiled binary..."
56+ echo "Current directory: $(pwd)"
57+ echo "Directory contents:"
58+ find . -name "godon_cli*" -type f -executable 2>/dev/null || true
59+
60+ # Install main binary - try multiple locations
61+ if [ -f "bin/godon_cli" ]; then
62+ echo "Found binary in bin/godon_cli"
63+ cp bin/godon_cli $out/bin/
64+ elif [ -f "godon_cli" ]; then
65+ echo "Found binary in godon_cli"
66+ cp godon_cli $out/bin/
67+ elif [ -f "src/godon_cli" ]; then
68+ echo "Found binary in src/godon_cli"
69+ cp src/godon_cli $out/bin/godon_cli
70+ else
71+ echo "Binary not found in any expected location!"
72+ echo "Full directory listing:"
73+ ls -la
74+ echo "nimble cache:"
75+ ls -la ~/.nimble/bin/ 2>/dev/null || true
76+ exit 1
77+ fi
78+
79+ # Make binary executable
80+ chmod +x $out/bin/godon_cli
81+
82+ echo "✅ Installation completed successfully!"
83+ echo "Installed binary: "
84+ ls -la $out/bin/
85+ '' ;
86+
87+ meta = with pkgs . lib ; {
88+ description = "CLI for the Godon API" ;
89+ license = licenses . agpl3Only ;
90+ platforms = platforms . all ;
91+ } ;
92+ } ;
93+
94+ in {
95+ packages . default = godon-cli { } ;
96+ packages . godon-cli = godon-cli ;
97+
98+ # Allow building with custom version
99+ packages . godon-cli-custom = version : godon-cli { inherit version ; } ;
100+
101+ # Development shell with Nim and build tools
102+ devShells . default = pkgs . mkShell {
103+ buildInputs = with pkgs ; [
104+ nim2
105+ nimble
106+ git
107+ ] ;
108+
109+ shellHook = ''
110+ echo "Godon CLI development environment"
111+ echo "Nim: $(nim --version | head -n1)"
112+ echo "Nimble: $(nimble --version | head -n1)"
113+ '' ;
114+ } ;
115+ } ) ;
116+ }
0 commit comments