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 trying with godon imports..."
59+ nim c --hints:on -d:release -d:VERSION="${ version } " -o:bin/godon_cli src/godon_cli.nim || {
60+ echo "Godon import compilation failed - checking module structure..."
61+ exit 1
62+ }
63+ echo "Build failed, checking for syntax errors..."
64+ echo "Current directory: $(pwd)"
65+ echo "Files in src:"
66+ ls -la src/
67+ echo "Files in src/godon:"
68+ ls -la src/godon/
69+ echo "Trying direct nim compilation check..."
70+ nim --hints:on check src/godon_cli.nim || true
71+ exit 1
72+ }
73+ '' ;
74+
75+ installPhase = ''
76+ mkdir -p $out/bin
77+
78+ echo "Looking for compiled binary..."
79+ echo "Current directory: $(pwd)"
80+ echo "Directory contents:"
81+ find . -name "godon_cli*" -type f -executable 2>/dev/null || true
82+
83+ # Install main binary - try multiple locations
84+ if [ -f "bin/godon_cli" ]; then
85+ echo "Found binary in bin/godon_cli"
86+ cp bin/godon_cli $out/bin/
87+ elif [ -f "godon_cli" ]; then
88+ echo "Found binary in godon_cli"
89+ cp godon_cli $out/bin/
90+ elif [ -f "src/godon_cli" ]; then
91+ echo "Found binary in src/godon_cli"
92+ cp src/godon_cli $out/bin/godon_cli
93+ else
94+ echo "Binary not found in any expected location!"
95+ echo "Full directory listing:"
96+ ls -la
97+ echo "nimble cache:"
98+ ls -la ~/.nimble/bin/ 2>/dev/null || true
99+ exit 1
100+ fi
101+
102+ # Make binary executable
103+ chmod +x $out/bin/godon_cli
104+
105+ echo "✅ Installation completed successfully!"
106+ echo "Installed binary: "
107+ ls -la $out/bin/
108+ '' ;
109+
110+ meta = with pkgs . lib ; {
111+ description = "CLI for the Godon API" ;
112+ license = licenses . agpl3Only ;
113+ platforms = platforms . all ;
114+ } ;
115+ } ;
116+
117+ in {
118+ packages . default = godon-cli { } ;
119+ packages . godon-cli = godon-cli ;
120+
121+ # Allow building with custom version
122+ packages . godon-cli-custom = version : godon-cli { inherit version ; } ;
123+
124+ # Development shell with Nim and build tools
125+ devShells . default = pkgs . mkShell {
126+ buildInputs = with pkgs ; [
127+ nim2
128+ nimble
129+ git
130+ ] ;
131+
132+ shellHook = ''
133+ echo "Godon CLI development environment"
134+ echo "Nim: $(nim --version | head -n1)"
135+ echo "Nimble: $(nimble --version | head -n1)"
136+ '' ;
137+ } ;
138+ } ) ;
139+ }
0 commit comments