writefreely_client 0.1.0

WriteFreely API client library
Documentation
# SPDX-FileCopyrightText: 2023 Gergely Nagy
# SPDX-FileContributor: Gergely Nagy
#
# SPDX-License-Identifier: EUPL-1.2
{
  description = "Rust API client for WriteFreely";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
    systems.url = "github:nix-systems/default";
    flake-parts.url = "github:hercules-ci/flake-parts";

    pre-commit-hooks = {
      url = "github:cachix/pre-commit-hooks.nix";
      inputs.nixpkgs.follows = "nixpkgs";
      inputs.nixpkgs-stable.follows = "nixpkgs";
    };
    rust-overlay = {
      url = "github:oxalica/rust-overlay";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    naersk = {
      url = "github:nix-community/naersk/master";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    treefmt-nix = {
      url = "github:numtide/treefmt-nix";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = inputs @ {flake-parts, ...}:
    flake-parts.lib.mkFlake {inherit inputs;} {
      systems = import inputs.systems;
      imports = [
        inputs.pre-commit-hooks.flakeModule
        inputs.treefmt-nix.flakeModule
      ];
      perSystem = {
        system,
        config,
        pkgs,
        ...
      }: let
        toolchain = pkgs.rust-bin.stable.latest.default;
        naersk-lib = pkgs.callPackage inputs.naersk {
          cargo = toolchain;
          rustc = toolchain;
        };
      in {
        _module.args.pkgs = import inputs.nixpkgs {
          inherit system;
          overlays = [
            inputs.rust-overlay.overlays.default
          ];
        };
        pre-commit = {
          settings.hooks = {
            treefmt = {
              enable = true;
              always_run = true;
            };
            reuse = {
              enable = true;
              name = "reuse";
              description = "Run REUSE compliance tests";
              entry = "${pkgs.reuse}/bin/reuse lint";
              pass_filenames = false;
              always_run = true;
            };
          };
        };
        treefmt.config = {
          projectRootFile = "Cargo.toml";
          programs = {
            alejandra.enable = true; # nix
            statix.enable = true; # nix static analysis
            deadnix.enable = true; # find dead nix code
            rustfmt.enable = true; # rust
            shellcheck.enable = true; # bash/shell
            taplo.enable = true; # toml
          };
        };
        devShells = {
          default = pkgs.mkShell {
            nativeBuildInputs = with pkgs; [
              cargo-tarpaulin
              reuse
              toolchain
            ];
            inputsFrom = [
              config.pre-commit.devShell
              config.treefmt.build.devShell
            ];

            shellHook = ''
              export CARGO_HOME=$(pwd)/.cargo
            '';
          };
        };
        packages = {
          default = config.packages.writefreely_client;
          writefreely_client = naersk-lib.buildPackage {
            pname = "writefreely_client";
            src = ./.;
            meta.description = "Rust API client for WriteFreely";
          };
          coverage = pkgs.writeShellApplication {
            name = "coverage";
            runtimeInputs = [pkgs.cargo-tarpaulin];
            text = ''
              cargo tarpaulin --features integration-tests --profile=tarpaulin --out Html
            '';
          };
        };
      };
    };
}