Skip to content

Instantly share code, notes, and snippets.

What would you like to do?

fix function - , , point where x = f(x) = f(f(f(f....f(x)....)))

rec { a = 1; b = a + 1; } is the same as fix (self: { a = 1; b = self.a + 1; })

builtins.trace - trace has different flavors, all lazy languages have trace

builtins.seq - in lazy languages data is represented as thunks (IF data has not been yet evaluated THEN it's pointer on function that should produce this data ELSE it's pointer on data), builtins.seq forces first layer of data to evaluate (evaluates it to WHNF?), builtins.deepSeq is recursive variant of seq, it forces whole data to evaluate (evaluates it to NF?), (more,

nix-shell - debugging example

$ nix-shell --pure <package>
$ typeset # to see all availeale functions with their definitions
$ type genericBuild # to see genericBuild definition
$ set -e # to exit on error
$ set -x # to show all executed commands
$ source $stdenv/setup # to setup env
$ genericBuild # to start phases

lib.evalModule - it's easy, n.b. it uses fixed points

derivation - it's easy,

mkDerivation - wrapper on derivation, I think maybe they put too much logic in this function

how path is different from string - paths are copied to nix store when they are forced to evaluate. IF string was constructed from path (this info is stored in "string context"), THEN string evaluation will force path to be copied to nix store too (e.g. evaluation of "${/foo}/bar" will copy directory /foo as /nix/store/xxxx-foo, resulting string will be /nix/store/xxxx-foo/bar).'s-string-context/

but "${toString ./foo}/bar" will produce "/fullpath/foo/bar"

callPackage -

IDF means import from derivation - when you import some file from derivation (e.g. arion = import "${arionSrcFromGithub}/release.nix"), the arionSrcFromGithub is not saved anywhere as dependency for arion and will be removed on next garbage collection. This makes sense, but you end up downloading arionSrcFromGithub all the time from the internet. To resolve this you can add arionSrcFromGithub to /nix/var/nix/gcroots using nix-build --add-root OR save the link to it inside some derivation that added to gcroots (e.g. arion)

nix-build --check - nix assumes that your derivation builder outputs same result given same inputs, this may not be true, using this flag the derivation will be built twice, IF resulting hash of the package content (!!!, not the hash of the path, i.e. xxxx in /nix/store/xxxx-yyy, this hash is computed only from derivation inputs) is different THEN it will return an error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.