

Use a Nix Flake without Adding it to Git
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.

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 ...
Recommend
-
6
Author: Nick Sigulya Here at Typeable, we wanted to publish a small series of posts about the way Nix helps us (and slightly hinders) in software development. We would like to start with an introduction to Nix which we might refer to...
-
11
adding new rows in excel without breaking a vba macro that uses Range.Value advertisements I've written a macro in VBA that simply fills in a...
-
11
Novice Nix: Flake Templates Flakes are very handy to setup entirely pure, project-specific dependencies (not just dependencies, but build steps, shell environments and more) in a declara...
-
7
-
5
28 Comments ...
-
11
Launch HN: DeploySentinel (YC S22) – End-to-end tests that don't flake Lau...
-
3
Do you use Nix or equivalent to manage projects and/or systems? I maintain several derivations (packages) in NixPkgs and manage all my personal/work machines using NixOS. I am considering to pus...
-
6
We use cookies to improve your experience and anonymously analyze usage. Learn more in our privacy settings.
-
6
Why tests flake more on CI than locally by Jason Swett, April 19,...
-
5
Introducing the Nix Flake Checker Jun 20, 2023By Luc PerkinsIntroducing the Nix Flak...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK