From 9215a20921df928b1ff8de201ea08196108cdb72 Mon Sep 17 00:00:00 2001 From: sidux Date: Wed, 22 Nov 2023 18:12:54 +0100 Subject: [PATCH 01/13] handle multiple dotenv files --- src/modules/integrations/dotenv.nix | 58 ++++++++++++----------------- 1 file changed, 23 insertions(+), 35 deletions(-) diff --git a/src/modules/integrations/dotenv.nix b/src/modules/integrations/dotenv.nix index b33c128d8..adb1f7665 100644 --- a/src/modules/integrations/dotenv.nix +++ b/src/modules/integrations/dotenv.nix @@ -3,9 +3,9 @@ let cfg = config.dotenv; - dotenvPath = config.devenv.root + "/" + cfg.filename; + dotenvFiles = if lib.length cfg.filenames > 0 then cfg.filenames else [ cfg.filename ]; + dotenvPaths = map (filename: config.devenv.root + "/" + filename) dotenvFiles; - dotenvFound = lib.pathExists dotenvPath; parseLine = line: let parts = builtins.match "(.+) *= *(.+)" line; @@ -16,6 +16,8 @@ let null; parseEnvFile = content: builtins.listToAttrs (lib.filter (x: !builtins.isNull x) (map parseLine (lib.splitString "\n" content))); + + mergeEnvFiles = files: lib.foldl' (acc: file: lib.recursiveUpdate acc (if lib.pathExists file then parseEnvFile (builtins.readFile file) else { })) { } files; in { options.dotenv = { @@ -24,9 +26,13 @@ in filename = lib.mkOption { type = lib.types.str; default = ".env"; - description = '' - The name of the dotenv file to load. - ''; + description = "The name of the primary dotenv file to load."; + }; + + filenames = lib.mkOption { + type = lib.types.listOf lib.types.str; + default = [ ]; + description = "The list of dotenv files to load, in order of precedence. Overrides the `filename` option if provided."; }; resolved = lib.mkOption { @@ -37,46 +43,28 @@ in disableHint = lib.mkOption { type = lib.types.bool; default = false; - description = '' - Disable the hint that are printed when the dotenv module is not enabled, but .env is present. - ''; + description = "Disable the hint that are printed when the dotenv module is not enabled, but .env is present."; }; }; config = lib.mkMerge [ - (lib.mkIf (cfg.enable && builtins.pathExists dotenvPath) { + (lib.mkIf cfg.enable { env = lib.mapAttrs (name: value: lib.mkDefault value) config.dotenv.resolved; - dotenv.resolved = parseEnvFile (builtins.readFile dotenvPath); + dotenv.resolved = mergeEnvFiles dotenvPaths; }) - (lib.mkIf (cfg.enable && !builtins.pathExists dotenvPath) ( - let - exampleExists = builtins.pathExists (dotenvPath + ".example"); - in - { - enterShell = '' - echo "💡 A ${cfg.filename} file was not found, while dotenv integration is enabled." + (lib.mkIf (!cfg.enable && !cfg.disableHint) { + enterShell = + let + dotenvFound = lib.any (file: lib.pathExists file) dotenvPaths; + in + lib.optionalString dotenvFound '' + echo "💡 A dotenv file was found, while dotenv integration is currently not enabled." echo - ${lib.optionalString exampleExists '' - echo " To create .env, you can copy the example file:" - echo - echo " $ cp ${dotenvPath}.example ${dotenvPath}"; - echo - ''} - echo " To disable it, add \`dotenv.enable = false;\` to your devenv.nix file."; + echo " To enable it, add \`dotenv.enable = true;\` to your devenv.nix file."; + echo " To disable this hint, add \`dotenv.disableHint = true;\` to your devenv.nix file."; echo echo "See https://devenv.sh/integrations/dotenv/ for more information."; ''; - } - )) - (lib.mkIf (!cfg.enable && !cfg.disableHint) { - enterShell = lib.optionalString dotenvFound '' - echo "💡 A ${cfg.filename} file found, while dotenv integration is currently not enabled." - echo - echo " To enable it, add \`dotenv.enable = true;\` to your devenv.nix file."; - echo " To disable this hint, add \`dotenv.disableHint = true;\` to your devenv.nix file."; - echo - echo "See https://devenv.sh/integrations/dotenv/ for more information."; - ''; }) ]; } From 22a57079f394157a1413b94f3c3bd0b37660ae34 Mon Sep 17 00:00:00 2001 From: sidux Date: Wed, 22 Nov 2023 19:52:06 +0100 Subject: [PATCH 02/13] bump version --- src/modules/latest-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/latest-version b/src/modules/latest-version index 844f6a91a..d2b13eb64 100644 --- a/src/modules/latest-version +++ b/src/modules/latest-version @@ -1 +1 @@ -0.6.3 +0.6.4 From 6f21a9df9f949dc17f8dd93100a309259cc82c42 Mon Sep 17 00:00:00 2001 From: sidux Date: Wed, 22 Nov 2023 20:00:28 +0100 Subject: [PATCH 03/13] update dotenv filenames tests --- docs/integrations/dotenv.md | 2 +- examples/dotenv/.test.sh | 2 +- examples/dotenv/devenv.nix | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/integrations/dotenv.md b/docs/integrations/dotenv.md index 2fb3b9713..a813ed509 100644 --- a/docs/integrations/dotenv.md +++ b/docs/integrations/dotenv.md @@ -8,7 +8,7 @@ If you have a `.env`, you'll see instructions how to enable integration: # Optionally, you can choose which filename to load. # - # dotenv.filename = ".env.production"; + # dotenv.filename = ".env.bar"; } ``` diff --git a/examples/dotenv/.test.sh b/examples/dotenv/.test.sh index 1840c4550..3ce26435d 100755 --- a/examples/dotenv/.test.sh +++ b/examples/dotenv/.test.sh @@ -1,2 +1,2 @@ env | grep FOO=1 -env | grep BAR=1 \ No newline at end of file +env | grep BAR=3 diff --git a/examples/dotenv/devenv.nix b/examples/dotenv/devenv.nix index 38cb50c22..34c647463 100644 --- a/examples/dotenv/devenv.nix +++ b/examples/dotenv/devenv.nix @@ -1,5 +1,6 @@ { pkgs, ... }: { dotenv.enable = true; + dotenv.filenames = [ ".env" ".env.bar" ]; env.BAR = "1"; } From 103bb42908b6571c9485af0c578a59fe18a1d49f Mon Sep 17 00:00:00 2001 From: sidux Date: Wed, 22 Nov 2023 22:10:06 +0100 Subject: [PATCH 04/13] update dotenv doc --- docs/integrations/dotenv.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/integrations/dotenv.md b/docs/integrations/dotenv.md index a813ed509..9d43a49c4 100644 --- a/docs/integrations/dotenv.md +++ b/docs/integrations/dotenv.md @@ -8,7 +8,9 @@ If you have a `.env`, you'll see instructions how to enable integration: # Optionally, you can choose which filename to load. # - # dotenv.filename = ".env.bar"; + # dotenv.filename = ".env.production"; + # or + # dotenv.filenames = [ ".env.production" ".env.development" ] } ``` From 6578f387783b81de9db74bfe199566d024d62948 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 22 Nov 2023 21:11:48 +0000 Subject: [PATCH 05/13] Auto generate docs/reference/options.md --- docs/reference/options.md | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/docs/reference/options.md b/docs/reference/options.md index d4cb9bf7f..d99c7832b 100644 --- a/docs/reference/options.md +++ b/docs/reference/options.md @@ -430,7 +430,7 @@ string *Default:* -` "0.6.3" ` +` "0.6.4" ` *Declared by:* - [https://github.com/cachix/devenv/blob/main/src/modules/update-check.nix](https://github.com/cachix/devenv/blob/main/src/modules/update-check.nix) @@ -506,7 +506,6 @@ Disable the hint that are printed when the dotenv module is not enabled, but .en - *Type:* boolean @@ -522,8 +521,7 @@ boolean ## dotenv.filename -The name of the dotenv file to load. - +The name of the primary dotenv file to load. @@ -540,6 +538,25 @@ string +## dotenv.filenames + +The list of dotenv files to load, in order of precedence. Overrides the `filename` option if provided. + + + +*Type:* +list of string + + + +*Default:* +` [ ] ` + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/dotenv.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/dotenv.nix) + + + ## enterShell Bash code to execute when entering the shell. @@ -1891,8 +1908,6 @@ to adjust the settings or add more extensions. You can find the extensions using `devenv search 'php extensions'` - - *Type:* package @@ -1924,6 +1939,8 @@ pkgs.php.buildEnv { Attribute set of packages including composer + + *Type:* submodule @@ -4727,8 +4744,6 @@ boolean ## pre-commit.settings.deadnix.noLambdaPatternNames - - Don’t check lambda pattern names (don’t break nixpkgs ` callPackage `). @@ -4748,6 +4763,8 @@ boolean ## pre-commit.settings.deadnix.noUnderscore + + Don’t check any bindings that start with a ` _ `. @@ -7025,8 +7042,6 @@ attribute set of attribute set of (INI atom (null, bool, int, float or string)) ## services.couchdb.settings.chttpd.bind_address - - Defines the IP address by which CouchDB will be accessible. @@ -7046,6 +7061,8 @@ string ## services.couchdb.settings.chttpd.port + + Defined the port number to listen. From 84c0c64e1fcdcbb9dc09b78c73f395322a1a5759 Mon Sep 17 00:00:00 2001 From: sidux Date: Wed, 22 Nov 2023 22:22:37 +0100 Subject: [PATCH 06/13] keep only filename instead of filenames in dotenv --- docs/integrations/dotenv.md | 2 +- examples/dotenv/devenv.nix | 2 +- src/modules/integrations/dotenv.nix | 15 +++++---------- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/docs/integrations/dotenv.md b/docs/integrations/dotenv.md index 9d43a49c4..ab6a17856 100644 --- a/docs/integrations/dotenv.md +++ b/docs/integrations/dotenv.md @@ -10,7 +10,7 @@ If you have a `.env`, you'll see instructions how to enable integration: # # dotenv.filename = ".env.production"; # or - # dotenv.filenames = [ ".env.production" ".env.development" ] + # dotenv.filename = [ ".env.production" ".env.development" ] } ``` diff --git a/examples/dotenv/devenv.nix b/examples/dotenv/devenv.nix index 34c647463..05cc64e38 100644 --- a/examples/dotenv/devenv.nix +++ b/examples/dotenv/devenv.nix @@ -1,6 +1,6 @@ { pkgs, ... }: { dotenv.enable = true; - dotenv.filenames = [ ".env" ".env.bar" ]; + dotenv.filename = [ ".env" ".env.bar" ]; env.BAR = "1"; } diff --git a/src/modules/integrations/dotenv.nix b/src/modules/integrations/dotenv.nix index adb1f7665..a2a78ed66 100644 --- a/src/modules/integrations/dotenv.nix +++ b/src/modules/integrations/dotenv.nix @@ -3,7 +3,8 @@ let cfg = config.dotenv; - dotenvFiles = if lib.length cfg.filenames > 0 then cfg.filenames else [ cfg.filename ]; + normalizeFilenames = filenames: if lib.isList filenames then filenames else [ filenames ]; + dotenvFiles = normalizeFilenames cfg.filename; dotenvPaths = map (filename: config.devenv.root + "/" + filename) dotenvFiles; parseLine = line: @@ -24,15 +25,9 @@ in enable = lib.mkEnableOption ".env integration, doesn't support comments or multiline values."; filename = lib.mkOption { - type = lib.types.str; + type = lib.types.either lib.types.str (lib.types.listOf lib.types.str); default = ".env"; - description = "The name of the primary dotenv file to load."; - }; - - filenames = lib.mkOption { - type = lib.types.listOf lib.types.str; - default = [ ]; - description = "The list of dotenv files to load, in order of precedence. Overrides the `filename` option if provided."; + description = "The name of the dotenv file to load, or a list of dotenv files to load in order of precedence."; }; resolved = lib.mkOption { @@ -59,7 +54,7 @@ in in lib.optionalString dotenvFound '' echo "💡 A dotenv file was found, while dotenv integration is currently not enabled." - echo + echo echo " To enable it, add \`dotenv.enable = true;\` to your devenv.nix file."; echo " To disable this hint, add \`dotenv.disableHint = true;\` to your devenv.nix file."; echo From 68f7e62e48e02ad7f739f6af7632bc023588e6f1 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 22 Nov 2023 22:02:22 +0000 Subject: [PATCH 07/13] Auto generate docs/reference/options.md --- docs/reference/options.md | 35 ++++++++--------------------------- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/docs/reference/options.md b/docs/reference/options.md index d99c7832b..1c81ce0f7 100644 --- a/docs/reference/options.md +++ b/docs/reference/options.md @@ -521,12 +521,12 @@ boolean ## dotenv.filename -The name of the primary dotenv file to load. +The name of the dotenv file to load, or a list of dotenv files to load in order of precedence. *Type:* -string +string or list of string @@ -538,25 +538,6 @@ string -## dotenv.filenames - -The list of dotenv files to load, in order of precedence. Overrides the `filename` option if provided. - - - -*Type:* -list of string - - - -*Default:* -` [ ] ` - -*Declared by:* - - [https://github.com/cachix/devenv/blob/main/src/modules/integrations/dotenv.nix](https://github.com/cachix/devenv/blob/main/src/modules/integrations/dotenv.nix) - - - ## enterShell Bash code to execute when entering the shell. @@ -1908,6 +1889,8 @@ to adjust the settings or add more extensions. You can find the extensions using `devenv search 'php extensions'` + + *Type:* package @@ -1939,8 +1922,6 @@ pkgs.php.buildEnv { Attribute set of packages including composer - - *Type:* submodule @@ -4744,6 +4725,8 @@ boolean ## pre-commit.settings.deadnix.noLambdaPatternNames + + Don’t check lambda pattern names (don’t break nixpkgs ` callPackage `). @@ -4763,8 +4746,6 @@ boolean ## pre-commit.settings.deadnix.noUnderscore - - Don’t check any bindings that start with a ` _ `. @@ -7042,6 +7023,8 @@ attribute set of attribute set of (INI atom (null, bool, int, float or string)) ## services.couchdb.settings.chttpd.bind_address + + Defines the IP address by which CouchDB will be accessible. @@ -7061,8 +7044,6 @@ string ## services.couchdb.settings.chttpd.port - - Defined the port number to listen. From a13d46c4308561e2d6f8e79f81f5c30da4585d2c Mon Sep 17 00:00:00 2001 From: sidux Date: Thu, 23 Nov 2023 10:50:34 +0100 Subject: [PATCH 08/13] fix dotenv test --- examples/dotenv/.env | 1 + examples/dotenv/.test.sh | 3 +- src/devenv.lock | 156 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 src/devenv.lock diff --git a/examples/dotenv/.env b/examples/dotenv/.env index a2227e944..118be34b6 100644 --- a/examples/dotenv/.env +++ b/examples/dotenv/.env @@ -1,2 +1,3 @@ FOO=1 BAR=2 +BAZ=3 diff --git a/examples/dotenv/.test.sh b/examples/dotenv/.test.sh index 3ce26435d..ffb0dbcba 100755 --- a/examples/dotenv/.test.sh +++ b/examples/dotenv/.test.sh @@ -1,2 +1,3 @@ env | grep FOO=1 -env | grep BAR=3 +env | grep BAR=1 +env | grep BAZ=5 diff --git a/src/devenv.lock b/src/devenv.lock new file mode 100644 index 000000000..539368261 --- /dev/null +++ b/src/devenv.lock @@ -0,0 +1,156 @@ +{ + "nodes": { + "devenv": { + "locked": { + "dir": "src/modules", + "lastModified": 1700691772, + "narHash": "sha256-LidI1PVpxL5/WchIRfMszzsiA5t40QyJiU8V/vd4ZZE=", + "owner": "cachix", + "repo": "devenv", + "rev": "38302f4b9ff45915151848b719c5c4127946c1b8", + "type": "github" + }, + "original": { + "dir": "src/modules", + "owner": "cachix", + "repo": "devenv", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1685518550, + "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1660459072, + "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1700538105, + "narHash": "sha256-uZhOCmwv8VupEmPZm3erbr9XXmyg7K67Ul3+Rx2XMe0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "51a01a7e5515b469886c120e38db325c96694c2f", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1685801374, + "narHash": "sha256-otaSUoFEMM+LjBI1XL/xGB5ao6IwnZOXc47qhIgJe8U=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c37ca420157f4abc31e26f436c1145f8951ff373", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "gitignore": "gitignore", + "nixpkgs": [ + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1700064067, + "narHash": "sha256-1ZWNDzhu8UlVCK7+DUN9dVQfiHX1bv6OQP9VxstY/gs=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "e558068cba67b23b4fbc5537173dbb43748a17e8", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "devenv": "devenv", + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} From 9926ec8bb60482e09138025509ff7999a85150de Mon Sep 17 00:00:00 2001 From: sidux Date: Thu, 23 Nov 2023 10:51:31 +0100 Subject: [PATCH 09/13] remove lock file --- src/devenv.lock | 156 ------------------------------------------------ 1 file changed, 156 deletions(-) delete mode 100644 src/devenv.lock diff --git a/src/devenv.lock b/src/devenv.lock deleted file mode 100644 index 539368261..000000000 --- a/src/devenv.lock +++ /dev/null @@ -1,156 +0,0 @@ -{ - "nodes": { - "devenv": { - "locked": { - "dir": "src/modules", - "lastModified": 1700691772, - "narHash": "sha256-LidI1PVpxL5/WchIRfMszzsiA5t40QyJiU8V/vd4ZZE=", - "owner": "cachix", - "repo": "devenv", - "rev": "38302f4b9ff45915151848b719c5c4127946c1b8", - "type": "github" - }, - "original": { - "dir": "src/modules", - "owner": "cachix", - "repo": "devenv", - "type": "github" - } - }, - "flake-compat": { - "flake": false, - "locked": { - "lastModified": 1673956053, - "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", - "owner": "edolstra", - "repo": "flake-compat", - "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", - "type": "github" - }, - "original": { - "owner": "edolstra", - "repo": "flake-compat", - "type": "github" - } - }, - "flake-utils": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1685518550, - "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "gitignore": { - "inputs": { - "nixpkgs": [ - "pre-commit-hooks", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1660459072, - "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", - "owner": "hercules-ci", - "repo": "gitignore.nix", - "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "gitignore.nix", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1700538105, - "narHash": "sha256-uZhOCmwv8VupEmPZm3erbr9XXmyg7K67Ul3+Rx2XMe0=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "51a01a7e5515b469886c120e38db325c96694c2f", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs-stable": { - "locked": { - "lastModified": 1685801374, - "narHash": "sha256-otaSUoFEMM+LjBI1XL/xGB5ao6IwnZOXc47qhIgJe8U=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "c37ca420157f4abc31e26f436c1145f8951ff373", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixos-23.05", - "repo": "nixpkgs", - "type": "github" - } - }, - "pre-commit-hooks": { - "inputs": { - "flake-compat": "flake-compat", - "flake-utils": "flake-utils", - "gitignore": "gitignore", - "nixpkgs": [ - "nixpkgs" - ], - "nixpkgs-stable": "nixpkgs-stable" - }, - "locked": { - "lastModified": 1700064067, - "narHash": "sha256-1ZWNDzhu8UlVCK7+DUN9dVQfiHX1bv6OQP9VxstY/gs=", - "owner": "cachix", - "repo": "pre-commit-hooks.nix", - "rev": "e558068cba67b23b4fbc5537173dbb43748a17e8", - "type": "github" - }, - "original": { - "owner": "cachix", - "repo": "pre-commit-hooks.nix", - "type": "github" - } - }, - "root": { - "inputs": { - "devenv": "devenv", - "nixpkgs": "nixpkgs", - "pre-commit-hooks": "pre-commit-hooks" - } - }, - "systems": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - } - }, - "root": "root", - "version": 7 -} From 9790569bbacf0b52a9ef0d72c857da0b4c4c3a39 Mon Sep 17 00:00:00 2001 From: sidux Date: Thu, 23 Nov 2023 12:26:11 +0100 Subject: [PATCH 10/13] print message for now found files --- src/modules/integrations/dotenv.nix | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/modules/integrations/dotenv.nix b/src/modules/integrations/dotenv.nix index a2a78ed66..7142e277a 100644 --- a/src/modules/integrations/dotenv.nix +++ b/src/modules/integrations/dotenv.nix @@ -19,6 +19,19 @@ let parseEnvFile = content: builtins.listToAttrs (lib.filter (x: !builtins.isNull x) (map parseLine (lib.splitString "\n" content))); mergeEnvFiles = files: lib.foldl' (acc: file: lib.recursiveUpdate acc (if lib.pathExists file then parseEnvFile (builtins.readFile file) else { })) { } files; + + createMissingFileMessage = file: + let + exampleExists = builtins.pathExists (file + ".example"); + in + lib.optionalString (!lib.pathExists file) '' + echo "💡 The dotenv file '${file}' was not found." + ${lib.optionalString exampleExists '' + echo " To create this file, you can copy the example file:" + echo " $ cp ${file}.example ${file}" + ''} + ''; + in { options.dotenv = { @@ -47,6 +60,9 @@ in env = lib.mapAttrs (name: value: lib.mkDefault value) config.dotenv.resolved; dotenv.resolved = mergeEnvFiles dotenvPaths; }) + (lib.mkIf (cfg.enable) { + enterShell = lib.concatStringsSep "\n" (map createMissingFileMessage dotenvPaths); + }) (lib.mkIf (!cfg.enable && !cfg.disableHint) { enterShell = let From 526703418c416f10da13fdbb8a1b5d37c1810e3b Mon Sep 17 00:00:00 2001 From: sidux Date: Thu, 23 Nov 2023 12:34:34 +0100 Subject: [PATCH 11/13] fix dotenv example --- examples/dotenv/bar.env | 1 + examples/dotenv/devenv.nix | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 examples/dotenv/bar.env diff --git a/examples/dotenv/bar.env b/examples/dotenv/bar.env new file mode 100644 index 000000000..7dec7853a --- /dev/null +++ b/examples/dotenv/bar.env @@ -0,0 +1 @@ +BAZ=5 diff --git a/examples/dotenv/devenv.nix b/examples/dotenv/devenv.nix index 05cc64e38..29a801e9d 100644 --- a/examples/dotenv/devenv.nix +++ b/examples/dotenv/devenv.nix @@ -1,6 +1,6 @@ { pkgs, ... }: { dotenv.enable = true; - dotenv.filename = [ ".env" ".env.bar" ]; + dotenv.filename = [ ".env" "bar.env" ]; env.BAR = "1"; } From e716471050be8fc55e193dcf92d82d4587bc38a9 Mon Sep 17 00:00:00 2001 From: sidux Date: Fri, 8 Dec 2023 15:24:45 +0100 Subject: [PATCH 12/13] de-bump latest-version --- src/modules/latest-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/latest-version b/src/modules/latest-version index d2b13eb64..844f6a91a 100644 --- a/src/modules/latest-version +++ b/src/modules/latest-version @@ -1 +1 @@ -0.6.4 +0.6.3 From 5ad1498d926a229af1a9f5c0575c0135cae33c22 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 8 Dec 2023 14:29:58 +0000 Subject: [PATCH 13/13] Auto generate docs/reference/options.md --- docs/reference/options.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/options.md b/docs/reference/options.md index 86d793ab6..02b3e061d 100644 --- a/docs/reference/options.md +++ b/docs/reference/options.md @@ -449,7 +449,7 @@ string *Default:* -` "0.6.4" ` +` "0.6.3" ` *Declared by:* - [https://github.com/cachix/devenv/blob/main/src/modules/update-check.nix](https://github.com/cachix/devenv/blob/main/src/modules/update-check.nix)