Skip to content

Commit 255fe24

Browse files
authored
Merge pull request #1018 from Atry/no-impure
Avoid --impure in flake-parts based projects
2 parents 349e28f + 38aa244 commit 255fe24

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

devenv.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@
8181
nix flake init --template ''${DEVENV_ROOT}#flake-parts
8282
nix flake update \
8383
--override-input devenv ''${DEVENV_ROOT}
84-
nix develop --accept-flake-config --impure --command echo nix-develop started succesfully |& tee ./console
84+
nix develop --accept-flake-config --override-input devenv-root "file+file://"<(printf %s "$PWD") --command echo nix-develop started succesfully |& tee ./console
8585
grep -F 'nix-develop started succesfully' <./console
8686
grep -F "$(${lib.getExe pkgs.hello})" <./console
8787
# Test that a container can be built
8888
if $(uname) == "Linux"
8989
then
90-
nix build --impure --accept-flake-config --show-trace .#container-processes
90+
nix build --override-input devenv-root "file+file://"<(printf %s "$PWD") --accept-flake-config --show-trace .#container-processes
9191
fi
9292
popd
9393
rm -rf "$tmp"

templates/flake-parts/.envrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ fi
55
nix_direnv_watch_file devenv.nix
66
nix_direnv_watch_file devenv.lock
77
nix_direnv_watch_file devenv.yaml
8-
if ! use flake . --impure
8+
9+
if ! use flake . --override-input devenv-root "file+file://"<(printf %s "$PWD")
910
then
1011
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
1112
fi

templates/flake-parts/flake.nix

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
description = "Description for the project";
33

44
inputs = {
5+
devenv-root = {
6+
url = "file+file:///dev/null";
7+
flake = false;
8+
};
59
nixpkgs.url = "github:cachix/devenv-nixpkgs/rolling";
610
devenv.url = "github:cachix/devenv";
711
nix2container.url = "github:nlewo/nix2container";
@@ -14,7 +18,7 @@
1418
extra-substituters = "https://devenv.cachix.org";
1519
};
1620

17-
outputs = inputs@{ flake-parts, ... }:
21+
outputs = inputs@{ flake-parts, devenv-root, ... }:
1822
flake-parts.lib.mkFlake { inherit inputs; } {
1923
imports = [
2024
inputs.devenv.flakeModule
@@ -33,6 +37,12 @@
3337
packages.default = pkgs.hello;
3438

3539
devenv.shells.default = {
40+
devenv.root =
41+
let
42+
devenvRootFileContent = builtins.readFile devenv-root.outPath;
43+
in
44+
pkgs.lib.mkIf (devenvRootFileContent != "") devenvRootFileContent;
45+
3646
name = "my-project";
3747

3848
imports = [

0 commit comments

Comments
 (0)