Advertisement
Guest User

Untitled

a guest
May 19th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. # Understanding Nix Inputs
  2.  
  3. Every Nix derivation produces a Nix store output that has 3 things:
  4.  
  5. * Executables
  6. * Libraries
  7. * Data
  8.  
  9. Executables are always exported using the `PATH` environment variable. This is pretty much automatic.
  10.  
  11. Libraries are exported in environment variables that are dependent on the language environment you are in.
  12. For example `PYTHONPATH` for Python. Or `C_INCLUDE_PATH` for `gcc`. This is usually done via a setup hook.
  13.  
  14. Data is often not exported with any special environment variables, unless you explicitly refer to them. You
  15. can do this within a Nix expression by simply interpolating the derivation as a string which will evaluate
  16. to their Nix store path.
  17.  
  18. During the transformation from a Nix derivation to a Nix output.
  19. We differentiate build environments from runtime environments.
  20. Here we are not considering cross-compilation.
  21. We are assuming that build and run environments are on the same machine.
  22.  
  23. * `buildInputs` - Dependencies that should exist in the runtime environment.
  24. * `propagatedBuildInputs` - Dependencies that should exist in the runtime environment and also propagated to downstream runtime environments.
  25. * `nativeBuildInputs` - Dependencies that should only exist in the build environment.
  26. * `propagatedNativeBuildInputs` - Dependencies that should only exist in the build environment and also propagated to downstream build environments.
  27.  
  28. The above is not strictly true all the time because it depends on the derivation functions you are using.
  29.  
  30. The specific derivation function may have a different interpretation of what "propagation" means. And what environment variables they will propagate.
  31.  
  32. But basically we can see that most Python modules for a Python package must exist at runtime.
  33. They must also be propagated to downstream runtime environments, because any Python package that loads your package must be able to load your package's dependencies.
  34. This is why Python packages that export Python modules need to be in `propagatedBuildInputs`.
  35.  
  36. However consider C libraries that get compiled into shared objects. These shared objects are linked into by your C executable. Downstream users of your executable don't need to know about your the shared objects that your executable uses.
  37. This is why C packages that expose C libraries are put into `buildInputs` and not `propagatedBuildInputs`.
  38.  
  39. Note that when we use `nix-shell`, we are essentially entering into the build environment.
  40. This could mean that packages that are in `propagatedBuildInputs` or `buildInputs` which expose CLI executables may not
  41. appear in the build environment. It is important to realise this is a __may__ as it depends on the derivation interpretation.
  42.  
  43. It's important to be explicit. So if you want something to always appear in the build environment and runtime environment, then it should be added to both.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement