Best practice for literate flakes

I actually have a literate NixOs config and I want to migrate to flakes.

As I have understood applying a flake all the files tracked by git are copied in the Nix store. The problem is that in my git repo all markdown files, the Makefile, and other utilities are tracked (and they have not to be copied), instead the tangled nix files (which are the only ones to be copied to the store) are in .gitignore since I don’t want them in my git repo as they are an artifact generated by tangling the markdown files.

I thought to tangle them in a temporary folder, initialize a git repo and then applying the flakes but this trick is unnecessary complicated and doesn’t allow me to track the lock file (I have to add an instruction to re-copy it back to the project folder in the makefile).

So are there any better practice to achieve this?

My actual dotfiles: Files · 12eb3c78a6712a4266c74c3b073cfd64a2f5b619 · Davide Peressoni / dotfiles · GitLab
relevant parts of the Makefile (config folder is gitignored):

install-system: build-system
	sudo nixos-rebuild switch -I nixos-config="./config/configuration.nix"

install-home: build-home
	home-manager switch -b bak -f "config/home.nix"

build-%: src/%
	@mkdir -p config
	cd config && lmt `find ../$</ -type f -name '*.md'`

A flake needn’t be a git repo, but iirc it uses git if it’s anywhere inside a git worktree. You could construct the flake outside the worktree, or you could use IFD to tangle and import the nix files when evaluating the flake. This would require that the flake.nix itself be non-literate, but would have the benefit of being completely transparent when using the flake, and tracking the locking of inputs normally.

1 Like

Please be aware that IFD will fail for many of the flake introspection commands and might also get disabled by default eventually.

1 Like

Ah, I didn’t think of the flake introspection command problem :slightly_frowning_face:. I’ve run into that before with nix search since I use an IFD-based overlay. You can get around it by explicitly adding --allow-import-from-derivation to the command, but that does get old fast.