From e7c7b7a6e1c53dfcb04afdfad15ffa8655b69070 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 19 Aug 2021 21:33:04 +0200 Subject: [PATCH] nix: setup flake w/ pre-commit --- flake.lock | 69 +++++++++++++++++++++++++++++++++++++ flake.nix | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 168 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..44e57dd --- /dev/null +++ b/flake.lock @@ -0,0 +1,69 @@ +{ + "nodes": { + "futils": { + "locked": { + "lastModified": 1629284811, + "narHash": "sha256-JHgasjPR0/J1J3DRm4KxM4zTyAj4IOJY8vIl75v/kPI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c5d161cc0af116a2e17f54316f0bf43f0819785c", + "type": "github" + }, + "original": { + "owner": "numtide", + "ref": "master", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1629292755, + "narHash": "sha256-5xMo32NVLnloY9DveqwJO/Cab1+PbTMPqU4WMmawX5M=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "253aecf69ed7595aaefabde779aa6449195bebb7", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-utils": [ + "futils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1624971177, + "narHash": "sha256-Amf/nBj1E77RmbSSmV+hg6YOpR+rddCbbVgo5C7BS0I=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "397f0713d007250a2c7a745e555fa16c5dc8cadb", + "type": "github" + }, + "original": { + "owner": "cachix", + "ref": "master", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "futils": "futils", + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..f5b2bcf --- /dev/null +++ b/flake.nix @@ -0,0 +1,99 @@ +{ + description = "A simple calculator"; + + inputs = { + futils = { + type = "github"; + owner = "numtide"; + repo = "flake-utils"; + ref = "master"; + }; + + nixpkgs = { + type = "github"; + owner = "NixOS"; + repo = "nixpkgs"; + ref = "nixos-unstable"; + }; + + pre-commit-hooks = { + type = "github"; + owner = "cachix"; + repo = "pre-commit-hooks.nix"; + ref = "master"; + inputs = { + flake-utils.follows = "futils"; + nixpkgs.follows = "nixpkgs"; + }; + }; + }; + + outputs = { self, futils, nixpkgs, pre-commit-hooks }: + futils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; }; + in + { + checks = { + inherit (self.packages.${system}) abacus; + + pre-commit = pre-commit-hooks.lib.${system}.run { + src = self; + + hooks = { + nixpkgs-fmt = { + enable = true; + }; + + clang-format = { + enable = true; + name = "clang-format"; + entry = "${pkgs.clang-tools}/bin/clang-format -style=file -i"; + types = [ "text" "c++" ]; + language = "system"; + }; + }; + }; + }; + + defaultPackage = self.packages.${system}.abacus; + + devShell = pkgs.mkShell { + inherit (self.defaultPackage.${system}) + buildInputs + nativeBuildInputs + ; + + inherit (self.checks.${system}.pre-commit) shellHook; + }; + + packages = futils.lib.flattenTree { + abacus = pkgs.stdenv.mkDerivation { + pname = "abacus"; + version = "0.0.0"; + + src = self; + + nativeBuildInputs = with pkgs; [ + bison + flex + meson + ninja + pkg-config + ]; + + buildInputs = with pkgs; [ + gtest + ]; + + meta = with pkgs.lib; { + description = "A simple calculator using big numbers"; + homepage = "https://gitea.belanyi.fr/ambroisie/abacus"; + license = licenses.mit; + maintainers = [ ambroisie ]; + platforms = platforms.unix; + }; + }; + }; + }); +}