@@ -1216,6 +1216,44 @@ importNix
12161216 :: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m )
12171217importNix = scopedImportNix $ nvSet mempty mempty
12181218
1219+ -- | @scopedImport scope path@
1220+ -- An undocumented secret powerful function.
1221+ --
1222+ -- At the same time it is strongly forbidden to be used, as prolonged use of it would bring devastating consequences.
1223+ -- As it is essentially allows rewriting(redefinition) paradigm.
1224+ --
1225+ -- Allows to import the environment into the scope of a file expression that gets imported.
1226+ -- It is as if the contents at @path@ were given to @import@ wrapped as: @with scope; path@
1227+ -- meaning:
1228+ --
1229+ -- > -- Nix pseudocode:
1230+ -- > import (with scope; path)
1231+ --
1232+ -- For example, it allows to use itself as:
1233+ -- > bar = scopedImport pkgs ./bar.nix;
1234+ -- > -- & declare @./bar.nix@ without a header, so as:
1235+ -- > stdenv.mkDerivation { ... buildInputs = [ libfoo ]; }
1236+ --
1237+ -- But that breaks the evaluation/execution sharing of the @import@s.
1238+ --
1239+ -- Function also allows to redefine or extend the builtins.
1240+ --
1241+ -- For instance, to trace all calls to function ‘map’:
1242+ --
1243+ -- > let
1244+ -- > overrides = {
1245+ -- > map = f: xs: builtins.trace "call of map!" (map f xs);
1246+ --
1247+ -- > # Propagate override by calls to import&scopedImport.
1248+ -- > import = fn: scopedImport overrides fn;
1249+ -- > scopedImport = attrs: fn: scopedImport (overrides // attrs) fn;
1250+ --
1251+ -- > # Update ‘builtins’.
1252+ -- > builtins = builtins // overrides;
1253+ -- > };
1254+ -- > in scopedImport overrides ./bla.nix
1255+ --
1256+ -- In the related matter the function can be added and passed around as builtin.
12191257scopedImportNix
12201258 :: forall e t f m
12211259 . MonadNix e t f m
0 commit comments