From cc0944a60978ad7cf74d429d18c2a8065f018545 Mon Sep 17 00:00:00 2001 From: "Yang, Bo" Date: Mon, 8 Apr 2024 08:15:18 +0000 Subject: [PATCH 1/2] Avoid --impure in flake-parts based projects --- templates/flake-parts/.envrc | 3 ++- templates/flake-parts/flake.nix | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) 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 = [ From 38aa2441c6943f96eb6b1a1a93a5776bd679e192 Mon Sep 17 00:00:00 2001 From: "Yang, Bo" Date: Mon, 8 Apr 2024 08:15:18 +0000 Subject: [PATCH 2/2] Remove --impure from tests --- devenv.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/devenv.nix b/devenv.nix index cf0c8d6fb..d13109b19 100644 --- a/devenv.nix +++ b/devenv.nix @@ -78,13 +78,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"