3

Use a Nix Flake without Adding it to Git

 8 months ago
source link: https://mtlynch.io/notes/use-nix-flake-without-git/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Use a Nix Flake without Adding it to Git

December 29, 2023

2-minute read

When I work in my own repositories these days, I always add a Nix flake to the repo so that I can spin up a working development environment on any system with a single command.

What do I do when I’m working in someone else’s repo and they don’t want to adopt Nix flakes?

Normally, I’d just add the file to my copy of the repo and gitignore it locally so I don’t commit my personally-specific files with the rest of my changes.

The problem with Nix flakes is that they don’t work unless you git add flake.nix to your repo. So, I searched for a way to have my own flake.nix file without committing it to Git.

Hiding changes from git 🔗︎

Silvan Mosberger offered this solution:

git add --intent-to-add flake.nix flake.lock && \
  git update-index --assume-unchanged flake.nix flake.lock

It doesn’t work perfectly, as commands like git reset will undo it, but it effectively hides the flake files from the changeset.

Telling Nix to ignore git 🔗︎

Serhii Khoma also showed a workaround where you can tell Nix to ignore the git repository:

nix develop path:.

This seems to be a little slower than the standard git-based version.

And then you can ignore the flake files locally with this command:

echo "flake.nix" >> .git/info/exclude && \
  echo "flake.lock" >> .git/info/exclude

This solution is more robust than the hide changes workaround, though you have to remember to use a different nix develop command than you might be used to.

Loading comments ...


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK