Yep. Definitely!
One caveat, in short, is: Everything involved in the build must be placed under the nix store (/nix/store). Which, for some software, can cause issues: They might have a hardcoded runtime path that references /usr/lib.
Nix provides tools to resolve these assumptions, but they can still be a sticking point at times.
There is also, more or less, a unsafePerformIO that can be used. Which is discouraged. Still, for private builds the cost can be acceptable.
Assuming I understand the question correctly: Yes.
Nix uses a pure evaluation model so it enjoys the property: An artifact in the nix store is uniquely identified by the closure used to build the artifact. For any artifacts A, B if and only if the closure used to build the artifact are equal then the artifact file path will be equal.
This creates opportunities for sharing between builds that can be hard to achieve in other systems. One form of sharing "referencing a derivation in multiple apps" works as expected, just like other systems: Each app will reference the same artifact.
(a derivation is the closure to be evaluated to build an artifact in the nix store. Well, attribute set of closures.)
Suppose a derivation is assigned to the variable "commonData" and two derivations "appX" and "appY" reference this closure. "commonData" will be built once and both app derivations will receive a path to the same file in the nix store.
The other form of sharing comes from the equality comparison being based on the closure and not the name used to reference the closure.
Ehh.. I'm butchering the explanation... I think there is a succinct PL term that covers this.
Suppose we have a derivation:
let x = mkDerviation { name = "foo"; builder = aBuilder; src = /share/src/foo; }
which is referenced by another derivation
let y = mkDerviation { name = "bar"; builder = aBuilder; src = /share/src/bar; inherit x; }
"y" will force the evaluation of the "x" derivation's closure. The source directories, since they are not in the nix store, will be copied to the nix store first. (By an implicit conversion between local files and nix store paths)
So far so good, but what happens if there is another derivation like so?
let z = mkDerviation { name = "zab"; builder = aBuilder; src = /share/src/zab; somethingLikeX = mkDerviation { name = "foo"; builder = aBuilder; src = /share/src/foo; }; }
"somethingLikeX"'s equation is equal to "x" but not the same reference.
What will happen if z is evaluated after y? (assuming aBuilder is the same)
First, the derivation "somethingLikeX" will be evaluated. Ah ha! That closure is equal to the closure for "x" above! Which has already been evaluated. So that evaluation result will be shared. Even though "z" does not directly reference "x".
This can result in more sharing than the developer explicitly requested: Equal closures are shared.