From f16fca53963fbfb83d1517a553068ddcb5ca216b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Domen=20Ko=C5=BEar?= Date: Mon, 17 Jul 2023 12:30:53 +0100 Subject: [PATCH] Allow plain file imports --- docs/reference/yaml-options.md | 1 + examples/imports/.test.sh | 2 ++ examples/imports/devenv.nix | 1 + examples/imports/devenv.yaml | 3 +++ examples/imports/file.nix | 3 +++ examples/imports/folder/devenv.nix | 3 +++ mkdocs.yml | 2 +- src/flake.nix | 4 +++- 8 files changed, 17 insertions(+), 2 deletions(-) create mode 100755 examples/imports/.test.sh create mode 100644 examples/imports/devenv.nix create mode 100644 examples/imports/devenv.yaml create mode 100644 examples/imports/file.nix create mode 100644 examples/imports/folder/devenv.nix diff --git a/docs/reference/yaml-options.md b/docs/reference/yaml-options.md index cd8079c88..86dab6399 100644 --- a/docs/reference/yaml-options.md +++ b/docs/reference/yaml-options.md @@ -42,6 +42,7 @@ inputs: imports: - ./frontend - ./backend + . ./mymodule.nix - myproject - myproject/relative/path ``` diff --git a/examples/imports/.test.sh b/examples/imports/.test.sh new file mode 100755 index 000000000..585606f3a --- /dev/null +++ b/examples/imports/.test.sh @@ -0,0 +1,2 @@ +env | grep "FILE=1" +env | grep "FOLDER=1" \ No newline at end of file diff --git a/examples/imports/devenv.nix b/examples/imports/devenv.nix new file mode 100644 index 000000000..ffcd4415b --- /dev/null +++ b/examples/imports/devenv.nix @@ -0,0 +1 @@ +{ } diff --git a/examples/imports/devenv.yaml b/examples/imports/devenv.yaml new file mode 100644 index 000000000..bf0130280 --- /dev/null +++ b/examples/imports/devenv.yaml @@ -0,0 +1,3 @@ +imports: +- ./file.nix +- ./folder/ \ No newline at end of file diff --git a/examples/imports/file.nix b/examples/imports/file.nix new file mode 100644 index 000000000..488c5c21f --- /dev/null +++ b/examples/imports/file.nix @@ -0,0 +1,3 @@ +{ + env.FILE = "1"; +} diff --git a/examples/imports/folder/devenv.nix b/examples/imports/folder/devenv.nix new file mode 100644 index 000000000..8cfe10d0f --- /dev/null +++ b/examples/imports/folder/devenv.nix @@ -0,0 +1,3 @@ +{ + env.FOLDER = "1"; +} diff --git a/mkdocs.yml b/mkdocs.yml index 550df86cd..caef64db6 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -42,7 +42,7 @@ nav: - Common Patterns: common-patterns.md - Writing devenv.yaml: - Inputs: inputs.md - - Composing Using Imports: composing-using-imports.md + - Imports: composing-using-imports.md - Overview: - Automatic Shell Activation: automatic-shell-activation.md - Garbage Collection: garbage-collection.md diff --git a/src/flake.nix b/src/flake.nix index ceca91dfb..970585903 100644 --- a/src/flake.nix +++ b/src/flake.nix @@ -31,7 +31,9 @@ lib = pkgs.lib; importModule = path: if lib.hasPrefix "./" path - then ./. + (builtins.substring 1 255 path) + "/devenv.nix" + then if lib.hasSuffix ".nix" path + then ./. + (builtins.substring 1 255 path) + else ./. + (builtins.substring 1 255 path) + "/devenv.nix" else if lib.hasPrefix "../" path then throw "devenv: ../ is not supported for imports" else let