From 605c8f7789d9ef446c8f22d8c6a261b315be861d Mon Sep 17 00:00:00 2001 From: Joachim Breitner Date: Tue, 28 Mar 2023 09:35:49 +0200 Subject: [PATCH 1/5] Docs: Explain why `import nixpkgs` works in flakes --- src/libexpr/primops.cc | 11 ++++++++--- src/nix/flake.md | 2 ++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 3641ee468..73ffe03d4 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -254,9 +254,14 @@ static RegisterPrimOp primop_import({ .args = {"path"}, // TODO turn "normal path values" into link below .doc = R"( - Load, parse and return the Nix expression in the file *path*. If - *path* is a directory, the file ` default.nix ` in that directory - is loaded. Evaluation aborts if the file doesn’t exist or contains + Load, parse and return the Nix expression in the file *path*. + + The value *path* is conveted to a string as described in `builtins.toString`. + + If *path* is a directory, the file ` default.nix ` in that directory + is loaded. + + Evaluation aborts if the file doesn’t exist or contains an incorrect Nix expression. `import` implements Nix’s module system: you can put any Nix expression (such as a set or a function) in a separate file, and use it from Nix expressions in diff --git a/src/nix/flake.md b/src/nix/flake.md index 8eaa41b96..cd9f656e3 100644 --- a/src/nix/flake.md +++ b/src/nix/flake.md @@ -317,6 +317,8 @@ The following attributes are supported in `flake.nix`: also contains some metadata about the inputs. These are: * `outPath`: The path in the Nix store of the flake's source tree. + This way, the attribute set can be passed to `import` as if it was a path, + as in the example above (`import nixpkgs`). * `rev`: The commit hash of the flake's repository, if applicable. From 3ce6d72b2b5dd69a274518f2927d4dde0aa91247 Mon Sep 17 00:00:00 2001 From: Joachim Breitner Date: Tue, 28 Mar 2023 14:38:39 +0200 Subject: [PATCH 2/5] Update src/libexpr/primops.cc Co-authored-by: asymmetric --- src/libexpr/primops.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 73ffe03d4..4da7063b2 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -256,7 +256,7 @@ static RegisterPrimOp primop_import({ .doc = R"( Load, parse and return the Nix expression in the file *path*. - The value *path* is conveted to a string as described in `builtins.toString`. + The value *path* is converted to a string as described in `builtins.toString`. If *path* is a directory, the file ` default.nix ` in that directory is loaded. From 2e6b95dac7bd96c175db995b0cf7a1c3972fe4b8 Mon Sep 17 00:00:00 2001 From: Joachim Breitner Date: Wed, 29 Mar 2023 13:19:51 +0200 Subject: [PATCH 3/5] Update src/libexpr/primops.cc Co-authored-by: Eelco Dolstra --- src/libexpr/primops.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 4da7063b2..ea91aac03 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -258,7 +258,7 @@ static RegisterPrimOp primop_import({ The value *path* is converted to a string as described in `builtins.toString`. - If *path* is a directory, the file ` default.nix ` in that directory + If *path* is a directory, the file `default.nix` in that directory is loaded. Evaluation aborts if the file doesn’t exist or contains From 1b6cfe6fa1f27046216a7b2a88b0513b1f6be4c1 Mon Sep 17 00:00:00 2001 From: Joachim Breitner Date: Thu, 30 Mar 2023 10:40:04 +0200 Subject: [PATCH 4/5] More precise wording --- src/libexpr/primops.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index ea91aac03..fdac53df2 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -256,7 +256,9 @@ static RegisterPrimOp primop_import({ .doc = R"( Load, parse and return the Nix expression in the file *path*. - The value *path* is converted to a string as described in `builtins.toString`. + The value *path* can be a path, a string, or an attribute set with an + `__toString` attribute or a `outPath` attribute (as derivations or falke + inputs typically have). If *path* is a directory, the file `default.nix` in that directory is loaded. From 02050bd055120874f38194b9790c70c84792c369 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 30 Mar 2023 10:49:21 +0200 Subject: [PATCH 5/5] Typo --- src/libexpr/primops.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index fdac53df2..72faeada8 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -257,7 +257,7 @@ static RegisterPrimOp primop_import({ Load, parse and return the Nix expression in the file *path*. The value *path* can be a path, a string, or an attribute set with an - `__toString` attribute or a `outPath` attribute (as derivations or falke + `__toString` attribute or a `outPath` attribute (as derivations or flake inputs typically have). If *path* is a directory, the file `default.nix` in that directory