From 9eac46cfeddc65938b3cc946629a9c3d93ac35ee Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Tue, 22 Aug 2023 10:53:12 -0400 Subject: Add a commit-msg hook lint and various other cleanups Turns out that gitlint by default enforces the exact commit-msg format that I like to use. I'm enabling this because even I write poor commit messages sometimes, and looking back on my commits from even a few days ago is sometimes not very helpful. I also made some minor comment and nix changes that I noticed while reviewing my work from the last few days. --- Biz/Bild.nix | 37 +++++++++++++++++-------------------- Biz/Bild/Builder.nix | 24 ++++++++++++++---------- Biz/Bild/Example.py | 2 +- Biz/Ide/hooks/commit-msg | 2 ++ 4 files changed, 34 insertions(+), 31 deletions(-) create mode 100755 Biz/Ide/hooks/commit-msg diff --git a/Biz/Bild.nix b/Biz/Bild.nix index 1955d2c..183e633 100644 --- a/Biz/Bild.nix +++ b/Biz/Bild.nix @@ -53,15 +53,15 @@ in nixpkgs // { bild = rec { bildRuntimeDeps = with nixpkgs; [ pkg-config # this is just to get access to ghc-pkg in bild - (haskell.ghcWith (hpkgs: with hpkgs; [])) + (haskell.ghcWith (_: [])) # lisp deps guile (lisp.sbclWith (p: with p; [asdf alexandria])) # just enough to build Example.lisp ]; - # a standard nix build for `bild` - this should be the only hand-written - # builder we need + # a standard nix build for bild, for bootstrapping. this should be the only + # hand-written builder we need bild = nixpkgs.stdenv.mkDerivation { name = "bild"; src = ../.; @@ -91,7 +91,7 @@ in nixpkgs // { bild = rec { }; # wrapper around bild - runBildAnalyze = main: nixpkgs.stdenv.mkDerivation rec { + runBildAnalyze = target: nixpkgs.stdenv.mkDerivation rec { name = "bild-analysis"; src = ../.; USER = "nixbld"; @@ -100,10 +100,10 @@ in nixpkgs // { bild = rec { BIZ_ROOT = "/build/biz"; # we need to remove the $src root because bild expects paths relative to the # working directory: - MAIN = "." + lib.strings.removePrefix (toString src) (toString main); + TARGET = "." + lib.strings.removePrefix (toString src) (toString target); buildPhase = '' mkdir $out - ${bild}/bin/bild --json "$MAIN" 1> $out/analysis.json \ + ${bild}/bin/bild --json "$TARGET" 1> $out/analysis.json \ 2> >(tee -a $out/stderr >&2) ''; installPhase = "exit 0"; @@ -111,31 +111,28 @@ in nixpkgs // { bild = rec { # gather data needed for compiling by analyzing the main module. returns the # json object of the build - analyze = main: builtins.readFile (runBildAnalyze main + "/analysis.json"); + analyze = target: builtins.readFile (runBildAnalyze target + "/analysis.json"); - # i think this isn't going to work because we have a nix-in-nix problem. - # instead: - # - get the store path some other way. if i can pass that to bild.os, then nix - # should automatically get all the deps required - # - just do runBildAnalyze, pass the args to Bild/Builder.nix, should continue - # no problem - run = main: import ./Bild/Builder.nix { analysisJSON = analyze main; }; + # this does a bild build for the given target, but entirely in nix. its kinda + # like IFD, but not as costly, i think + run = target: import ./Bild/Builder.nix { analysisJSON = analyze target; }; # the main development environment - env = let - linters = with nixpkgs.pkgs; [ ormolu hlint deadnix indent black]; - in nixpkgs.pkgs.mkShell { + env = nixpkgs.pkgs.mkShell { name = "bizdev"; # this should just be dev tools - buildInputs = with nixpkgs.pkgs; linters ++ bildRuntimeDeps ++ [ + buildInputs = with nixpkgs.pkgs; [ bild + black ctags + deadnix figlet git - nixpkgs.haskell.packages.${constants.ghcCompiler}.fast-tags + gitlint hlint + indent lolcat - #nixops # fails to build + nixpkgs.haskell.packages.${constants.ghcCompiler}.fast-tags ormolu shellcheck wemux diff --git a/Biz/Bild/Builder.nix b/Biz/Bild/Builder.nix index a5a31c7..342569b 100644 --- a/Biz/Bild/Builder.nix +++ b/Biz/Bild/Builder.nix @@ -22,9 +22,9 @@ let skip = ["_" ".direnv"]; filter = file: type: if lib.lists.elem (builtins.baseNameOf file) skip then false - # TODO: this means any new directory will cause a rebuild. this bad. i + # TODO: this means any new directory will cause a rebuild. this bad. i # should recurse into the directory and match against the srcs. for now I - # just use postUnpack to delete empty dirs + # just use preBuild to delete empty dirs else if type == "directory" then true else if type == "regular" then lib.trivial.pipe file [ (f: lib.strings.removePrefix "${root}/" f) @@ -32,8 +32,8 @@ let ] else false; - # clean up empty dirs - #postUnpack = "find $src -type d -empty -delete"; + # remove empty directories, leftover from the src filter + preBuild = "find . -type d -empty -delete"; src = lib.sources.cleanSourceWith {inherit filter; src = lib.sources.cleanSource root;}; @@ -41,26 +41,28 @@ let if isEmpty target.langdeps then [] else - lib.attrsets.attrVals + lib.attrsets.attrVals target.langdeps (lib.attrsets.getAttrFromPath (lib.strings.splitString "." target.packageSet) bild); + sysdeps_ = if isEmpty target.sysdeps then [] else lib.attrsets.attrVals target.sysdeps pkgs; + BIZ_ROOT = "."; builders = { base = stdenv.mkDerivation rec { - inherit name src BIZ_ROOT; + inherit name src BIZ_ROOT preBuild; buildInputs = langdeps_ ++ sysdeps_; installPhase = "install -D ${name} $out/bin/${name}"; buildPhase = compileLine; }; haskell = stdenv.mkDerivation rec { - inherit name src BIZ_ROOT; + inherit name src BIZ_ROOT preBuild; buildInputs = sysdeps_ ++ [ (bild.haskell.ghcWith (p: (lib.attrsets.attrVals target.langdeps p) @@ -71,7 +73,7 @@ let }; c = stdenv.mkDerivation rec { - inherit name src BIZ_ROOT; + inherit name src BIZ_ROOT preBuild; buildInputs = langdeps_ ++ sysdeps_; installPhase = "install -D ${name} $out/bin/${name}"; buildPhase = lib.strings.concatStringsSep " " [ @@ -98,7 +100,9 @@ let check python -m ${mainModule} test ''; preBuild = '' - # initialize possibly-empty subdirectories as python modules + # remove empty directories, leftover from the src filter + find . -type d -empty -delete + # initialize remaining dirs as python modules find . -type d -exec touch {}/__init__.py \; # generate a minimal setup.py cat > setup.py << EOF @@ -120,7 +124,7 @@ let }; }; in builders.${target.builder}; -# the caller gives us the Analysis type, which is a hashmap, but i need to +# the bild caller gives us the Analysis type, which is a hashmap, but i need to # return a single drv, so just take the first one for now. ideally i would only # pass Target, one at a time, (perhaps parallelized in haskell land) and then i # wouldn't need all of this let nesting diff --git a/Biz/Bild/Example.py b/Biz/Bild/Example.py index 25686fa..5d165d8 100644 --- a/Biz/Bild/Example.py +++ b/Biz/Bild/Example.py @@ -1,6 +1,6 @@ """ Example Python file that also serves as a test case for bild. -fernet.""" +""" # : out example # : dep cryptography import sys diff --git a/Biz/Ide/hooks/commit-msg b/Biz/Ide/hooks/commit-msg new file mode 100755 index 0000000..64e400d --- /dev/null +++ b/Biz/Ide/hooks/commit-msg @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +gitlint --ignore-stdin --staged --msg-filename "$1" run-hook -- cgit v1.2.3