|
| 1 | +{ |
| 2 | + inputs = { |
| 3 | + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; |
| 4 | + |
| 5 | + rust-overlay = { |
| 6 | + url = "github:oxalica/rust-overlay"; |
| 7 | + inputs.nixpkgs.follows = "nixpkgs"; |
| 8 | + }; |
| 9 | + crane = { |
| 10 | + url = "github:ipetkov/crane"; |
| 11 | + }; |
| 12 | + flake-utils = { |
| 13 | + url = "github:numtide/flake-utils"; |
| 14 | + }; |
| 15 | + }; |
| 16 | + |
| 17 | + outputs = |
| 18 | + { |
| 19 | + self, |
| 20 | + flake-utils, |
| 21 | + nixpkgs, |
| 22 | + rust-overlay, |
| 23 | + crane, |
| 24 | + ... |
| 25 | + }: |
| 26 | + flake-utils.lib.eachDefaultSystem ( |
| 27 | + system: |
| 28 | + let |
| 29 | + overlays = [ (import rust-overlay) ]; |
| 30 | + pkgs = import nixpkgs { |
| 31 | + inherit system overlays; |
| 32 | + }; |
| 33 | + filteredSource = |
| 34 | + let |
| 35 | + pathsToIgnore = [ |
| 36 | + ".envrc" |
| 37 | + ".ignore" |
| 38 | + ".github" |
| 39 | + ".gitignore" |
| 40 | + "rust-toolchain.toml" |
| 41 | + "README.MD" |
| 42 | + "flake.nix" |
| 43 | + "flake.lock" |
| 44 | + "target" |
| 45 | + "LICENCE" |
| 46 | + ".direnv" |
| 47 | + ]; |
| 48 | + ignorePaths = |
| 49 | + path: type: |
| 50 | + let |
| 51 | + inherit (nixpkgs) lib; |
| 52 | + # split the nix store path into its components |
| 53 | + components = lib.splitString "/" path; |
| 54 | + # drop off the `/nix/hash-source` section from the path |
| 55 | + relPathComponents = lib.drop 4 components; |
| 56 | + # reassemble the path components |
| 57 | + relPath = lib.concatStringsSep "/" relPathComponents; |
| 58 | + in |
| 59 | + lib.all (p: !(lib.hasPrefix p relPath)) pathsToIgnore; |
| 60 | + in |
| 61 | + builtins.path { |
| 62 | + name = "mania-source"; |
| 63 | + path = toString ./.; |
| 64 | + # filter out unnecessary paths |
| 65 | + filter = ignorePaths; |
| 66 | + }; |
| 67 | + stdenv = if pkgs.stdenv.isLinux then pkgs.stdenv else pkgs.clangStdenv; |
| 68 | + rustToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; |
| 69 | + craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain; |
| 70 | + commonArgs = { |
| 71 | + inherit stdenv; |
| 72 | + inherit |
| 73 | + (craneLib.crateNameFromCargoToml { |
| 74 | + cargoToml = ./mania/Cargo.toml; |
| 75 | + }) |
| 76 | + pname |
| 77 | + ; |
| 78 | + inherit |
| 79 | + (craneLib.crateNameFromCargoToml { |
| 80 | + cargoToml = ./Cargo.toml; |
| 81 | + }) |
| 82 | + version |
| 83 | + ; |
| 84 | + src = filteredSource; |
| 85 | + strictDeps = true; |
| 86 | + nativeBuildInputs = [ |
| 87 | + pkgs.protobuf |
| 88 | + ]; |
| 89 | + doCheck = false; |
| 90 | + meta = { |
| 91 | + mainProgram = "mania"; |
| 92 | + homepage = "https://github.com/LagrangeDev/mania"; |
| 93 | + license = pkgs.lib.licenses.gpl3Only; |
| 94 | + }; |
| 95 | + }; |
| 96 | + cargoArtifacts = craneLib.buildDepsOnly commonArgs; |
| 97 | + in |
| 98 | + { |
| 99 | + packages = { |
| 100 | + mania = craneLib.buildPackage ( |
| 101 | + commonArgs |
| 102 | + // { |
| 103 | + inherit cargoArtifacts; |
| 104 | + cargoExtraArgs = '' |
| 105 | + --example multi-login |
| 106 | + ''; |
| 107 | + postInstall = '' |
| 108 | + mkdir -p $out/bin |
| 109 | +
|
| 110 | + cp ./target/release/examples/multi-login $out/bin/mania |
| 111 | + ''; |
| 112 | + } |
| 113 | + ); |
| 114 | + default = self.packages."${system}".mania; |
| 115 | + }; |
| 116 | + checks = { |
| 117 | + inherit (self.packages."${system}") mania; |
| 118 | + clippy = craneLib.cargoClippy ( |
| 119 | + commonArgs |
| 120 | + // { |
| 121 | + inherit cargoArtifacts; |
| 122 | + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; |
| 123 | + } |
| 124 | + ); |
| 125 | + fmt = craneLib.cargoFmt commonArgs; |
| 126 | + doc = craneLib.cargoDoc ( |
| 127 | + commonArgs |
| 128 | + // { |
| 129 | + inherit cargoArtifacts; |
| 130 | + } |
| 131 | + ); |
| 132 | + test = craneLib.cargoTest ( |
| 133 | + commonArgs |
| 134 | + // { |
| 135 | + inherit cargoArtifacts; |
| 136 | + } |
| 137 | + ); |
| 138 | + }; |
| 139 | + devShells.default = pkgs.mkShell { |
| 140 | + packages = with pkgs; [ |
| 141 | + (rust-bin.fromRustupToolchainFile ./rust-toolchain.toml) |
| 142 | + rust-analyzer |
| 143 | + ]; |
| 144 | + nativeBuildInputs = with pkgs; [ protobuf ]; |
| 145 | + }; |
| 146 | + } |
| 147 | + ) |
| 148 | + // { |
| 149 | + overlays.default = final: prev: { |
| 150 | + inherit (self.packages."${final.system}") mania; |
| 151 | + }; |
| 152 | + }; |
| 153 | + |
| 154 | +} |
0 commit comments