this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

build(nix): rewrite flake to use crane

+209 -257
+2 -1
.github/workflows/nix.yml
··· 19 19 uses: DeterminateSystems/magic-nix-cache-action@main 20 20 21 21 - name: Check 22 - run: nix flake check 22 + # Run 1 at a time and print all the log files 23 + run: nix flake check --max-jobs 1 -L 23 24 24 25 - name: Build 25 26 run: nix build
+90 -185
flake.lock
··· 1 1 { 2 2 "nodes": { 3 - "crane": { 3 + "advisory-db": { 4 4 "flake": false, 5 5 "locked": { 6 - "lastModified": 1681175776, 7 - "narHash": "sha256-7SsUy9114fryHAZ8p1L6G6YSu7jjz55FddEwa2U8XZc=", 8 - "owner": "ipetkov", 9 - "repo": "crane", 10 - "rev": "445a3d222947632b5593112bb817850e8a9cf737", 6 + "lastModified": 1690651200, 7 + "narHash": "sha256-0aDZUueboXYxKy/ckHQYA6zkvLOVsb2wyzJjSuEdJzE=", 8 + "owner": "rustsec", 9 + "repo": "advisory-db", 10 + "rev": "98e8483ac17d42eeeeee51d4d02ad8a690bd12c7", 11 11 "type": "github" 12 12 }, 13 13 "original": { 14 - "owner": "ipetkov", 15 - "ref": "v0.12.1", 16 - "repo": "crane", 14 + "owner": "rustsec", 15 + "repo": "advisory-db", 17 16 "type": "github" 18 17 } 19 18 }, 20 - "dream2nix": { 19 + "crane": { 21 20 "inputs": { 22 - "all-cabal-json": [ 23 - "nci" 24 - ], 25 - "crane": "crane", 26 - "devshell": [ 27 - "nci" 28 - ], 29 - "drv-parts": "drv-parts", 30 21 "flake-compat": "flake-compat", 31 - "flake-parts": [ 32 - "nci", 33 - "parts" 34 - ], 35 - "flake-utils-pre-commit": [ 36 - "nci" 37 - ], 38 - "ghc-utils": [ 39 - "nci" 40 - ], 41 - "gomod2nix": [ 42 - "nci" 43 - ], 44 - "mach-nix": [ 45 - "nci" 46 - ], 47 - "nix-pypi-fetcher": [ 48 - "nci" 49 - ], 22 + "flake-utils": "flake-utils", 50 23 "nixpkgs": [ 51 - "nci", 52 24 "nixpkgs" 53 25 ], 54 - "nixpkgsV1": "nixpkgsV1", 55 - "poetry2nix": [ 56 - "nci" 57 - ], 58 - "pre-commit-hooks": [ 59 - "nci" 60 - ], 61 - "pruned-racket-catalog": [ 62 - "nci" 63 - ] 26 + "rust-overlay": [] 64 27 }, 65 28 "locked": { 66 - "lastModified": 1688815683, 67 - "narHash": "sha256-mGeQgTcAltpQlr3KUBA1WoGBQadq6OAhuF864ci4+vI=", 68 - "owner": "nix-community", 69 - "repo": "dream2nix", 70 - "rev": "99373e29568de05287d391a745947154ddbf4e3e", 29 + "lastModified": 1688772518, 30 + "narHash": "sha256-ol7gZxwvgLnxNSZwFTDJJ49xVY5teaSvF7lzlo3YQfM=", 31 + "owner": "ipetkov", 32 + "repo": "crane", 33 + "rev": "8b08e96c9af8c6e3a2b69af5a7fa168750fcf88e", 71 34 "type": "github" 72 35 }, 73 36 "original": { 74 - "owner": "nix-community", 75 - "ref": "legacy", 76 - "repo": "dream2nix", 37 + "owner": "ipetkov", 38 + "repo": "crane", 77 39 "type": "github" 78 40 } 79 41 }, 80 - "drv-parts": { 42 + "fenix": { 81 43 "inputs": { 82 - "flake-compat": [ 83 - "nci", 84 - "dream2nix", 85 - "flake-compat" 86 - ], 87 - "flake-parts": [ 88 - "nci", 89 - "dream2nix", 90 - "flake-parts" 91 - ], 92 44 "nixpkgs": [ 93 - "nci", 94 - "dream2nix", 95 45 "nixpkgs" 96 - ] 46 + ], 47 + "rust-analyzer-src": [] 97 48 }, 98 49 "locked": { 99 - "lastModified": 1680698112, 100 - "narHash": "sha256-FgnobN/DvCjEsc0UAZEAdPLkL4IZi2ZMnu2K2bUaElc=", 101 - "owner": "davhau", 102 - "repo": "drv-parts", 103 - "rev": "e8c2ec1157dc1edb002989669a0dbd935f430201", 50 + "lastModified": 1690611557, 51 + "narHash": "sha256-VP59ksXc+4DUWTHl7Ly7TquDXZB/tW8MWLLcBKk82ic=", 52 + "owner": "nix-community", 53 + "repo": "fenix", 54 + "rev": "4253a8cb191d91dcf88d15966c3574f2460bad85", 104 55 "type": "github" 105 56 }, 106 57 "original": { 107 - "owner": "davhau", 108 - "repo": "drv-parts", 58 + "owner": "nix-community", 59 + "repo": "fenix", 109 60 "type": "github" 110 61 } 111 62 }, ··· 146 97 "systems": "systems" 147 98 }, 148 99 "locked": { 149 - "lastModified": 1689068808, 150 - "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=", 100 + "lastModified": 1687709756, 101 + "narHash": "sha256-Y5wKlQSkgEK2weWdOu4J3riRd+kV/VCgHsqLNTTWQ/0=", 151 102 "owner": "numtide", 152 103 "repo": "flake-utils", 153 - "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4", 104 + "rev": "dbabf0ca0c0c4bce6ea5eaf65af5cb694d2082c7", 154 105 "type": "github" 155 106 }, 156 107 "original": { ··· 159 110 "type": "github" 160 111 } 161 112 }, 162 - "gitignore": { 113 + "flake-utils_2": { 163 114 "inputs": { 164 - "nixpkgs": [ 165 - "pre-commit-hooks", 166 - "nixpkgs" 167 - ] 115 + "systems": "systems_2" 168 116 }, 169 117 "locked": { 170 - "lastModified": 1660459072, 171 - "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", 172 - "owner": "hercules-ci", 173 - "repo": "gitignore.nix", 174 - "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", 118 + "lastModified": 1689068808, 119 + "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=", 120 + "owner": "numtide", 121 + "repo": "flake-utils", 122 + "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4", 175 123 "type": "github" 176 124 }, 177 125 "original": { 178 - "owner": "hercules-ci", 179 - "repo": "gitignore.nix", 126 + "owner": "numtide", 127 + "repo": "flake-utils", 180 128 "type": "github" 181 129 } 182 130 }, 183 - "mk-naked-shell": { 184 - "flake": false, 131 + "flake-utils_3": { 132 + "inputs": { 133 + "systems": "systems_3" 134 + }, 185 135 "locked": { 186 - "lastModified": 1681286841, 187 - "narHash": "sha256-3XlJrwlR0nBiREnuogoa5i1b4+w/XPe0z8bbrJASw0g=", 188 - "owner": "yusdacra", 189 - "repo": "mk-naked-shell", 190 - "rev": "7612f828dd6f22b7fb332cc69440e839d7ffe6bd", 136 + "lastModified": 1685518550, 137 + "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", 138 + "owner": "numtide", 139 + "repo": "flake-utils", 140 + "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", 191 141 "type": "github" 192 142 }, 193 143 "original": { 194 - "owner": "yusdacra", 195 - "repo": "mk-naked-shell", 144 + "owner": "numtide", 145 + "repo": "flake-utils", 196 146 "type": "github" 197 147 } 198 148 }, 199 - "nci": { 149 + "gitignore": { 200 150 "inputs": { 201 - "dream2nix": "dream2nix", 202 - "mk-naked-shell": "mk-naked-shell", 203 151 "nixpkgs": [ 152 + "pre-commit-hooks", 204 153 "nixpkgs" 205 - ], 206 - "parts": [ 207 - "parts" 208 - ], 209 - "rust-overlay": "rust-overlay" 154 + ] 210 155 }, 211 156 "locked": { 212 - "lastModified": 1690265492, 213 - "narHash": "sha256-Of8stm/ij0LKCQzJw2JcSGJuHJH/kzavTudoEomvOEg=", 214 - "owner": "yusdacra", 215 - "repo": "nix-cargo-integration", 216 - "rev": "d486db902946bcbada2853b7ef0c29bd46579411", 157 + "lastModified": 1660459072, 158 + "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", 159 + "owner": "hercules-ci", 160 + "repo": "gitignore.nix", 161 + "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", 217 162 "type": "github" 218 163 }, 219 164 "original": { 220 - "owner": "yusdacra", 221 - "repo": "nix-cargo-integration", 165 + "owner": "hercules-ci", 166 + "repo": "gitignore.nix", 222 167 "type": "github" 223 168 } 224 169 }, 225 170 "nixpkgs": { 226 171 "locked": { 227 - "lastModified": 1686960236, 228 - "narHash": "sha256-AYCC9rXNLpUWzD9hm+askOfpliLEC9kwAo7ITJc4HIw=", 172 + "lastModified": 1690548937, 173 + "narHash": "sha256-x3ZOPGLvtC0/+iFAg9Kvqm/8hTAIkGjc634SqtgaXTA=", 229 174 "owner": "nixos", 230 175 "repo": "nixpkgs", 231 - "rev": "04af42f3b31dba0ef742d254456dc4c14eedac86", 176 + "rev": "2a9d660ff0f7ffde9d73be328ee6e6f10ef66b28", 232 177 "type": "github" 233 178 }, 234 179 "original": { ··· 238 183 "type": "github" 239 184 } 240 185 }, 241 - "nixpkgsV1": { 242 - "locked": { 243 - "lastModified": 1686501370, 244 - "narHash": "sha256-G0WuM9fqTPRc2URKP9Lgi5nhZMqsfHGrdEbrLvAPJcg=", 245 - "owner": "NixOS", 246 - "repo": "nixpkgs", 247 - "rev": "75a5ebf473cd60148ba9aec0d219f72e5cf52519", 248 - "type": "github" 249 - }, 250 - "original": { 251 - "id": "nixpkgs", 252 - "ref": "nixos-unstable", 253 - "type": "indirect" 254 - } 255 - }, 256 - "parts": { 257 - "inputs": { 258 - "nixpkgs-lib": [ 259 - "nixpkgs" 260 - ] 261 - }, 262 - "locked": { 263 - "lastModified": 1688466019, 264 - "narHash": "sha256-VeM2akYrBYMsb4W/MmBo1zmaMfgbL4cH3Pu8PGyIwJ0=", 265 - "owner": "hercules-ci", 266 - "repo": "flake-parts", 267 - "rev": "8e8d955c22df93dbe24f19ea04f47a74adbdc5ec", 268 - "type": "github" 269 - }, 270 - "original": { 271 - "owner": "hercules-ci", 272 - "repo": "flake-parts", 273 - "type": "github" 274 - } 275 - }, 276 186 "pre-commit-hooks": { 277 187 "inputs": { 278 188 "flake-compat": "flake-compat_2", 279 - "flake-utils": "flake-utils", 189 + "flake-utils": "flake-utils_3", 280 190 "gitignore": "gitignore", 281 191 "nixpkgs": [ 282 192 "nixpkgs" ··· 286 196 ] 287 197 }, 288 198 "locked": { 289 - "lastModified": 1687251716, 290 - "narHash": "sha256-+sFS41thsB5U+lY/dBYPSmU4AJ7nz/VdM1WD35fXVeM=", 199 + "lastModified": 1690628027, 200 + "narHash": "sha256-OTSbA2hM6VmxyZ/4siYPANffMBzIsKu04GLjXcv8ST0=", 291 201 "owner": "cachix", 292 202 "repo": "pre-commit-hooks.nix", 293 - "rev": "7807e1851d95828ed98491930d2d9e7ddbe65da4", 203 + "rev": "1e2443dd3f669eb65433b2fc26a3065e05a7dc9c", 294 204 "type": "github" 295 205 }, 296 206 "original": { ··· 301 211 }, 302 212 "root": { 303 213 "inputs": { 304 - "nci": "nci", 214 + "advisory-db": "advisory-db", 215 + "crane": "crane", 216 + "fenix": "fenix", 217 + "flake-utils": "flake-utils_2", 305 218 "nixpkgs": "nixpkgs", 306 - "parts": "parts", 307 - "pre-commit-hooks": "pre-commit-hooks", 308 - "treefmt": "treefmt" 219 + "pre-commit-hooks": "pre-commit-hooks" 309 220 } 310 221 }, 311 - "rust-overlay": { 312 - "flake": false, 222 + "systems": { 313 223 "locked": { 314 - "lastModified": 1690252178, 315 - "narHash": "sha256-9oEz822bvbHobfCUjJLDor2BqW3I5tycIauzDlzOALY=", 316 - "owner": "oxalica", 317 - "repo": "rust-overlay", 318 - "rev": "8d64353ca827002fb8459e44d49116c78d868eba", 224 + "lastModified": 1681028828, 225 + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", 226 + "owner": "nix-systems", 227 + "repo": "default", 228 + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", 319 229 "type": "github" 320 230 }, 321 231 "original": { 322 - "owner": "oxalica", 323 - "repo": "rust-overlay", 232 + "owner": "nix-systems", 233 + "repo": "default", 324 234 "type": "github" 325 235 } 326 236 }, 327 - "systems": { 237 + "systems_2": { 328 238 "locked": { 329 239 "lastModified": 1681028828, 330 240 "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", ··· 339 249 "type": "github" 340 250 } 341 251 }, 342 - "treefmt": { 343 - "inputs": { 344 - "nixpkgs": [ 345 - "nixpkgs" 346 - ] 347 - }, 252 + "systems_3": { 348 253 "locked": { 349 - "lastModified": 1689620039, 350 - "narHash": "sha256-BtNwghr05z7k5YMdq+6nbue+nEalvDepuA7qdQMAKoQ=", 351 - "owner": "numtide", 352 - "repo": "treefmt-nix", 353 - "rev": "719c2977f958c41fa60a928e2fbc50af14844114", 254 + "lastModified": 1681028828, 255 + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", 256 + "owner": "nix-systems", 257 + "repo": "default", 258 + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", 354 259 "type": "github" 355 260 }, 356 261 "original": { 357 - "owner": "numtide", 358 - "repo": "treefmt-nix", 262 + "owner": "nix-systems", 263 + "repo": "default", 359 264 "type": "github" 360 265 } 361 266 }
+117 -71
flake.nix
··· 10 10 nixpkgs-stable.follows = "nixpkgs"; 11 11 }; 12 12 }; 13 - parts = { 14 - url = "github:hercules-ci/flake-parts"; 15 - inputs.nixpkgs-lib.follows = "nixpkgs"; 13 + 14 + crane = { 15 + url = "github:ipetkov/crane"; 16 + inputs.nixpkgs.follows = "nixpkgs"; 17 + inputs.rust-overlay.follows = ""; # Replaced with fenix 16 18 }; 17 - nci = { 18 - url = "github:yusdacra/nix-cargo-integration"; 19 - inputs = { 20 - nixpkgs.follows = "nixpkgs"; 21 - parts.follows = "parts"; 22 - }; 19 + 20 + flake-utils.url = "github:numtide/flake-utils"; 21 + 22 + fenix = { 23 + # Needed because rust-overlay, normally used by crane, doesn't have llvm-tools for coverage 24 + url = "github:nix-community/fenix"; 25 + inputs.nixpkgs.follows = "nixpkgs"; 26 + inputs.rust-analyzer-src.follows = ""; 23 27 }; 24 - # Universal formatting 25 - treefmt = { 26 - url = "github:numtide/treefmt-nix"; 27 - inputs.nixpkgs.follows = "nixpkgs"; 28 + 29 + advisory-db = { 30 + # Rust dependency security advisories 31 + url = "github:rustsec/advisory-db"; 32 + flake = false; 28 33 }; 29 34 }; 30 35 31 - outputs = inputs: 32 - inputs.parts.lib.mkFlake {inherit inputs;} { 33 - imports = [ 34 - inputs.nci.flakeModule 35 - inputs.pre-commit-hooks.flakeModule 36 - inputs.treefmt.flakeModule 37 - ]; 38 - systems = ["aarch64-darwin" "aarch64-linux" "x86_64-darwin" "x86_64-linux"]; 39 - perSystem = { 40 - config, 41 - pkgs, 42 - lib, 43 - ... 44 - }: { 45 - nci = { 46 - projects.cmprss.relPath = ""; 47 - crates.cmprss = {export = true;}; 48 - }; 49 - packages.default = config.nci.outputs.cmprss.packages.release; 36 + outputs = {self, ...} @ inputs: 37 + inputs.flake-utils.lib.eachDefaultSystem (system: let 38 + pkgs = import inputs.nixpkgs { 39 + inherit system; 40 + }; 50 41 51 - treefmt = { 52 - projectRootFile = ./flake.nix; 53 - programs = { 54 - # Format nix files using alejandra 55 - alejandra.enable = true; 42 + inherit (pkgs) lib; 56 43 57 - # Format Markdown/css/etc 58 - # The settings are contained in .prettierrc.yaml 59 - prettier.enable = true; 44 + # Use the stable rust tools from fenix 45 + fenixStable = inputs.fenix.packages.${system}.stable; 46 + rustSrc = fenixStable.rust-src; 47 + toolChain = fenixStable.completeToolchain; 60 48 61 - # Format rust files using rustfmt 62 - rustfmt.enable = true; 63 - }; 64 - }; 49 + # Use the toolchain with the crane helper functions 50 + craneLib = inputs.crane.lib.${system}.overrideToolchain toolChain; 65 51 66 - pre-commit = { 67 - # Can't run in `nix flake check` due to the sandbox 68 - check.enable = false; 69 - settings = { 70 - settings.treefmt.package = config.treefmt.build.wrapper; 71 - hooks = { 72 - treefmt.enable = true; 52 + # Clean the src to only have the Rust-relevant files 53 + src = craneLib.cleanCargoSource (craneLib.path ./.); 73 54 74 - # Ensure no clippy warnings exist 75 - # FIXME: Re-enable. Fails for unknown reasons 76 - #clippy.enable = true; 55 + # Common arguments for mkCargoDerivation, a helper for the crane functions 56 + # Arguments can be included here even if they aren't used, but we only 57 + # place them here if they would otherwise show up in multiple places 58 + commonArgs = { 59 + inherit src cargoArtifacts; 60 + }; 77 61 78 - # Runs `cargo check` to look for errors 79 - cargo-check.enable = true; 62 + # Build only the cargo dependencies so we can cache them all when running in CI 63 + cargoArtifacts = craneLib.buildDepsOnly commonArgs; 64 + 65 + # Build the actual crate itself, reusing the cargoArtifacts 66 + cmprss = craneLib.buildPackage commonArgs; 67 + in { 68 + checks = 69 + { 70 + # Build the crate as part of `nix flake check` for convenience 71 + inherit cmprss; 72 + 73 + # Run clippy (and deny all warnings) on the crate source 74 + cmprss-clippy = craneLib.cargoClippy (commonArgs 75 + // { 76 + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; 77 + }); 78 + 79 + # Check docs build successfully 80 + cmprss-doc = craneLib.cargoDoc commonArgs; 81 + 82 + # Check formatting 83 + cmprss-fmt = craneLib.cargoFmt commonArgs; 84 + 85 + # Build code coverage helper that uses llvm-cov 86 + cmprss-llvm-cov = craneLib.cargoLlvmCov commonArgs; 87 + 88 + # Run tests with cargo-nextest 89 + # Note: This provides limited value, as tests are already run in the build 90 + cmprss-nextest = craneLib.cargoNextest commonArgs; 91 + 92 + # Audit dependencies 93 + crate-audit = craneLib.cargoAudit (commonArgs 94 + // { 95 + inherit (inputs) advisory-db; 96 + }); 97 + } 98 + // lib.optionalAttrs (system == "x86_64-linux") { 99 + # Check code coverage with tarpaulin runs 100 + cmprss-tarpaulin = craneLib.cargoTarpaulin commonArgs; 101 + } 102 + // { 103 + # Run formatting checks before commit 104 + # Can be run manually with `pre-commit run -a` 105 + pre-commit-check = inputs.pre-commit-hooks.lib.${system}.run { 106 + src = ./.; 107 + tools.rustfmt = toolChain; 108 + hooks = { 109 + alejandra.enable = true; # Nix formatting 110 + prettier.enable = true; # Markdown formatting 111 + rustfmt.enable = true; # Rust formatting 80 112 }; 81 113 }; 82 114 }; 83 115 84 - devShells.default = 85 - config.nci.outputs.cmprss.devShell.overrideAttrs 86 - (old: { 87 - name = "cmprss"; 88 - shellHook = '' 89 - ${config.pre-commit.installationScript} 90 - ''; 91 - nativeBuildInputs = with pkgs; [ 92 - act # For running Github Actions locally 93 - config.treefmt.build.wrapper # `treefmt` to format everything 94 - nodePackages.prettier 95 - rust-analyzer 96 - ]; 97 - }); 116 + packages = { 117 + default = cmprss; 118 + }; 119 + 120 + apps.default = inputs.flake-utils.lib.mkApp { 121 + drv = cmprss; 122 + }; 123 + 124 + devShells.default = pkgs.mkShell { 125 + name = "cmprss"; 126 + inherit (self.checks.${system}.pre-commit-check) shellHook; 127 + 128 + # Include the packages from the defined checks and packages 129 + inputsFrom = 130 + (builtins.attrValues self.checks.${system}) 131 + ++ (builtins.attrValues self.packages.${system}); 132 + 133 + # Extra inputs can be added here 134 + nativeBuildInputs = with pkgs; [ 135 + act # For running Github Actions locally 136 + statix 137 + deadnix 138 + nodePackages.prettier 139 + alejandra 140 + ]; 141 + 142 + # Many tools read this to find the sources for rust stdlib 143 + RUST_SRC_PATH = "${rustSrc}/lib/rustlib/src/rust/library"; 98 144 }; 99 - }; 145 + }); 100 146 }