Testing locally… I think I’ve hit a snag that I don’t quite know how to fix. My blog’s articles generate a changelog using git and that relies on having access to the git repo… and I think when nix yanks the source repo to start a nix build it doesn’t bring the whole .git folder and history with it?
so when the nix-dominated ruby script runs and makes calls out to git log I see errors that this isn’t a git repo and there’s no .git folder.
The things I’ve thought:
Figure out a way to make the full git history available to the git executable when the static site builder is running.
Use a different method to get the “changelog…” maybe computing it before-hand?
It could be that using nix build to run a static site generator to generate a folder of .html files is the wrong path entirely.
Can you explain a bit more about how this should work. We’re talking about a pipeline runner so is it correct to assume that your repo is already checked out there? Is there a reason you cannot use the history from that?
In a nix shell, I can run middleman build and middleman takes the contents of my ./source folder and builds the result into ./build. When I run nix build I run into the “not a git repository” problems.
The reason that the “builder” is calling out to git is because I use git log to build changelog’s of blog posts. I played with commenting those out, and then it works fine. I tried using builtins.fetchGit { url = ./.; shallow = false; } with nix build --impure, but then I was having git crash with error 128, which is what I’m chasing at the moment.
What I’m seeing is that every time the file would call out to git log it throws that error, and that ends up in the middleman logs, which are passing it up to the nix derivation logs.
I’ve played with adding a ls -la to the build phase instructions, and there’s no ./.git folder, so I’m guessing that’s a big part of it.
Thank you for your patience and help @jalphad. I really appreciate it.
If you run the experimental nix build in a Git directory, it is currently interpreted as a git+file: URL which cannot include any files not tracked in Git, including .git.
The best way to fix that is to tell the program that tries to read .git to not do that, and instead pass it the Git version information you receive from the flake, such as self.rev. You’ll find lots of examples of this in Nixpkgs, e.g. here or here.
There’s also other ways of getting around that, but these won’t work when you build e.g. from a builtins.fetchGit or pkgs.fetchFromGitHub source, so I don’t recommend them (though you could set leaveDotGit = true, which would work):
You can explicitly tell Nix to not do the Git filtering on the repo using nix build path:.. This comes with the drawback that it’s going to copy the entire repository, including the full history, into the Nix store every time you build, so I wouldn’t recommend that.
You can use the stable nix-build interface which doesn’t have any implicit filtering behavior, which then allows you to e.g. explicitly filter for git-tracked files but adding some file from the .git directory:
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.union
(lib.fileset.gitTracked ./.)
# Also include this file in the source, only works reasonably with `nix-build`
./.git/HEAD;
}
If I understand you correctly, you are suggesting bringing in just the current commit or sha for tagging purposes. I’m looking to do a little more than that.
Each markdown file on my blog when it’s being built calls out to git log to get it’s changelog, which is then rendered as part of the final page. The goal is to provide a list of edits. So I think I want more than just .git/HEAD or self.rev.
You have provided a great clue with the reference to git+file:'s behavior. Maybe that rabbit trail will lead me down the right road.
Can you think of a way that during the buildPhase I could run git log commands against a file?