1
0

flake.nix 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. {
  2. description = "The EZA flake for developing and releasing (soon)";
  3. inputs = {
  4. flake-utils.url = "github:numtide/flake-utils";
  5. naersk.url = "github:nix-community/naersk";
  6. nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
  7. treefmt-nix.url = "github:numtide/treefmt-nix";
  8. rust-overlay.url = "github:oxalica/rust-overlay";
  9. };
  10. outputs = {
  11. self,
  12. flake-utils,
  13. naersk,
  14. nixpkgs,
  15. treefmt-nix,
  16. rust-overlay,
  17. }:
  18. flake-utils.lib.eachDefaultSystem (
  19. system: let
  20. overlays = [(import rust-overlay)];
  21. pkgs = (import nixpkgs) {
  22. inherit system overlays;
  23. };
  24. toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
  25. naersk' = pkgs.callPackage naersk {
  26. cargo = toolchain;
  27. rustc = toolchain;
  28. clippy = toolchain;
  29. };
  30. treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
  31. buildInputs = with pkgs; lib.optionals stdenv.isDarwin [libiconv darwin.apple_sdk.frameworks.Security];
  32. in rec {
  33. # For `nix fmt`
  34. formatter = treefmtEval.config.build.wrapper;
  35. packages = {
  36. # For `nix build` & `nix run`:
  37. default = naersk'.buildPackage {
  38. src = ./.;
  39. doCheck = true; # run `cargo test` on build
  40. inherit buildInputs;
  41. };
  42. # Run `nix build .#check` to check code
  43. check = naersk'.buildPackage {
  44. src = ./.;
  45. mode = "check";
  46. inherit buildInputs;
  47. };
  48. # Run `nix build .#test` to run tests
  49. test = naersk'.buildPackage {
  50. src = ./.;
  51. mode = "test";
  52. inherit buildInputs;
  53. };
  54. # Run `nix build .#clippy` to lint code
  55. clippy = naersk'.buildPackage {
  56. src = ./.;
  57. mode = "clippy";
  58. inherit buildInputs;
  59. };
  60. };
  61. # For `nix develop`:
  62. devShells.default = pkgs.mkShell {
  63. nativeBuildInputs = with pkgs; [toolchain just pandoc];
  64. };
  65. # for `nix flake check`
  66. checks = {
  67. formatting = treefmtEval.config.build.check self;
  68. build = packages.check;
  69. test = packages.test;
  70. lint = packages.clippy;
  71. };
  72. }
  73. );
  74. }