Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid --impure in flake-parts based projects #1018

Merged
merged 2 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions devenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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"
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
Loading