upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/docs/archive/2025-11-04-flake-migration.md
blob: 2d2514d7cbe37660b2585f9319d6390c5d39431c (plain)
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
# Flake Migration Complete

**Date:** November 4, 2025  
**Change:** Migrated from shell.nix to flake.nix

## What Changed

### Files Modified

1. **Created: grasp-audit/flake.nix**
   - Based on ../ngit/flake.nix
   - Uses rust-overlay for Rust toolchain
   - Includes devShell and package outputs
   - Properly configured with dependencies

2. **Removed: grasp-audit/shell.nix**
   - Old Nix shell configuration
   - Replaced by flake.nix

3. **Updated Documentation:**
   - grasp-audit/README.md
   - grasp-audit/QUICK_START.md
   - NEXT_SESSION_QUICKSTART.md
   - SMOKE_TEST_REPORT.md
   - FILES_CREATED.md

All references to `nix-shell` changed to `nix develop`.

## New Flake Configuration

```nix
{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    rust-overlay.url = "github:oxalica/rust-overlay";
    flake-utils.url = "github:numtide/flake-utils";
  };

  outputs = { nixpkgs, rust-overlay, flake-utils, ... }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        overlays = [ (import rust-overlay) ];
        pkgs = import nixpkgs { inherit system overlays; };
        manifest = pkgs.lib.importTOML ./Cargo.toml;
      in with pkgs; {
        devShells.default = mkShell {
          nativeBuildInputs = [
            rust-bin.stable.latest.default
            pkg-config
            gitlint
          ];
          buildInputs = [
            openssl
          ];
          shellHook = ''
            echo "πŸ¦€ GRASP Audit development environment loaded"
            # ... helpful messages ...
            export RUST_SRC_PATH=${pkgs.rustPlatform.rustLibSrc}
          '';
        };
        
        packages.default = pkgs.rustPlatform.buildRustPackage {
          pname = manifest.package.name;
          version = manifest.package.version;
          src = ./.;
          cargoLock = { lockFile = ./Cargo.lock; };
          buildInputs = [ openssl ];
          nativeBuildInputs = [ pkg-config ];
          doCheck = false;
        };
      });
}
```

## Flake Validation

```bash
$ cd grasp-audit && nix flake show
git+file:///persistent/dcdev/clones/ngit-grasp?dir=grasp-audit
β”œβ”€β”€β”€devShells
β”‚   β”œβ”€β”€β”€aarch64-darwin
β”‚   β”‚   └───default: omitted (use '--all-systems' to show)
β”‚   β”œβ”€β”€β”€aarch64-linux
β”‚   β”‚   └───default: omitted (use '--all-systems' to show)
β”‚   β”œβ”€β”€β”€x86_64-darwin
β”‚   β”‚   └───default: omitted (use '--all-systems' to show)
β”‚   └───x86_64-linux
β”‚       └───default: development environment 'nix-shell'
└───packages
    β”œβ”€β”€β”€aarch64-darwin
    β”‚   └───default: omitted (use '--all-systems' to show)
    β”œβ”€β”€β”€aarch64-linux
    β”‚   └───default: omitted (use '--all-systems' to show)
    β”œβ”€β”€β”€x86_64-darwin
    β”‚   └───default: omitted (use '--all-systems' to show)
    └───x86_64-linux
        └───default: package 'grasp-audit-0.1.0'
```

βœ… Flake is valid and provides:
- Dev shell for all major systems
- Package output for grasp-audit binary

## Usage

### Old Way (shell.nix)
```bash
cd grasp-audit
nix-shell
cargo build
```

### New Way (flake.nix)
```bash
cd grasp-audit
nix develop
cargo build
```

### Additional Flake Commands

```bash
# Show flake outputs
nix flake show

# Check flake validity
nix flake check

# Build the package directly
nix build

# Run without installing
nix run

# Update flake inputs
nix flake update
```

## Benefits of Flakes

1. **Reproducibility:** Locked inputs ensure consistent builds
2. **Multi-output:** Both dev shell and package in one file
3. **Standard:** Follows modern Nix best practices
4. **Composability:** Can be used as input to other flakes
5. **Better UX:** `nix develop` is clearer than `nix-shell`

## Updated Quick Start

```bash
# 1. Enter dev environment
cd grasp-audit
nix develop

# 2. Build
cargo build

# 3. Test
cargo test --lib

# 4. Run example
cargo run --example simple_audit
```

## Documentation Updates

All documentation has been updated to use `nix develop` instead of `nix-shell`:

- βœ… grasp-audit/README.md
- βœ… grasp-audit/QUICK_START.md
- βœ… NEXT_SESSION_QUICKSTART.md
- βœ… SMOKE_TEST_REPORT.md
- βœ… FILES_CREATED.md

## Next Steps

The flake is ready to use. Next session can:

1. **Enter dev environment:**
   ```bash
   cd grasp-audit
   nix develop
   ```

2. **Build and test:**
   ```bash
   cargo build
   cargo test --lib
   ```

3. **Continue with integration tests** (once relay is set up)

## Status

- βœ… Flake created and validated
- βœ… Documentation updated
- βœ… Old shell.nix removed
- βœ… Git tracking enabled
- 🚧 Dev environment ready (first run will download dependencies)
- 🚧 Build pending (waiting for nix develop to complete)

---

**Migration Complete:** shell.nix β†’ flake.nix βœ