Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
187 lines (160 loc) · 5.77 KB
/
Copy pathflake.nix
File metadata and controls
187 lines (160 loc) · 5.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
{
description = "Development environment for woplanner written in rust with htmx";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
# gives us access to more rust versions
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
# utils to build flakes for different systems
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, rust-overlay, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
extensions = [
"rust-src"
"rust-analyzer"
"rustfmt"
"clippy"
];
};
# Build-only toolchain (without dev extensions for smaller builds)
rustToolchainBuild = pkgs.rust-bin.stable.latest.default;
nativeBuildInputs = with pkgs; [
rustToolchain
sqlite
cargo-watch
cargo-edit
pkg-config
openssl
];
buildInputs = with pkgs; [
openssl
sqlite
] ++ lib.optionals pkgs.stdenv.isDarwin [
pkgs.darwin.apple_sdk.frameworks.Security
pkgs.darwin.apple_sdk.frameworks.SystemConfiguration
];
in
{
# Production package build
packages.default = pkgs.rustPlatform.buildRustPackage {
pname = "woplanner";
version = "0.1.0";
src = ./.;
cargoLock = {
lockFile = ./Cargo.lock;
};
nativeBuildInputs = with pkgs; [
pkg-config
rustToolchainBuild
];
buildInputs = with pkgs; [
openssl
sqlite
] ++ lib.optionals pkgs.stdenv.isDarwin [
pkgs.darwin.apple_sdk.frameworks.Security
pkgs.darwin.apple_sdk.frameworks.SystemConfiguration
];
# SQLx offline mode: use pre-generated query metadata
# Required because Nix sandbox has no database for compile-time query verification
SQLX_OFFLINE = true;
# Copy static files, templates, migrations to output
postInstall = ''
mkdir -p $out/share/woplanner
cp -r static templates migrations seeds $out/share/woplanner/
# Create wrapper script that sets correct paths
mv $out/bin/woplanner $out/bin/.woplanner-wrapped
cat > $out/bin/woplanner <<EOF
#!/bin/sh
cd $out/share/woplanner
exec $out/bin/.woplanner-wrapped "\$@"
EOF
chmod +x $out/bin/woplanner
'';
meta = with pkgs.lib; {
description = "WOPlanner - Progressive Web App for strength training";
homepage = "https://github.com/yourusername/woplanner";
license = licenses.mit;
maintainers = [ "David Dähne" ];
};
};
# OCI/Docker image
packages.docker = pkgs.dockerTools.buildImage {
name = "woplanner";
tag = "latest";
copyToRoot = pkgs.buildEnv {
name = "woplanner-env";
paths = with pkgs; [
self.packages.${system}.default
sqlite
cacert # For HTTPS
coreutils
bashInteractive
];
pathsToLink = [ "/bin" "/share" ];
};
config = {
Cmd = [ "${self.packages.${system}.default}/bin/woplanner" ];
ExposedPorts = {
"3000/tcp" = {};
};
Env = [
"DATABASE_URL=sqlite:/data/woplanner.db"
"SEED_DATABASE=false"
"PORT=3000"
];
WorkingDir = "/data";
Volumes = {
"/data" = {};
};
};
};
# Flake app for easy running
apps.default = {
type = "app";
program = "${self.packages.${system}.default}/bin/woplanner";
};
# Development shell
devShells.default = pkgs.mkShell {
inherit buildInputs nativeBuildInputs;
shellHook = ''
echo "🏋️ WOPlanner Development Environment"
echo "Rust version: $(rustc --version)"
echo "Cargo version: $(cargo --version)"
echo ""
echo "Available commands:"
echo " cargo run - Run the application"
echo " cargo build - Build the application"
echo " cargo watch -x run - Auto-restart on changes"
echo " cargo test - Run tests"
echo " cargo clippy - Run linter"
echo " cargo fmt - Format code"
echo " npm run assets - Copy bulma/htmx/chart.js into static/"
echo ""
echo "Nix commands:"
echo " nix build - Build production package"
echo " nix build .#docker - Build OCI/Docker image"
echo " nix run - Run production build"
echo ""
echo "Database:"
echo " DATABASE_URL=${"\$DATABASE_URL"}"
echo " SEED_DATABASE=${"\$SEED_DATABASE"} (set to 'false' to disable sample data)"
echo ""
# Rust-Analyzer für bessere IDE-Unterstützung
export RUST_SRC_PATH="${rustToolchain}/lib/rustlib/src/rust/library"
# Database URL (SQLite als Standard)
export DATABASE_URL="sqlite:./bodybuilding.db"
# Enable seeds in development by default
export SEED_DATABASE="''${SEED_DATABASE:-true}"
'';
};
});
}