From 6e525bd524bcda68da4c9d98901545e9c0fb1ad7 Mon Sep 17 00:00:00 2001 From: Geoff Johnson Date: Sun, 22 Sep 2024 15:12:56 -0700 Subject: [PATCH 1/2] feat: add nix setup --- .envrc | 1 + default.nix | 35 +++++++++++++++++++++++++++++++++++ flake.nix | 28 ++++++++++++++++++++++++++++ shell.nix | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+) create mode 100644 .envrc create mode 100644 default.nix create mode 100644 flake.nix create mode 100644 shell.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..a5dbbcb --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake . diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..c7812a1 --- /dev/null +++ b/default.nix @@ -0,0 +1,35 @@ +{ pkgs ? import { } +, stdenv ? pkgs.stdenv +, lib ? stdenv.lib +# A set providing `buildRustPackage :: attrsets -> derivation` +, rustPlatform ? pkgs.rustPlatform +, fetchFromGitHub ? pkgs.fetchFromGitHub +, gitignoreSrc ? null +}: + +let + gitignoreSource = + if gitignoreSrc != null + then gitignoreSrc.gitignoreSource + else (import (fetchFromGitHub { + owner = "hercules-ci"; + repo = "gitignore"; + rev = "c4662e662462e7bf3c2a968483478a665d00e717"; + sha256 = "0jx2x49p438ap6psy8513mc1nnpinmhm8ps0a4ngfms9jmvwrlbi"; + }) { inherit lib; }).gitignoreSource; +in +rustPlatform.buildRustPackage rec { + pname = "git-utils"; + version = "0.1.0"; + + src = gitignoreSource ./.; + + nativeBuildInputs = [ pkgconfig ]; + cargoSha256 = "sha256-0hfmV4mbr3l86m0X7EMYTOu/b+BjueVEbbyQz0KgOFY="; + + meta = with stdenv.lib; { + homepage = ""; + description = "Personal git utilities"; + license = licenses.mit; + }; +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..9cc34ac --- /dev/null +++ b/flake.nix @@ -0,0 +1,28 @@ +{ + description = "git-utils flake"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; # We want to use packages from the binary cache + flake-utils.url = "github:numtide/flake-utils"; + gitignore = { url = "github:hercules-ci/gitignore.nix"; flake = false; }; + pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix"; + }; + + outputs = inputs@{ self, nixpkgs, flake-utils, pre-commit-hooks, ... }: + (flake-utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + gitignoreSrc = pkgs.callPackage inputs.gitignore { }; + in rec { + packages.app = pkgs.callPackage ./default.nix { inherit gitignoreSrc; }; + + legacyPackages = packages; + + defaultPackage = packages.app; + + devShells.default = pkgs.callPackage ./shell.nix { + inherit pre-commit-hooks; + }; + }) + ); +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..038fadc --- /dev/null +++ b/shell.nix @@ -0,0 +1,34 @@ +{ pkgs, pre-commit-hooks }: + let + pre-commit-check = pre-commit-hooks.lib.${pkgs.system}.run { + src = ./.; + hooks = { + # cargo-check = { + # enable = true; + # name = "cargo-check"; + # description = "Check project"; + # files = "\.rs$"; + # entry = "${pkgs.cargo}/bin/cargo check --all"; + # require_serial = true; + # pass_filenames = false; + # }; + rustfmt.enable = true; + # clippy.enable = true; + }; + }; + in + pkgs.mkShell { + inherit (pre-commit-check) shellHook; + + CARGO_INSTALL_ROOT = "${toString ./.}/.cargo"; + + packages = [ + pkgs.cargo + pkgs.clippy + pkgs.deno + pkgs.ollama + pkgs.overmind + pkgs.rustc + pkgs.rustfmt + ]; + } From d020838d300ce547254d471dd2bafac5d3cf4c41 Mon Sep 17 00:00:00 2001 From: Geoff Johnson Date: Sun, 22 Sep 2024 15:16:12 -0700 Subject: [PATCH 2/2] feat: add flake lock --- .gitignore | 3 +- .pre-commit-config.yaml | 1 + flake.lock | 169 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 172 insertions(+), 1 deletion(-) create mode 120000 .pre-commit-config.yaml create mode 100644 flake.lock diff --git a/.gitignore b/.gitignore index ea8c4bf..420bbe1 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -/target +.direnv/ +target/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 120000 index 0000000..338cee5 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1 @@ +/nix/store/vn4f8qah8fvdmyfs54v6qycg5fbb71mz-pre-commit-config.json \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..3e114ae --- /dev/null +++ b/flake.lock @@ -0,0 +1,169 @@ +{ + "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1726560853, + "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gitignore": { + "flake": false, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "gitignore_2": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1726755586, + "narHash": "sha256-PmUr/2GQGvFTIJ6/Tvsins7Q43KTMvMFhvG6oaYK+Wk=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "c04d5652cfa9742b1d519688f65d1bbccea9eb7e", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1720386169, + "narHash": "sha256-NGKVY4PjzwAa4upkGtAMz1npHGoRzWotlSnVlqI40mo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "194846768975b7ad2c4988bdb82572c00222c0d7", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1719082008, + "narHash": "sha256-jHJSUH619zBQ6WdC21fFAlDxHErKVDJ5fpN0Hgx4sjs=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9693852a2070b398ee123a329e68f0dab5526681", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "gitignore": "gitignore_2", + "nixpkgs": "nixpkgs_2", + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1726745158, + "narHash": "sha256-D5AegvGoEjt4rkKedmxlSEmC+nNLMBPWFxvmYnVLhjk=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "4e743a6920eab45e8ba0fbe49dc459f1423a4b74", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "gitignore": "gitignore", + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +}