Skip to content

Commit

Permalink
Merge pull request #1018 from Atry/no-impure
Browse files Browse the repository at this point in the history
Avoid --impure in flake-parts based projects
  • Loading branch information
domenkozar authored Apr 19, 2024
2 parents 349e28f + 38aa244 commit 255fe24
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions devenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion templates/flake-parts/.envrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 11 additions & 1 deletion templates/flake-parts/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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
Expand All @@ -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 = [
Expand Down

0 comments on commit 255fe24

Please sign in to comment.