How to keep clean in local nix assembly
I read an article by Oliver Charles called "How I Grow with Nix" . Now I would like to use Nix for Haskell development too. One thing that puzzled me a bit, however, is the local build nix script description:
{ haskellPackages ? (import <nixpkgs> {}).haskellPackages }:
let
inherit (haskellPackages) cabal cabalInstall_1_18_0_2
text mtl transformers; # Haskell dependencies here
in cabal.mkDerivation (self: {
pname = "project-name";
version = "1.0.0";
src = ./.;
buildDepends = [
# As imported above
text mtl transformers
];
buildTools = [ cabalInstall_1_18_0_2 ];
enableSplitObjs = false;
})
(Source: Cited article )
If I'm not mistaken, Nix makes guarantees like binary substitution by invoking a hash from a set of attributes passed to the function. However, in this case, there is no version associated with the src attribute. Thus, I think that modifying my code locally would mean that different compilation results are associated with the same hash. Doesn't that violate Nix's warranties? Is Nix smart enough to detect changes to the filesystem (by looking at timestamps, for example)?
source to share
Every time you invoke nix-shell, it calculates the hash of what is currently in src and copy it to the nix repository under the name hash if it doesn't already exist. So the changed src content will result in a new hash at the end. This is true for all paths in the derivation attribute set; They are all copied to the nix repository.
Of course, the same thing happens when you do the correct installation.
source to share