flk 0.1.3

A CLI tool for managing flake.nix files like Jetify Devbox
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
# flk πŸš€

> A modern CLI tool for managing Nix flake development environments with the simplicity of Devbox

[![Crates.io](https://img.shields.io/crates/v/flk.svg)](https://crates.io/crates/flk)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Rust](https://img.shields.io/badge/rust-1.70%2B-blue.svg)](https://www.rust-lang.org)

**flk** makes managing Nix flakes feel like using a package manager. No more manually editing `flake.nix` filesβ€”just use simple commands to add packages, create custom shell commands, and manage your development environment.

## ✨ Features

- 🎯 **Smart Initialization** - Auto-detects your project type (Rust, Python, Node.js, Go) and creates the right template
- πŸ” **Package Search** - Search nixpkgs directly from your terminal
- πŸ“¦ **Easy Package Management** - Add and remove packages with simple commands
- ⚑ **Custom Shell Commands** - Define reusable commands for your development workflow
- 🌍 **Environment Variables** - Manage environment variables through the CLI
- πŸ”’ **Lock File Management** - View, backup, and restore your flake.lock with ease
- 🎨 **Language Templates** - Pre-configured templates for popular languages and frameworks

## πŸ“¦ Installation

### Prerequisites

- [Nix]https://nixos.org/download.html with flakes enabled
- Rust 1.70+ (if building from source)

### From Source

```bash
git clone https://github.com/AEduardo-dev/flk.git
cd flk
cargo build --release
sudo cp target/release/flk /usr/local/bin/
```

### From Cargo (Coming Soon)

```bash
cargo install flk
```

### With Nix

```bash
nix profile install github:AEduardo-dev/flk
```

## πŸš€ Quick Start

### 1. Initialize Your Project

```bash
# Auto-detect project type and create flake.nix
flk init

# Or specify a template
flk init --template rust
flk init --template python
flk init --template node
flk init --template go
```

**Supported auto-detection:**

- `Cargo.toml` β†’ Rust template
- `package.json` β†’ Node.js template
- `pyproject.toml` or `requirements.txt` β†’ Python template
- `go.mod` β†’ Go template

### 2. Add Packages

```bash
# Search for packages
flk search ripgrep

# Get detailed package info
flk deep-search ripgrep --versions

# Add packages to your environment
flk add ripgrep
flk add git
flk add neovim
```

### 3. Add Custom Commands

```bash
# Add inline commands
flk add-command test "cargo test --all"
flk add-command dev "npm run dev"

# Source commands from a file
flk add-command scripts --file ./scripts/dev.sh
```

### 4. Manage Environment Variables

```bash
# Add environment variables
flk env add DATABASE_URL "postgresql://localhost/mydb"
flk env add API_KEY "your-api-key"

# List all environment variables
flk env list

# Remove an environment variable
flk env remove API_KEY
```

### 5. Enter Your Development Environment

```bash
nix develop
```

Your custom commands and environment variables will be automatically available!

### 6. Generate completions

```bash
# Generates the completion file and prints it
flk completions

# Install the generated completions to the detected shell
flk completions --install
```

Follow the instructions after the command to make the completions available for you.

## πŸ“– Command Reference

### Project Management

#### `flk init [OPTIONS]`

Initialize a new `flake.nix` in the current directory.

**Options:**

- `-t, --template <TYPE>` - Project type: `rust`, `python`, `node`, `go`, or `generic`
- `-f, --force` - Overwrite existing `flake.nix`

**Examples:**

```bash
flk init                    # Auto-detect project type
flk init --template rust    # Use Rust template
flk init --force            # Overwrite existing flake.nix
```

#### `flk show`

Display the contents and configuration of your `flake.nix` in a human-readable format.

```bash
flk show
```

#### `flk list`

List all packages in your development environment.

```bash
flk list
```

### Package Management

#### `flk search <QUERY> [OPTIONS]`

Search for packages in nixpkgs.

**Options:**

- `-l, --limit <NUMBER>` - Limit number of results (default: 10)

**Examples:**

```bash
flk search ripgrep
flk search python --limit 20
```

#### `flk deep-search <PACKAGE> [OPTIONS]`

Get detailed information about a specific package.

**Options:**

- `-v, --versions` - Show version pinning information

**Examples:**

```bash
flk deep-search ripgrep
flk deep-search python311 --versions
```

#### `flk add <PACKAGE>`

Add a package to your `flake.nix`.

**Examples:**

```bash
flk add ripgrep
flk add git
flk add nodejs
```

**Note:** Version pinning is planned for a future release (see [issue #5](https://github.com/AEduardo-dev/flk/issues/5)).

#### `flk remove <PACKAGE>`

Remove a package from your `flake.nix`.

**Examples:**

```bash
flk remove ripgrep
```

### Custom Commands

#### `flk add-command <NAME> <COMMAND> [OPTIONS]`

Add a custom shell command to your development environment.

**Options:**

- `-f, --file <PATH>` - Source commands from a file

**Examples:**

```bash
# Inline command
flk add-command test "cargo test --all"
flk add-command dev "npm run dev -- --watch"

# Multi-line command
flk add-command deploy "cargo build --release && scp target/release/app server:/opt/"

# Source from file
flk add-command scripts --file ./dev-scripts.sh
```

**Command naming rules:**

- Must contain only letters, numbers, hyphens, and underscores
- Cannot start with a hyphen
- Examples: `test`, `dev-server`, `build_prod`

#### `flk remove-command <NAME>`

Remove a custom command from your dev shell.

**Examples:**

```bash
flk remove-command test
```

### Environment Variables

#### `flk env add <NAME> <VALUE>`

Add an environment variable to your dev shell.

**Examples:**

```bash
flk env add DATABASE_URL "postgresql://localhost:5432/mydb"
flk env add NODE_ENV "development"
flk env add API_KEY "sk-..."
```

**Variable naming rules:**

- Must start with a letter or underscore
- Can only contain letters, numbers, and underscores
- Examples: `MY_VAR`, `_private`, `API_KEY_2`

#### `flk env remove <NAME>`

Remove an environment variable from your dev shell.

**Examples:**

```bash
flk env remove DATABASE_URL
```

#### `flk env list`

List all environment variables in your dev shell.

```bash
flk env list
```

### Lock File Management

#### `flk lock show`

Display detailed information about your `flake.lock` file.

```bash
flk lock show
```

#### `flk lock history`

Show backup history of your lock file.

```bash
flk lock history
```

#### `flk lock restore <BACKUP>`

Restore a previous version of your lock file.

**Examples:**

```bash
flk lock restore latest                    # Restore most recent backup
flk lock restore 2025-01-27_14-30-00      # Restore specific backup
```

### Updates

#### `flk update [OPTIONS]`

Update all flake inputs to their latest versions.

**Options:**

- `--show` - Preview updates without applying them

**Examples:**

```bash
flk update              # Update all inputs
flk update --show       # Preview available updates
```

**Note:** A backup of your `flake.lock` is automatically created before updating.

## πŸ’‘ Usage Examples

### Python Data Science Environment

```bash
flk init --template python
flk add python311Packages.numpy
flk add python311Packages.pandas
flk add python311Packages.matplotlib
flk add jupyter

flk add-command notebook "jupyter notebook --port=8888"
flk env add JUPYTER_CONFIG_DIR "./.jupyter"

nix develop
notebook  # Your custom command is ready!
```

### Rust Web Development

```bash
flk init --template rust
flk add postgresql
flk add redis

flk add-command dev "cargo watch -x run"
flk add-command migrate "sqlx migrate run"
flk env add DATABASE_URL "postgresql://localhost/myapp"

nix develop
dev      # Start development server with auto-reload
migrate  # Run database migrations
```

### Node.js Full-Stack Project

```bash
flk init --template node
flk add postgresql
flk add docker-compose

flk add-command dev "npm run dev"
flk add-command db "docker-compose up -d postgres"
flk env add NODE_ENV "development"

nix develop
db   # Start database
dev  # Start development server
```

### Go Microservice

```bash
flk init --template go
flk add protobuf
flk add grpcurl

flk add-command build "go build -o bin/service ./cmd/service"
flk add-command proto "protoc --go_out=. --go-grpc_out=. api/*.proto"
flk env add GO_ENV "development"

nix develop
proto  # Generate protobuf code
build  # Build the service
```

## πŸ› οΈ Development

### Prerequisites

- Rust 1.70+
- Nix with flakes enabled

### Building

```bash
git clone https://github.com/AEduardo-dev/flk.git
cd flk
cargo build
```

### Running Tests

```bash
# Run all tests
cargo test

# Run integration tests
cargo test --test integration_tests

# Run with output
cargo test -- --nocapture
```

### Installing Locally

```bash
cargo install --path .
```

## πŸ—οΈ Project Structure

```
flk/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main.rs              # CLI entry point
β”‚   β”œβ”€β”€ commands/            # Command implementations
β”‚   β”‚   β”œβ”€β”€ init.rs          # Initialize flake
β”‚   β”‚   β”œβ”€β”€ add.rs           # Add packages
β”‚   β”‚   β”œβ”€β”€ remove.rs        # Remove packages
β”‚   β”‚   β”œβ”€β”€ search.rs        # Search packages
β”‚   β”‚   β”œβ”€β”€ add_command.rs   # Add custom commands
β”‚   β”‚   β”œβ”€β”€ remove_command.rs
β”‚   β”‚   β”œβ”€β”€ env.rs           # Environment variable management
β”‚   β”‚   β”œβ”€β”€ lock.rs          # Lock file management
β”‚   β”‚   β”œβ”€β”€ update.rs        # Update flake inputs
β”‚   β”‚   β”œβ”€β”€ show.rs          # Display flake config
β”‚   β”‚   └── list.rs          # List packages
β”‚   β”œβ”€β”€ flake/               # Flake parsing and generation
β”‚   β”‚   β”œβ”€β”€ parser.rs        # Parse flake.nix
β”‚   β”‚   β”œβ”€β”€ generator.rs     # Generate flake.nix
β”‚   β”‚   └── interface.rs     # Data structures
β”‚   β”œβ”€β”€ nix/                 # Nix command wrappers
β”‚   β”‚   └── mod.rs
β”‚   └── utils/               # Utility functions
β”‚       └── backup.rs        # Backup management
β”œβ”€β”€ templates/               # Flake templates
β”‚   β”œβ”€β”€ default_flake.nix
β”‚   β”œβ”€β”€ rust_flake.nix
β”‚   β”œβ”€β”€ python_flake.nix
β”‚   β”œβ”€β”€ node_flake.nix
β”‚   └── go_flake.nix
└── tests/                   # Test files
    β”œβ”€β”€ integration_tests.rs
    └── unit_tests.rs
```

## πŸ—ΊοΈ Roadmap

[Roadmap](https://github.com/AEduardo-dev/flk/issues/6)

## 🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

### How to Contribute

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

## πŸ› Bug Reports

If you find a bug, please open an issue with:

- A clear description of the problem
- Steps to reproduce
- Expected vs actual behavior
- Your environment (OS, Nix version, etc.)

## πŸ”— Related Projects

- [Devbox]https://github.com/jetify-com/devbox - Instant, portable dev environments (inspiration for flk)
- [devenv]https://devenv.sh/ - Fast, declarative developer environments
- [Flox]https://flox.dev/ - Developer environments you can take with you
- [direnv]https://direnv.net/ - Shell extension for loading environments

## πŸ“„ License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## πŸ™ Acknowledgments

- The Nix community for creating an amazing ecosystem
- Jetify for the Devbox inspiration and showing what's possible
- All contributors and users of flk

## πŸ“ž Support

- πŸ“§ Open an [issue]https://github.com/AEduardo-dev/flk/issues for bug reports or feature requests
- πŸ’¬ Start a [discussion]https://github.com/AEduardo-dev/flk/discussions for questions or ideas
- ⭐ Star the repository if you find it useful!

---

**Made with ❀️ by [AEduardo-dev](https://github.com/AEduardo-dev)**

**Note:** This project is under active development (v0.1.0). While all core features are implemented and working, some advanced features like version pinning are still in progress. See the [roadmap](#-roadmap) for details.