apps.nix (2836B)
1 { 2 common, 3 config, 4 lib, 5 pkgs, 6 toolchains, 7 }: 8 let 9 stablePath = "export PATH=${toolchains.stable}/bin:$PATH"; 10 coveragePath = "export PATH=${toolchains.stable}/bin:${toolchains.coverage}/bin:$PATH"; 11 coverageShellExec = 12 name: command: 13 let 14 scriptName = "${name}-coverage-shell"; 15 script = pkgs.writeShellApplication { 16 name = scriptName; 17 runtimeInputs = common.runtimeInputs.coverage; 18 text = command; 19 }; 20 in 21 '' 22 exec nix develop .#coverage --accept-flake-config -c ${script}/bin/${scriptName} "$@" 23 ''; 24 mkRepoApp = 25 { 26 name, 27 description ? "Run ${name} in the radroots workspace", 28 runtimeInputs, 29 command, 30 env ? common.exportSharedEnv, 31 pathPrefix ? stablePath, 32 }: 33 let 34 script = pkgs.writeShellApplication { 35 inherit name runtimeInputs; 36 text = '' 37 set -euo pipefail 38 39 repo_root="$(git rev-parse --show-toplevel 2>/dev/null || pwd)" 40 cd "$repo_root" 41 42 ${common.ensureRepoRoot} 43 ${env} 44 ${pathPrefix} 45 46 ${command} 47 ''; 48 }; 49 in 50 { 51 type = "app"; 52 program = "${script}/bin/${name}"; 53 meta.description = description; 54 }; 55 in 56 { 57 check = mkRepoApp { 58 name = "check"; 59 description = "Run cargo check across the radroots workspace"; 60 runtimeInputs = common.runtimeInputs.stable; 61 command = common.checkCommand; 62 }; 63 64 contract = mkRepoApp { 65 name = "contract"; 66 description = "Run the core-library contract lane"; 67 runtimeInputs = common.runtimeInputs.stable; 68 command = common.contractCommand; 69 }; 70 71 coverage-report = mkRepoApp { 72 name = "coverage-report"; 73 description = "Generate coverage reports and blocking gate artifacts"; 74 runtimeInputs = common.runtimeInputs.coverage; 75 command = common.coverageReportCommand; 76 env = common.exportCoverageEnv; 77 pathPrefix = coveragePath; 78 }; 79 80 guards = mkRepoApp { 81 name = "guards"; 82 description = "Run repository hygiene guards"; 83 runtimeInputs = common.runtimeInputs.stable; 84 command = '' 85 cargo run -q -p xtask -- hygiene forbidden-identifiers 86 ''; 87 }; 88 89 fmt = mkRepoApp { 90 name = "fmt"; 91 description = "Format rust, nix, shell, and toml files"; 92 runtimeInputs = common.runtimeInputs.stable ++ [ 93 config.treefmt.build.wrapper 94 ]; 95 command = '' 96 cargo fmt --all 97 ${config.treefmt.build.wrapper}/bin/treefmt 98 ''; 99 }; 100 101 release-preflight = mkRepoApp { 102 name = "release-preflight"; 103 description = "Run release coverage refresh and preflight validation"; 104 runtimeInputs = [ 105 pkgs.nix 106 ]; 107 command = coverageShellExec "release-preflight" common.releasePreflightCommand; 108 env = common.exportCoverageEnv; 109 pathPrefix = coveragePath; 110 }; 111 112 }