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 using our custom task
48+ nimble refresh
49+ echo "Running nimble build with maximum verbosity..."
50+ echo "Building godon_cli.nim binary..."
51+ # Test basic compilation without godon imports first
52+ echo 'echo "Basic compilation test"' > test_basic.nim
53+ nim c --hints:on -d:release -o:bin/godon_cli test_basic.nim || {
54+ echo "Basic compilation failed - this is a Nim/Nix environment issue"
55+ exit 1
56+ }
57+
58+ echo "Now testing minimal imports with proper path..."
59+ nim c --hints:on --path:src -d:release -o:bin/test_imports test_imports.nim || {
60+ echo "Minimal import test failed - there's a fundamental module issue"
61+ exit 1
62+ }
63+
64+ echo "Now testing ultra-minimal to isolate the issue..."
65+ echo 'echo "test"' > test_ultra.nim
66+ nim c --hints:on -d:release -o:bin/test_ultra test_ultra.nim || {
67+ echo "Ultra-minimal test failed - this is a Nim environment issue"
68+ exit 1
69+ }
70+
71+ echo "Now testing just parseopt without godon imports..."
72+ cat > test_parseopt.nim << 'EOF'
73+ import std/[strutils]
74+ proc test() =
75+ var args: seq[string] = @["a", "b", "c"]
76+ let lenVal: int = args.len
77+ echo "args.len: ", lenVal
78+ echo "Test completed"
79+ when isMainModule:
80+ test()
81+ EOF
82+ nim c --hints:on -d:release -o:bin/test_parseopt test_parseopt.nim || {
83+ echo "Parseopt test failed - issue with std lib or range operations"
84+ exit 1
85+ }
86+
87+ echo "Now trying simplified CLI without loops..."
88+ nim c --hints:on --path:src -d:release -d:VERSION="${ version } " -o:bin/godon_cli src/godon_cli_simple.nim || {
89+ echo "Simplified CLI failed - still an issue"
90+ exit 1
91+ }
92+
93+ echo "Build completed successfully!"
94+ echo "Build failed, checking for syntax errors..."
95+ echo "Current directory: $(pwd)"
96+ echo "Files in src:"
97+ ls -la src/
98+ echo "Files in src/godon:"
99+ ls -la src/godon/
100+ echo "Trying direct nim compilation check..."
101+ nim --hints:on check src/godon_cli.nim || true
102+ exit 1
103+ }
104+ '' ;
105+
106+ installPhase = ''
107+ mkdir -p $out/bin
108+
109+ echo "Looking for compiled binary..."
110+ echo "Current directory: $(pwd)"
111+ echo "Directory contents:"
112+ find . -name "godon_cli*" -type f -executable 2>/dev/null || true
113+
114+ # Install main binary - try multiple locations
115+ if [ -f "bin/godon_cli" ]; then
116+ echo "Found binary in bin/godon_cli"
117+ cp bin/godon_cli $out/bin/
118+ elif [ -f "godon_cli" ]; then
119+ echo "Found binary in godon_cli"
120+ cp godon_cli $out/bin/
121+ elif [ -f "src/godon_cli" ]; then
122+ echo "Found binary in src/godon_cli"
123+ cp src/godon_cli $out/bin/godon_cli
124+ else
125+ echo "Binary not found in any expected location!"
126+ echo "Full directory listing:"
127+ ls -la
128+ echo "nimble cache:"
129+ ls -la ~/.nimble/bin/ 2>/dev/null || true
130+ exit 1
131+ fi
132+
133+ # Make binary executable
134+ chmod +x $out/bin/godon_cli
135+
136+ echo "✅ Installation completed successfully!"
137+ echo "Installed binary: "
138+ ls -la $out/bin/
139+ '' ;
140+
141+ meta = with pkgs . lib ; {
142+ description = "CLI for the Godon API" ;
143+ license = licenses . agpl3Only ;
144+ platforms = platforms . all ;
145+ } ;
146+ } ;
147+
148+ in {
149+ packages . default = godon-cli { } ;
150+ packages . godon-cli = godon-cli ;
151+
152+ # Allow building with custom version
153+ packages . godon-cli-custom = version : godon-cli { inherit version ; } ;
154+
155+ # Development shell with Nim and build tools
156+ devShells . default = pkgs . mkShell {
157+ buildInputs = with pkgs ; [
158+ nim2
159+ nimble
160+ git
161+ ] ;
162+
163+ shellHook = ''
164+ echo "Godon CLI development environment"
165+ echo "Nim: $(nim --version | head -n1)"
166+ echo "Nimble: $(nimble --version | head -n1)"
167+ '' ;
168+ } ;
169+ } ) ;
170+ }
0 commit comments