Skip to content

Commit

Permalink
Avoid --impure in flake-parts based projects
Browse files Browse the repository at this point in the history
  • Loading branch information
Atry committed Mar 20, 2024
1 parent cbd16d2 commit 5efce28
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
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
nixpkgs.lib.mkIf (devenvRootFileContent != "") devenvRootFileContent;

name = "my-project";

imports = [
Expand Down

0 comments on commit 5efce28

Please sign in to comment.