diff --git a/devenv.nix b/devenv.nix index 348989c12..e13daa4eb 100644 --- a/devenv.nix +++ b/devenv.nix @@ -81,13 +81,13 @@ nix flake init --template ''${DEVENV_ROOT}#flake-parts nix flake update \ --override-input devenv ''${DEVENV_ROOT} - nix develop --accept-flake-config --impure --command echo nix-develop started succesfully |& tee ./console + nix develop --accept-flake-config --override-input devenv-root "file+file://"<(printf %s "$PWD") --command echo nix-develop started succesfully |& tee ./console grep -F 'nix-develop started succesfully' <./console grep -F "$(${lib.getExe pkgs.hello})" <./console # Test that a container can be built if $(uname) == "Linux" then - nix build --impure --accept-flake-config --show-trace .#container-processes + nix build --override-input devenv-root "file+file://"<(printf %s "$PWD") --accept-flake-config --show-trace .#container-processes fi popd rm -rf "$tmp" diff --git a/templates/flake-parts/.envrc b/templates/flake-parts/.envrc index b351dff3d..9a651c991 100644 --- a/templates/flake-parts/.envrc +++ b/templates/flake-parts/.envrc @@ -5,7 +5,8 @@ fi nix_direnv_watch_file devenv.nix nix_direnv_watch_file devenv.lock nix_direnv_watch_file devenv.yaml -if ! use flake . --impure + +if ! use flake . --override-input devenv-root "file+file://"<(printf %s "$PWD") then echo "devenv could not be built. The devenv environment was not loaded. Make the necessary changes to devenv.nix and hit enter to try again." >&2 fi diff --git a/templates/flake-parts/flake.nix b/templates/flake-parts/flake.nix index 115c28de4..05dcb6749 100644 --- a/templates/flake-parts/flake.nix +++ b/templates/flake-parts/flake.nix @@ -2,6 +2,10 @@ description = "Description for the project"; inputs = { + devenv-root = { + url = "file+file:///dev/null"; + flake = false; + }; nixpkgs.url = "github:cachix/devenv-nixpkgs/rolling"; devenv.url = "github:cachix/devenv"; nix2container.url = "github:nlewo/nix2container"; @@ -14,7 +18,7 @@ extra-substituters = "https://devenv.cachix.org"; }; - outputs = inputs@{ flake-parts, ... }: + outputs = inputs@{ flake-parts, devenv-root, ... }: flake-parts.lib.mkFlake { inherit inputs; } { imports = [ inputs.devenv.flakeModule @@ -33,6 +37,12 @@ packages.default = pkgs.hello; devenv.shells.default = { + devenv.root = + let + devenvRootFileContent = builtins.readFile devenv-root.outPath; + in + pkgs.lib.mkIf (devenvRootFileContent != "") devenvRootFileContent; + name = "my-project"; imports = [