Skip to content

Commit 4e2e2b6

Browse files
samroseyvan-sraka
authored andcommitted
feat: package and activation
1 parent 2e42d1c commit 4e2e2b6

File tree

2 files changed

+126
-15
lines changed

2 files changed

+126
-15
lines changed

flake.nix

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,6 @@
170170
mkdir -p /etc/auth.d
171171
mkdir -p /etc/gotrue
172172
173-
# Create gotrue user if it doesn't exist
174-
if ! id "gotrue" &>/dev/null; then
175-
useradd -r -s /bin/false gotrue
176-
fi
177-
178173
# Set proper ownership
179174
chown -R gotrue:gotrue /opt/gotrue
180175
chown -R gotrue:gotrue /etc/auth.d
@@ -185,7 +180,7 @@
185180
chmod 775 /etc/auth.d
186181
chmod 775 /etc/gotrue
187182
188-
# Copy the binary
183+
# Copy the binary to the correct location
189184
cp ${auth-service}/bin/supabase-auth /opt/gotrue/gotrue
190185
chown gotrue:gotrue /opt/gotrue/gotrue
191186
chmod 755 /opt/gotrue/gotrue
@@ -194,15 +189,26 @@
194189
cp $out/lib/systemd/system/gotrue.service /etc/systemd/system/
195190
chmod 644 /etc/systemd/system/gotrue.service
196191
197-
# Copy the environment file
198-
cp $out/etc/auth.env /etc/gotrue.generated.env
199-
chown gotrue:gotrue /etc/gotrue.generated.env
200-
chmod 600 /etc/gotrue.generated.env
201-
202-
# Create symlinks for easy access
203-
ln -sf $out/bin/manage-auth /usr/local/bin/gotrue-manage
204-
ln -sf $out/share/gotrue/gotrue.service /usr/local/share/gotrue/gotrue.service
205-
ln -sf $out/bin/activate /usr/local/bin/auth-activate
192+
# Copy the environment file to the correct location
193+
cp $out/etc/auth.env /etc/auth.d/20_generated.env
194+
chown gotrue:gotrue /etc/auth.d/20_generated.env
195+
chmod 600 /etc/auth.d/20_generated.env
196+
197+
# Create symlinks for easy access from nix profile
198+
mkdir -p /usr/local/bin
199+
mkdir -p /usr/local/share/gotrue
200+
201+
# Create symlinks to the nix profile locations
202+
ln -sf "\$NIX_PROFILE/bin/manage-auth" /usr/local/bin/gotrue-manage
203+
ln -sf "\$NIX_PROFILE/share/gotrue/gotrue.service" /usr/local/share/gotrue/gotrue.service
204+
ln -sf "\$NIX_PROFILE/bin/activate" /usr/local/bin/auth-activate
205+
ln -sf "\$NIX_PROFILE/bin/gotrue" /usr/local/bin/gotrue
206+
207+
# Allow UFW connections to GoTrue metrics exporter if UFW is installed
208+
if command -v ufw >/dev/null 2>&1; then
209+
ufw allow 9122/tcp comment "GoTrue metrics exporter"
210+
echo "Added UFW rule for GoTrue metrics exporter"
211+
fi
206212
207213
# Reload systemd
208214
systemctl daemon-reload
@@ -213,12 +219,20 @@
213219
214220
echo "Gotrue service has been activated and started"
215221
echo "You can manage the service using: gotrue-manage {start|stop|restart|status}"
222+
echo "The following commands are available:"
223+
echo " gotrue-manage - Manage the Gotrue service"
224+
echo " auth-activate - Run this activation script again"
225+
echo " gotrue - The auth service binary"
216226
EOF
217227
chmod +x $out/bin/activate
218228
219229
# Create symlinks to the systemd unit files for easy access
220230
mkdir -p $out/share/gotrue
221231
ln -s $out/lib/systemd/system/gotrue.service $out/share/gotrue/gotrue.service
232+
233+
# Copy the auth binary to the package's bin directory
234+
cp ${auth-service}/bin/supabase-auth $out/bin/gotrue
235+
chmod +x $out/bin/gotrue
222236
'';
223237

224238
installPhase = "true";

nix/README.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Nix Configuration for Auth Service
2+
3+
This directory contains Nix modules and configurations for the Auth service. The setup allows for building and installing the Auth service using Nix, with proper systemd integration and configuration management.
4+
5+
## Files
6+
7+
- `auth-module.nix`: Defines the Nix module for the Auth service configuration
8+
- `steps-module.nix`: Defines the Nix module for service startup steps and commands
9+
10+
## Building and Installation
11+
12+
### Prerequisites
13+
14+
- Nix package manager installed
15+
- System with systemd (for service management)
16+
17+
### Installation
18+
19+
1. Install the package:
20+
```bash
21+
nix profile install .
22+
```
23+
24+
2. Activate the service:
25+
```bash
26+
sudo auth-activate
27+
```
28+
29+
### Available Commands
30+
31+
After installation, the following commands are available:
32+
33+
- `gotrue`: The auth service binary
34+
- `gotrue-manage`: Manage the service (start/stop/restart/status)
35+
- `auth-activate`: Run the activation script again
36+
37+
## Configuration
38+
39+
The service configuration is managed through environment variables, which are set in the Nix configuration. The main configuration file is generated at `/etc/auth.d/20_generated.env` during activation.
40+
41+
### Service Structure
42+
43+
- Binary: `/opt/gotrue/gotrue`
44+
- Config directory: `/etc/auth.d`
45+
- Systemd service: `gotrue.service`
46+
- Metrics port: 9122 (automatically configured in UFW if available)
47+
48+
## Development
49+
50+
### Updating the Service
51+
52+
1. Modify the relevant Nix files:
53+
- `flake.nix` for package definition and build process
54+
- `auth-module.nix` for service configuration
55+
- `steps-module.nix` for startup steps
56+
57+
2. Rebuild and reinstall:
58+
```bash
59+
nix profile install .
60+
sudo auth-activate
61+
```
62+
63+
### Testing Changes
64+
65+
1. Build the package:
66+
```bash
67+
nix build .
68+
```
69+
70+
2. The result will be in `./result/` with the following structure:
71+
- `bin/`: Contains the binary and management scripts
72+
- `share/gotrue/`: Contains the systemd service file
73+
- `etc/`: Contains the environment configuration
74+
75+
## System Requirements
76+
77+
- Linux system with systemd
78+
- UFW (optional, for metrics port configuration)
79+
- Proper permissions for the `gotrue` user (created by system image)
80+
81+
## Troubleshooting
82+
83+
1. If the service fails to start:
84+
- Check logs: `journalctl -u gotrue.service`
85+
- Verify permissions: `ls -l /opt/gotrue /etc/auth.d`
86+
- Check config: `cat /etc/auth.d/20_generated.env`
87+
88+
2. If commands are not found:
89+
- Verify installation: `nix profile list`
90+
- Check symlinks: `ls -l /usr/local/bin/gotrue*`
91+
92+
## Notes
93+
94+
- The activation script assumes the `gotrue` user exists (created by system image)
95+
- The service runs as the `gotrue` user
96+
- Configuration is managed through environment variables
97+
- The service is automatically started and enabled on activation

0 commit comments

Comments
 (0)