this repo has no description
0
fork

Configure Feed

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

build: overhaul of flake to use flake-parts

+162 -222
+11 -8
.github/workflows/nix.yml
··· 18 18 - name: Nix Cache 19 19 uses: DeterminateSystems/magic-nix-cache-action@main 20 20 21 - - name: Check 21 + - name: Build Cmprss 22 + run: nix build 23 + 24 + # Runs all the other checks: formatting, building docs, clippy, etc. 25 + - name: Nix Flake Checks 22 26 # Run 1 at a time and print all the log files 23 27 run: nix flake check --max-jobs 1 -L 24 28 25 - # This should really be a noop since the package is built in the checks 26 - - name: Build 27 - run: nix build 28 - 29 - # This should really be a noop since the package is already built 30 - # This is run to get the coverage file linked in result/lcov.info 29 + # If everything is successful so far, build and run test coverage 31 30 - name: Build Coverage 32 - run: nix build -L .#checks.x86_64-linux.cmprss-tarpaulin 31 + run: nix build -L .#coverage 33 32 34 33 # Upload code coverage 35 34 - name: Upload coverage to Codecov ··· 37 36 with: 38 37 token: ${{ secrets.CODECOV_TOKEN }} 39 38 file: ./result/lcov.info 39 + 40 + # Run the security audit 41 + - name: Security Audit 42 + run: nix build .#audit
+1 -2
Taskfile.yml
··· 41 41 - ./**/*.rs 42 42 - ./**/*.nix 43 43 cmds: 44 - - cargo fmt --all 45 - - alejandra . 44 + - nix fmt 46 45 test: 47 46 desc: Run all tests 48 47 aliases: [t]
+34 -102
flake.lock
··· 18 18 }, 19 19 "crane": { 20 20 "inputs": { 21 - "nixpkgs": ["nixpkgs"] 21 + "nixpkgs": [ 22 + "nixpkgs" 23 + ] 22 24 }, 23 25 "locked": { 24 26 "lastModified": 1708794349, ··· 36 38 }, 37 39 "fenix": { 38 40 "inputs": { 39 - "nixpkgs": ["nixpkgs"], 41 + "nixpkgs": [ 42 + "nixpkgs" 43 + ], 40 44 "rust-analyzer-src": [] 41 45 }, 42 46 "locked": { ··· 53 57 "type": "github" 54 58 } 55 59 }, 56 - "flake-compat": { 57 - "flake": false, 58 - "locked": { 59 - "lastModified": 1696426674, 60 - "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", 61 - "owner": "edolstra", 62 - "repo": "flake-compat", 63 - "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", 64 - "type": "github" 65 - }, 66 - "original": { 67 - "owner": "edolstra", 68 - "repo": "flake-compat", 69 - "type": "github" 70 - } 71 - }, 72 - "flake-utils": { 73 - "inputs": { 74 - "systems": "systems" 75 - }, 76 - "locked": { 77 - "lastModified": 1705309234, 78 - "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", 79 - "owner": "numtide", 80 - "repo": "flake-utils", 81 - "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", 82 - "type": "github" 83 - }, 84 - "original": { 85 - "owner": "numtide", 86 - "repo": "flake-utils", 87 - "type": "github" 88 - } 89 - }, 90 - "flake-utils_2": { 91 - "inputs": { 92 - "systems": "systems_2" 93 - }, 94 - "locked": { 95 - "lastModified": 1701680307, 96 - "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", 97 - "owner": "numtide", 98 - "repo": "flake-utils", 99 - "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", 100 - "type": "github" 101 - }, 102 - "original": { 103 - "owner": "numtide", 104 - "repo": "flake-utils", 105 - "type": "github" 106 - } 107 - }, 108 - "gitignore": { 60 + "flake-parts": { 109 61 "inputs": { 110 - "nixpkgs": ["pre-commit-hooks", "nixpkgs"] 62 + "nixpkgs-lib": "nixpkgs-lib" 111 63 }, 112 64 "locked": { 113 - "lastModified": 1703887061, 114 - "narHash": "sha256-gGPa9qWNc6eCXT/+Z5/zMkyYOuRZqeFZBDbopNZQkuY=", 65 + "lastModified": 1717285511, 66 + "narHash": "sha256-iKzJcpdXih14qYVcZ9QC9XuZYnPc6T8YImb6dX166kw=", 115 67 "owner": "hercules-ci", 116 - "repo": "gitignore.nix", 117 - "rev": "43e1aa1308018f37118e34d3a9cb4f5e75dc11d5", 68 + "repo": "flake-parts", 69 + "rev": "2a55567fcf15b1b1c7ed712a2c6fadaec7412ea8", 118 70 "type": "github" 119 71 }, 120 72 "original": { 121 73 "owner": "hercules-ci", 122 - "repo": "gitignore.nix", 74 + "repo": "flake-parts", 123 75 "type": "github" 124 76 } 125 77 }, ··· 139 91 "type": "github" 140 92 } 141 93 }, 142 - "pre-commit-hooks": { 143 - "inputs": { 144 - "flake-compat": "flake-compat", 145 - "flake-utils": "flake-utils_2", 146 - "gitignore": "gitignore", 147 - "nixpkgs": ["nixpkgs"], 148 - "nixpkgs-stable": ["nixpkgs"] 149 - }, 94 + "nixpkgs-lib": { 150 95 "locked": { 151 - "lastModified": 1708018599, 152 - "narHash": "sha256-M+Ng6+SePmA8g06CmUZWi1AjG2tFBX9WCXElBHEKnyM=", 153 - "owner": "cachix", 154 - "repo": "pre-commit-hooks.nix", 155 - "rev": "5df5a70ad7575f6601d91f0efec95dd9bc619431", 156 - "type": "github" 96 + "lastModified": 1717284937, 97 + "narHash": "sha256-lIbdfCsf8LMFloheeE6N31+BMIeixqyQWbSr2vk79EQ=", 98 + "type": "tarball", 99 + "url": "https://github.com/NixOS/nixpkgs/archive/eb9ceca17df2ea50a250b6b27f7bf6ab0186f198.tar.gz" 157 100 }, 158 101 "original": { 159 - "owner": "cachix", 160 - "repo": "pre-commit-hooks.nix", 161 - "type": "github" 102 + "type": "tarball", 103 + "url": "https://github.com/NixOS/nixpkgs/archive/eb9ceca17df2ea50a250b6b27f7bf6ab0186f198.tar.gz" 162 104 } 163 105 }, 164 106 "root": { ··· 166 108 "advisory-db": "advisory-db", 167 109 "crane": "crane", 168 110 "fenix": "fenix", 169 - "flake-utils": "flake-utils", 111 + "flake-parts": "flake-parts", 170 112 "nixpkgs": "nixpkgs", 171 - "pre-commit-hooks": "pre-commit-hooks" 113 + "treefmt-nix": "treefmt-nix" 172 114 } 173 115 }, 174 - "systems": { 175 - "locked": { 176 - "lastModified": 1681028828, 177 - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", 178 - "owner": "nix-systems", 179 - "repo": "default", 180 - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", 181 - "type": "github" 116 + "treefmt-nix": { 117 + "inputs": { 118 + "nixpkgs": [ 119 + "nixpkgs" 120 + ] 182 121 }, 183 - "original": { 184 - "owner": "nix-systems", 185 - "repo": "default", 186 - "type": "github" 187 - } 188 - }, 189 - "systems_2": { 190 122 "locked": { 191 - "lastModified": 1681028828, 192 - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", 193 - "owner": "nix-systems", 194 - "repo": "default", 195 - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", 123 + "lastModified": 1718271476, 124 + "narHash": "sha256-35hUMmFesmchb+u7heKHLG5B6c8fBOcSYo0jj0CHLes=", 125 + "owner": "numtide", 126 + "repo": "treefmt-nix", 127 + "rev": "e75ba0a6bb562d2ce275db28f6a36a2e4fd81391", 196 128 "type": "github" 197 129 }, 198 130 "original": { 199 - "owner": "nix-systems", 200 - "repo": "default", 131 + "owner": "numtide", 132 + "repo": "treefmt-nix", 201 133 "type": "github" 202 134 } 203 135 }
+116 -110
flake.nix
··· 3 3 4 4 inputs = { 5 5 nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; 6 - pre-commit-hooks = { 7 - url = "github:cachix/pre-commit-hooks.nix"; 8 - inputs = { 9 - nixpkgs.follows = "nixpkgs"; 10 - nixpkgs-stable.follows = "nixpkgs"; 11 - }; 12 - }; 13 6 14 7 crane = { 15 8 url = "github:ipetkov/crane"; 16 9 inputs.nixpkgs.follows = "nixpkgs"; 17 10 }; 18 11 19 - flake-utils.url = "github:numtide/flake-utils"; 20 - 21 12 fenix = { 22 13 # Needed because rust-overlay, normally used by crane, doesn't have llvm-tools for coverage 23 14 url = "github:nix-community/fenix"; ··· 30 21 url = "github:rustsec/advisory-db"; 31 22 flake = false; 32 23 }; 24 + 25 + # Flake helper for better organization with modules. 26 + flake-parts.url = "github:hercules-ci/flake-parts"; 27 + 28 + # For creating a universal `nix fmt` 29 + treefmt-nix = { 30 + url = "github:numtide/treefmt-nix"; 31 + inputs.nixpkgs.follows = "nixpkgs"; 32 + }; 33 33 }; 34 34 35 - outputs = {self, ...} @ inputs: 36 - inputs.flake-utils.lib.eachDefaultSystem (system: let 37 - pkgs = import inputs.nixpkgs { 38 - inherit system; 39 - }; 35 + outputs = inputs @ { 36 + self, 37 + flake-parts, 38 + ... 39 + }: 40 + flake-parts.lib.mkFlake {inherit inputs;} { 41 + systems = ["aarch64-linux" "x86_64-linux" "aarch64-darwin" "x86_64-darwin"]; 40 42 41 - inherit (pkgs) lib; 43 + imports = [ 44 + flake-parts.flakeModules.easyOverlay 45 + inputs.treefmt-nix.flakeModule 46 + ]; 42 47 43 - # Use the stable rust tools from fenix 44 - fenixStable = inputs.fenix.packages.${system}.stable; 45 - rustSrc = fenixStable.rust-src; 46 - toolChain = fenixStable.completeToolchain; 48 + perSystem = { 49 + config, 50 + system, 51 + pkgs, 52 + ... 53 + }: let 54 + # Use the stable rust tools from fenix 55 + fenixStable = inputs.fenix.packages.${system}.stable; 56 + rustSrc = fenixStable.rust-src; 57 + toolChain = fenixStable.completeToolchain; 47 58 48 - # Use the toolchain with the crane helper functions 49 - craneLib = inputs.crane.lib.${system}.overrideToolchain toolChain; 59 + # Use the toolchain with the crane helper functions 60 + craneLib = inputs.crane.lib.${system}.overrideToolchain toolChain; 50 61 51 - # Clean the src to only have the Rust-relevant files 52 - src = craneLib.cleanCargoSource (craneLib.path ./.); 62 + # Clean the src to only have the Rust-relevant files 63 + src = craneLib.cleanCargoSource (craneLib.path ./.); 53 64 54 - # Common arguments for mkCargoDerivation, a helper for the crane functions 55 - # Arguments can be included here even if they aren't used, but we only 56 - # place them here if they would otherwise show up in multiple places 57 - commonArgs = { 58 - inherit src cargoArtifacts; 59 - }; 65 + # Common arguments for mkCargoDerivation, a helper for the crane functions 66 + # Arguments can be included here even if they aren't used, but we only 67 + # place them here if they would otherwise show up in multiple places 68 + commonArgs = { 69 + inherit src cargoArtifacts; 70 + meta.mainProgram = "cmprss"; 71 + }; 60 72 61 - # Build only the cargo dependencies so we can cache them all when running in CI 62 - cargoArtifacts = craneLib.buildDepsOnly commonArgs; 73 + # Build only the cargo dependencies so we can cache them all when running in CI 74 + cargoArtifacts = craneLib.buildDepsOnly commonArgs; 63 75 64 - # Build the actual crate itself, reusing the cargoArtifacts 65 - cmprss = craneLib.buildPackage commonArgs; 66 - in { 67 - checks = 68 - { 76 + # Build the actual crate itself, reusing the cargoArtifacts 77 + cmprss = craneLib.buildPackage commonArgs; 78 + in { 79 + checks = { 69 80 # Build the crate as part of `nix flake check` for convenience 70 81 inherit cmprss; 71 82 72 83 # Run clippy (and deny all warnings) on the crate source 73 - cmprss-clippy = craneLib.cargoClippy (commonArgs 84 + clippy = craneLib.cargoClippy (commonArgs 74 85 // { 75 86 cargoClippyExtraArgs = "--all-targets -- --deny warnings"; 76 87 }); 77 88 78 89 # Check docs build successfully 79 - cmprss-doc = craneLib.cargoDoc commonArgs; 90 + doc = craneLib.cargoDoc commonArgs; 80 91 81 92 # Check formatting 82 - cmprss-fmt = craneLib.cargoFmt commonArgs; 93 + fmt = craneLib.cargoFmt commonArgs; 83 94 84 95 # Run tests with cargo-nextest 85 96 # Note: This provides limited value, as tests are already run in the build 86 - cmprss-nextest = craneLib.cargoNextest commonArgs; 97 + nextest = craneLib.cargoNextest commonArgs; 98 + }; 87 99 88 - # Audit dependencies 89 - crate-audit = craneLib.cargoAudit (commonArgs 90 - // { 91 - inherit (inputs) advisory-db; 92 - }); 93 - } 94 - // lib.optionalAttrs (system == "x86_64-linux") { 95 - # Check code coverage with tarpaulin runs 96 - cmprss-tarpaulin = craneLib.cargoTarpaulin (commonArgs 100 + treefmt = { 101 + projectRootFile = ./flake.nix; 102 + programs = { 103 + alejandra.enable = true; 104 + prettier.enable = true; 105 + rustfmt = { 106 + enable = true; 107 + package = toolChain; 108 + }; 109 + }; 110 + }; 111 + 112 + packages = { 113 + default = cmprss; 114 + cmprss = cmprss; 115 + 116 + # Check code coverage with tarpaulin 117 + coverage = craneLib.cargoTarpaulin (commonArgs 97 118 // { 98 119 # Use lcov output as thats far more widely supported 99 120 cargoTarpaulinExtraArgs = "--skip-clean --include-tests --output-dir $out --out lcov"; 100 121 }); 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 112 - }; 113 - }; 122 + 123 + # Audit dependencies 124 + audit = craneLib.cargoAudit (commonArgs 125 + // { 126 + inherit (inputs) advisory-db; 127 + }); 114 128 }; 115 129 116 - packages = { 117 - default = cmprss; 118 - cmprss = cmprss; 119 - }; 130 + apps = rec { 131 + default = cmprss; 132 + cmprss.program = self.packages.${system}.cmprss; 133 + }; 120 134 121 - apps = rec { 122 - default = cmprss; 123 - cmprss = inputs.flake-utils.lib.mkApp { 124 - drv = self.packages.${system}.cmprss; 135 + overlayAttrs = { 136 + inherit (config.packages) cmprss; 125 137 }; 126 - }; 127 138 128 - devShells.default = pkgs.mkShell { 129 - name = "cmprss"; 130 - shellHook = '' 131 - ${self.checks.${system}.pre-commit-check.shellHook} 132 - echo --------------------- 133 - task --list 134 - echo --------------------- 135 - ''; 139 + devShells.default = pkgs.mkShell { 140 + name = "cmprss"; 141 + shellHook = '' 142 + echo --------------------- 143 + task --list 144 + echo --------------------- 145 + ''; 136 146 137 - # Include the packages from the defined checks and packages 138 - inputsFrom = 139 - (builtins.attrValues self.checks.${system}) 140 - ++ (builtins.attrValues self.packages.${system}); 147 + # Include the packages from the defined checks and packages 148 + inputsFrom = 149 + (builtins.attrValues self.checks.${system}) 150 + ++ (builtins.attrValues self.packages.${system}); 141 151 142 - # Extra inputs can be added here 143 - nativeBuildInputs = with pkgs; [ 144 - act # For running Github Actions locally 145 - alejandra 146 - deadnix 147 - git-cliff 148 - go-task 149 - gum # Pretty printing in scripts 150 - nodePackages.prettier 151 - statix 152 + # Extra inputs can be added here 153 + nativeBuildInputs = with pkgs; [ 154 + act # For running Github Actions locally 155 + alejandra 156 + deadnix 157 + git-cliff 158 + go-task 159 + gum # Pretty printing in scripts 160 + nodePackages.prettier 161 + statix 152 162 153 - # Code coverage 154 - cargo-tarpaulin 163 + # Code coverage 164 + cargo-tarpaulin 155 165 156 - # For running tests 157 - diffutils 158 - # Official tools 159 - bzip2 160 - gnutar 161 - gzip 162 - xz 163 - ]; 166 + # For running tests 167 + diffutils 168 + # Official tools 169 + bzip2 170 + gnutar 171 + gzip 172 + xz 173 + ]; 164 174 165 - # Many tools read this to find the sources for rust stdlib 166 - RUST_SRC_PATH = "${rustSrc}/lib/rustlib/src/rust/library"; 167 - }; 168 - }) 169 - // { 170 - overlays.default = final: prev: { 171 - cmprss = self.packages.${final.system}.cmprss; 175 + # Many tools read this to find the sources for rust stdlib 176 + RUST_SRC_PATH = "${rustSrc}/lib/rustlib/src/rust/library"; 177 + }; 172 178 }; 173 179 }; 174 180 }