diff options
Diffstat (limited to '')
| -rw-r--r-- | flake.nix | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..10dd5d7 --- /dev/null +++ b/flake.nix @@ -0,0 +1,115 @@ +{ + description = "name of your package"; + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + crane.url = "github:ipetkov/crane"; + treefmt-nix = { + url = "github:numtide/treefmt-nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + fenix = { + url = "github:nix-community/fenix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + outputs = + { + self, + nixpkgs, + flake-utils, + crane, + fenix, + treefmt-nix, + ... + }: + flake-utils.lib.eachDefaultSystem ( + system: + let + pkg_name = "name"; + pkgs = nixpkgs.legacyPackages.${system}; + lib = pkgs.lib; + + rustToolchain = fenix.packages.${system}.fromToolchainFile { + file = ./rust-toolchain.toml; + sha256 = "sha256-LAQdG4kB6olIXlVFbq610fgUl9hCTtgnYgX7kZQfE+Q="; + }; + + craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain; + src = (craneLib.cleanCargoSource ./.); + + commonArgs = { + inherit src; + strictDeps = true; + cargoToml = ./Cargo.toml; + + nativeBuildInputs = [ + pkgs.pkg-config + ]; + }; + + cargoArtifacts = craneLib.buildDepsOnly commonArgs; + + _package = craneLib.buildPackage ( + commonArgs + // { + inherit cargoArtifacts; + } + ); + + tree-fmt-eval = treefmt-nix.lib.evalModule pkgs ( + { ... }: + { + # Used to find the project root + projectRootFile = "flake.nix"; + programs.nixfmt.enable = true; + programs.deadnix.enable = true; + programs.rustfmt = { + enable = true; + package = rustToolchain; + }; + } + ); + + in + { + checks = { + inherit _package; # Compile to test + str-clippy = craneLib.cargoClippy ( + commonArgs + // { + inherit cargoArtifacts; + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; + } + ); + formatting = tree-fmt-eval.config.build.check self; + }; + + formatter = tree-fmt-eval.config.build.wrapper; + + apps.default = flake-utils.lib.mkApp { + drv = _package; + }; + packages.${pkg_name} = _package; + packages.default = _package; + + devShells.default = craneLib.devShell { + checks = self.checks.${system}; + + packages = with pkgs; [ + # Put your packages for dev here + ]; + + env = { + "LD_LIBRARY_PATH" = lib.makeLibraryPath ( + with pkgs; + [ + stdenv.cc.cc.lib + ] + ); + }; + }; + } + ); +} |
