flake.nix (6409B)
1 { 2 description = "RHI evidence reconciliation and attestation service"; 3 4 inputs = { 5 # Crane 0.23+ currently asks nixpkgs' Cargo vendor helper to fetch 6 # semver-build-metadata crate versions through the crates.io API. That 7 # endpoint rejects the literal `+`; the immutable v0.22.0 input avoids 8 # that upstream fetch defect while preserving the same locked sources. 9 crane.url = "github:ipetkov/crane/01bc1d404a51a0a07e9d8759cd50a7903e218c82"; 10 lib = { 11 url = "github:radrootslabs/lib/e55c1749902811732167a2ce5c099e22e964624f"; 12 inputs.crane.follows = "crane"; 13 }; 14 nixpkgs.follows = "lib/nixpkgs"; 15 rust-overlay.follows = "lib/rust-overlay"; 16 }; 17 18 outputs = 19 { 20 self, 21 crane, 22 lib, 23 nixpkgs, 24 rust-overlay, 25 ... 26 }: 27 let 28 systems = lib.lib.supportedSystems; 29 forAllSystems = function: 30 builtins.listToAttrs ( 31 map (system: { 32 name = system; 33 value = function system; 34 }) systems 35 ); 36 serviceOutputs = 37 system: 38 let 39 pkgs = import nixpkgs { 40 inherit system; 41 overlays = [ rust-overlay.overlays.default ]; 42 }; 43 helpers = lib.lib.mkServiceHelpers system; 44 toolchain = helpers.mkToolchain { 45 rustToolchainFile = ./rust-toolchain.toml; 46 }; 47 nativeInputs = helpers.mkNativeInputs { }; 48 craneLib = (crane.mkLib pkgs).overrideToolchain toolchain; 49 source = pkgs.lib.cleanSourceWith { 50 src = ./.; 51 # Standalone tests also consume identity, policy and packaging assets. 52 filter = pkgs.lib.cleanSourceFilter; 53 name = "rhi-source"; 54 }; 55 commonArgs = { 56 src = source; 57 cargoLock = ./Cargo.lock; 58 strictDeps = true; 59 nativeBuildInputs = nativeInputs.nativeBuildInputs; 60 buildInputs = nativeInputs.buildInputs; 61 env = nativeInputs.environment; 62 doCheck = false; 63 }; 64 cargoArtifacts = craneLib.buildDepsOnly commonArgs; 65 package = craneLib.buildPackage ( 66 commonArgs 67 // { 68 inherit cargoArtifacts; 69 pname = "rhi"; 70 version = "0.1.0"; 71 CARGO_PROFILE = "release"; 72 cargoExtraArgs = "--locked --package rhi --bin rhi"; 73 postInstall = '' 74 install -Dm444 ${lib.outPath}/crates/domain/NOTICE "$out/share/doc/rhi/NOTICE" 75 ''; 76 } 77 ); 78 mkCargoCheck = 79 name: command: extraArgs: 80 craneLib.mkCargoDerivation ( 81 commonArgs 82 // extraArgs 83 // { 84 inherit cargoArtifacts; 85 pname = "rhi-${name}"; 86 version = "1"; 87 buildPhaseCargoCommand = command; 88 installPhaseCommand = "mkdir -p $out"; 89 } 90 ); 91 checks = { 92 fmt = craneLib.cargoFmt ( 93 commonArgs 94 // { 95 pname = "rhi-fmt"; 96 version = "1"; 97 } 98 ); 99 check = mkCargoCheck "check" "cargo check --workspace --all-targets --locked" { }; 100 test = mkCargoCheck "test" "cargo test --workspace --all-targets --locked" { 101 nativeBuildInputs = nativeInputs.nativeBuildInputs ++ [ pkgs.coreutils ]; 102 }; 103 clippy = mkCargoCheck "clippy" "cargo clippy --workspace --all-targets --locked -- -D warnings" { }; 104 docs = mkCargoCheck "docs" "cargo doc --workspace --no-deps --locked" { 105 RUSTDOCFLAGS = "-D warnings"; 106 }; 107 config = package; 108 integration = package; 109 package = package; 110 source-lock = package; 111 sqlx = package; 112 }; 113 apps = helpers.mkServiceApps { 114 serviceName = "rhi"; 115 binaryName = "rhi"; 116 inherit nativeInputs package toolchain; 117 releaseAcceptanceCommand = '' 118 ${package}/bin/rhi \ 119 --profile repo-local \ 120 --instance nix-release-acceptance \ 121 --repo-local-root "$PWD" \ 122 config schema >/dev/null 123 ''; 124 }; 125 devShells.default = helpers.mkServiceDevShell { 126 serviceName = "rhi"; 127 inherit nativeInputs toolchain; 128 }; 129 oci = helpers.mkServiceOciImage { 130 serviceName = "rhi"; 131 binaryName = "rhi"; 132 inherit package; 133 buildInfo = { 134 serviceVersion = "0.1.0"; 135 serviceCommit = self.rev or "0000000000000000000000000000000000000000"; 136 libRevision = "e55c1749902811732167a2ce5c099e22e964624f"; 137 rustVersion = "1.99.0"; 138 target = "x86_64-unknown-linux-gnu"; 139 featureProfile = "service-host"; 140 contractVersions = { 141 config = 1; 142 state = 11; 143 admin = 1; 144 status = 1; 145 provider = 1; 146 }; 147 }; 148 }; 149 in 150 helpers.mkServiceOutputs { 151 serviceName = "rhi"; 152 inherit 153 apps 154 checks 155 devShells 156 nativeInputs 157 package 158 ; 159 extraPackages = if system == "x86_64-linux" then { inherit oci; } else { }; 160 }; 161 in 162 { 163 packages = forAllSystems (system: (serviceOutputs system).packages); 164 apps = forAllSystems (system: (serviceOutputs system).apps); 165 checks = forAllSystems (system: (serviceOutputs system).checks); 166 devShells = forAllSystems (system: (serviceOutputs system).devShells); 167 168 nixosModules.default = 169 let 170 helpers = lib.lib.mkServiceHelpers "x86_64-linux"; 171 in 172 helpers.mkServiceNixosModule { 173 serviceName = "rhi"; 174 binaryName = "rhi"; 175 packageFor = _pkgs: self.packages.x86_64-linux.default; 176 commandForInstance = instance: [ 177 "--profile" 178 "service-host" 179 "--instance" 180 instance 181 "--config" 182 "/etc/radroots/services/rhi/${instance}/config.toml" 183 "run" 184 ]; 185 }; 186 }; 187 }