lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README

apps.nix (3122B)


      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   architecture = mkRepoApp {
     58     name = "architecture";
     59     description = "Run crates-release architecture and freshness checks";
     60     runtimeInputs = common.runtimeInputs.stable;
     61     command = common.architectureCommand;
     62   };
     63 
     64   check = mkRepoApp {
     65     name = "check";
     66     description = "Run cargo check across the radroots workspace";
     67     runtimeInputs = common.runtimeInputs.stable;
     68     command = common.checkCommand;
     69   };
     70 
     71   contract = mkRepoApp {
     72     name = "contract";
     73     description = "Run the core-library contract lane";
     74     runtimeInputs = common.runtimeInputs.stable;
     75     command = common.contractCommand;
     76   };
     77 
     78   coverage-report = mkRepoApp {
     79     name = "coverage-report";
     80     description = "Generate coverage reports and blocking gate artifacts";
     81     runtimeInputs = common.runtimeInputs.coverage;
     82     command = common.coverageReportCommand;
     83     env = common.exportCoverageEnv;
     84     pathPrefix = coveragePath;
     85   };
     86 
     87   guards = mkRepoApp {
     88     name = "guards";
     89     description = "Run repository hygiene guards";
     90     runtimeInputs = common.runtimeInputs.stable;
     91     command = ''
     92       cargo run -q -p xtask -- hygiene forbidden-identifiers
     93       cargo run -q -p xtask -- hygiene prototype-contracts
     94     '';
     95   };
     96 
     97   fmt = mkRepoApp {
     98     name = "fmt";
     99     description = "Format rust, nix, shell, and toml files";
    100     runtimeInputs = common.runtimeInputs.stable ++ [
    101       config.treefmt.build.wrapper
    102     ];
    103     command = ''
    104       cargo fmt --all
    105       ${config.treefmt.build.wrapper}/bin/treefmt
    106     '';
    107   };
    108 
    109   release-preflight = mkRepoApp {
    110     name = "release-preflight";
    111     description = "Run release coverage refresh and preflight validation";
    112     runtimeInputs = [
    113       pkgs.nix
    114     ];
    115     command = coverageShellExec "release-preflight" common.releasePreflightCommand;
    116     env = common.exportCoverageEnv;
    117     pathPrefix = coveragePath;
    118   };
    119 
    120 }