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