# Derivation gets always rebuilt

**URL:** https://discourse.nixos.org/t/derivation-gets-always-rebuilt/51246
**Category:** Help
**Created:** [August 27, 2024, 3:46pm UTC](https://discourse.nixos.org/t/derivation-gets-always-rebuilt/51246 "2024-08-27T15:46:31Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![ElvishJerricco](https://discourse.nixos.org/user_avatar/discourse.nixos.org/elvishjerricco/32/984_2.png) [@ElvishJerricco](https://discourse.nixos.org/u/ElvishJerricco)
#### Post date: [August 27, 2024, 4:37pm UTC](https://discourse.nixos.org/t/derivation-gets-always-rebuilt/51246/3 "2024-08-27T16:37:30Z")

</div>

@waffle8946 The tip in that link is not relevant, since it’s the same source directory in use.

That said, @brodriguesco pointing `src` at `./.` is often a cause of issues. In this case, I wager it’s because of the `result` symlink. When you first build, `./.` contains no `result` symlink. Then when you build again, it’s a difference source directory, because this one has a `result` symlink pointing at the last result. And this results in a new build with a new `result` symlink. Since the result symlink is different now, the next build with have a different source again. Ad infinitum.

The fix is to filter the source. `nixpkgs` has a lib function called `cleanSource` that will filter out stuff like this and your `.git` directory, so you can do `src = pkgs.lib.cleanSource ./.;`. Or, you can use `src = builtins.fetchGit ./.;` to only get those files tracked by git (meaning you’ll have to `git add` any new files before building); providing no `rev` argument means it’ll get the dirty worktree. This is actually what flakes do, so using flakes is another option.

---

_[View the full topic](https://discourse.nixos.org/t/derivation-gets-always-rebuilt/51246)._
