@@ -1,12 +1,14 @@
1{ pkgs, nix, runCommand, checkMaterialization }@defaults:
1{ pkgs, nix, runCommand, checkMaterialization }@defaults:
2−{ sha256
2+{ sha256 ? null # Has to make this a fixed output derivation
3−, sha256Arg # Name of the sha256 argument for more meaningful
4+ # Name of the sha256 argument for more meaningful
4 # error messages when checking the materialization.
5 # error messages when checking the materialization.
5, materialized # null or path where to find materialized version of
6, materialized # null or path where to find materialized version of
6 # the output. If this is set but does not exist
7 # the output. If this is set but does not exist
7 # the derivation will fail but with a message
8 # the derivation will fail but with a message
8 # advising how to populate it.
9 # advising how to populate it.
10+, reasonNotSafe ? null
9−, reasonNotSafe # Some times there a reasont the derivation will
11+ # Some times there a reasont the derivation will
10 # not produce output that can be safely materialized.
12 # not produce output that can be safely materialized.
11 # Set this to a string explaining why and materialization
13 # Set this to a string explaining why and materialization
12 # will not be used (if sha256 was set an error will be
14 # will not be used (if sha256 was set an error will be
@@ -37,7 +39,7 @@ let
37 # Warn the user if they tried to pin stuff down when it is not safe
39 # Warn the user if they tried to pin stuff down when it is not safe
38 traceIgnoringSha256 reasonNotSafe
40 traceIgnoringSha256 reasonNotSafe
39 (traceIgnoringMaterialized reasonNotSafe calculateNoHash)
41 (traceIgnoringMaterialized reasonNotSafe calculateNoHash)
40− else if sha256 == null
42+ else if sha256 == null && materialized == null
42 # Let the user know how to calculate a sha256 to use to make this
44 # Let the user know how to calculate a sha256 to use to make this
43 # a fixed output derivation.
45 # a fixed output derivation.
@@ -52,7 +54,7 @@ let
52 calculateUseHash
54 calculateUseHash
54 # Everything is in place we can safely use the sha256 and materialized
56 # Everything is in place we can safely use the sha256 and materialized
55− calculateUseAll;
57+ calculateUseMaterialized;
57 # Build fully and check the hash and materialized versions
59 # Build fully and check the hash and materialized versions
58 checked = runCommand name {
60 checked = runCommand name {
@@ -119,17 +121,14 @@ let
119 # Make sure output files can be removed from the sandbox
121 # Make sure output files can be removed from the sandbox
120 chmod -R +w $out
122 chmod -R +w $out
122− calculateUseAll =
124+ calculateUseMaterialized =
123− # Skip right to expectedPath if it already exists
124− if materialized != null
125+ assert materialized != null;
126− assert __pathExists materialized;
126+ assert __pathExists materialized;
127− runCommand name hashArgs ''
127+ runCommand name (pkgs.lib.optionalAttrs (sha256 == null) hashArgs) ''
128− cp -r ${materialized} $out
128+ cp -r ${materialized} $out
129− # Make sure output files can be removed from the sandbox
129+ # Make sure output files can be removed from the sandbox
130− chmod -R +w $out
130+ chmod -R +w $out
132− else calculateUseHash;
134 # Materialized location was specified, but the files are not there.
133 # Materialized location was specified, but the files are not there.
135 missingMaterialized = materialized != null && !__pathExists materialized;
134 missingMaterialized = materialized != null && !__pathExists materialized;