From fea13064d409cda9d18e222ef29ceaaa47e2f205 Mon Sep 17 00:00:00 2001 From: Noam Yorav-Raphael Date: Wed, 10 Apr 2024 21:29:58 +0300 Subject: [PATCH 1/3] Improve the description of how runtime dependencies are found --- pills/09-automatic-runtime-dependencies.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pills/09-automatic-runtime-dependencies.md b/pills/09-automatic-runtime-dependencies.md index 3641c27..a976251 100644 --- a/pills/09-automatic-runtime-dependencies.md +++ b/pills/09-automatic-runtime-dependencies.md @@ -48,9 +48,12 @@ Nix handles runtime dependencies for us automatically. The technique it uses to 1. Dump the derivation as a NAR. Recall that this is a serialization of the derivation output \-- meaning this works fine whether the output is a single file or a directory. -2. For each build dependency `.drv` and its relative out path, search the contents of the NAR for this out path. +2. For each build dependency, search the contents of the NAR for the hash part of its out path. For example: + * Our derivation depends on `/nix/store/sk590g7fv53m3zp0ycnxsc41snc2kdhp-gzip-1.6.drv` + * Its output path is `/nix/store/hcrf95x3r60kw71wgwbdybjfcq0ipkpj-gzip-1.6`. + * Therefore, Nix will search the NAR for `hcrf95x3r60kw71wgwbdybjfcq0ipkpj`. -3. If the path is found, then it's a runtime dependency. +3. If the hash is found, then it's a runtime dependency. The snippet below shows the dependencies for `hello`. From 8a9dd1684027c77fee320b9d880cf3e921fa6b32 Mon Sep 17 00:00:00 2001 From: Noam Yorav-Raphael Date: Fri, 12 Apr 2024 10:18:54 +0300 Subject: [PATCH 2/3] Make the description more accurate, and link to the source code --- pills/09-automatic-runtime-dependencies.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pills/09-automatic-runtime-dependencies.md b/pills/09-automatic-runtime-dependencies.md index a976251..67c23d2 100644 --- a/pills/09-automatic-runtime-dependencies.md +++ b/pills/09-automatic-runtime-dependencies.md @@ -46,14 +46,16 @@ We now note that Nix automatically recognized build dependencies once our `deriv Nix handles runtime dependencies for us automatically. The technique it uses to do so may seem fragile at first glance, but it works so well that the NixOS operating system is built off of it. The underlying mechanism relies on the hash of the store paths. It proceeds in three steps: -1. Dump the derivation as a NAR. Recall that this is a serialization of the derivation output \-- meaning this works fine whether the output is a single file or a directory. +1. Dump the derivation as a NAR. Recall that this is a serialization of the derivation output — meaning this works fine whether the output is a single file or a directory. -2. For each build dependency, search the contents of the NAR for the hash part of its out path. For example: +2. For each build dependency (including transitive dependencies), search the contents of the NAR for the hash part of its out path. For example: * Our derivation depends on `/nix/store/sk590g7fv53m3zp0ycnxsc41snc2kdhp-gzip-1.6.drv` * Its output path is `/nix/store/hcrf95x3r60kw71wgwbdybjfcq0ipkpj-gzip-1.6`. * Therefore, Nix will search the NAR for `hcrf95x3r60kw71wgwbdybjfcq0ipkpj`. -3. If the hash is found, then it's a runtime dependency. +3. Each hash which is found somewhere in the NAR is recorded as a runtime dependency. + +(For completeness: some derivations have multiple output paths. In that case, Nix will search for the hashes of all the outputs. Also, Nix will search for the hashes of source dependencies, such as our `build.sh` file. The authoritative definition is the [source code](https://github.com/NixOS/nix/blob/a268c0de7192188c7233bf83a4635198c360e270/src/libstore/build/local-derivation-goal.cc#L2220-L2227).) The snippet below shows the dependencies for `hello`. From 91132ba30f71e94228a29b317e2dabd0dc13435e Mon Sep 17 00:00:00 2001 From: Noam Yorav-Raphael Date: Fri, 12 Apr 2024 13:26:28 +0300 Subject: [PATCH 3/3] Fix description: Nix only looks at the hashes of all referenced outputs. --- pills/09-automatic-runtime-dependencies.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pills/09-automatic-runtime-dependencies.md b/pills/09-automatic-runtime-dependencies.md index 67c23d2..727c3e2 100644 --- a/pills/09-automatic-runtime-dependencies.md +++ b/pills/09-automatic-runtime-dependencies.md @@ -55,7 +55,7 @@ Nix handles runtime dependencies for us automatically. The technique it uses to 3. Each hash which is found somewhere in the NAR is recorded as a runtime dependency. -(For completeness: some derivations have multiple output paths. In that case, Nix will search for the hashes of all the outputs. Also, Nix will search for the hashes of source dependencies, such as our `build.sh` file. The authoritative definition is the [source code](https://github.com/NixOS/nix/blob/a268c0de7192188c7233bf83a4635198c360e270/src/libstore/build/local-derivation-goal.cc#L2220-L2227).) +(For completeness: some derivations have multiple output paths. In that case, Nix will search for the hashes of all the referenced outputs. Also, Nix will search for the hashes of source dependencies, such as our `build.sh` file. The authoritative definition is the [source code](https://github.com/NixOS/nix/blob/a268c0de7192188c7233bf83a4635198c360e270/src/libstore/build/local-derivation-goal.cc#L2220-L2227).) The snippet below shows the dependencies for `hello`.