cachix / devenv

Fast, Declarative, Reproducible, and Composable Developer Environments
https://devenv.sh
Apache License 2.0
3.56k stars 259 forks source link

"path '/devenv.nix' does not exist in Git repository" when ignored by git #1078

Closed hqm42 closed 1 month ago

hqm42 commented 1 month ago

Describe the bug After upgrading to from < 1 to 1.0.2 I started getting the error path '/devenv.nix' does not exist in Git repository

Context As I work in a constrained environment, I can not add any devenv related files into our git repositories. I am using an envelope project that syncs the devenv config files into the respective project directories:

> tree envelope
envelope
├── devenv
│   ├── repo-1
│   │   ├── devenv.nix
│   │   └── devenv.yaml
│   └── repo-2
│       ├── devenv.nix
│       └── devenv.yaml
├── repo-1
│   └── ...
├── repo-2
    └── ...

The devenv specific files are ignored by git not using the normal .gitignore but instead using the repo local .git/info/exclude file:

> cat repo-1/.git/info/exclude
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
.devenv*
devenv.local.nix
.direnv
.pre-commit-config.yaml
devenv.nix
devenv.lock
devenv.yaml
.envrc

To reproduce

mkdir devenv-test
cd devenv-test
git init
devenv init
echo devenv.nix >> .gitignore
direnv reload
...
error:
error: path '/devenv.nix' does not exist in Git repository '/home/xxx/devenv-test'

Version devenv 1.0.2 (x86_64-darwin)

hqm42 commented 1 month ago

For now it would be enough for me to be able to downgrade to an older devenv version, but I did not find a simple way to do that.

Edit: I downgraded to 0.6.3 using nix-env -if https://github.com/cachix/devenv/tarball/v0.6.3

domenkozar commented 1 month ago

Hmmm, I'll look into this.

zevisert commented 1 month ago

I'm also seeing this, as I also frequently use devenv to work on customer, internal, and oss repositories that don't track devenv files. My ignore solution is a bit simpler though; it's just a global gitignorefile tracked by my dotfiles that I can include via git config in the repositories that I need

> # if a repo isn't using devenv, just tell git to ignore its files
> git config --local --set core.excludesfile ~/.devenv.gitignore
# file: ~/.devenv.gitignore
# Devenv
.devenv*
devenv.local.nix

# direnv
.direnv

.envrc
devenv.lock
devenv.nix
devenv.yaml
mrbrownt commented 4 weeks ago

@domenkozar this is still occurring in 1.0.4 image

domenkozar commented 2 weeks ago

I tested recently released 1.0.5 and it fixes the issue, please someone confirm using https://github.com/cachix/devenv/releases/tag/v1.0.5

On Sat, Apr 20, 2024 at 8:24 PM Todd Brown @.***> wrote:

@domenkozar https://github.com/domenkozar this is still occurring in 1.0.4 image.png (view on web) https://github.com/cachix/devenv/assets/18373623/d123d8a0-c76e-4ce8-86ab-b1ebd18846bb

— Reply to this email directly, view it on GitHub https://github.com/cachix/devenv/issues/1078#issuecomment-2067761619, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA63A3ONIUYI6RWTSGC7LDY6K6GNAVCNFSM6AAAAABFML7MZOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANRXG43DCNRRHE . You are receiving this because you were mentioned.Message ID: @.***>

zevisert commented 2 weeks ago

It seems like 1.0.5 does allow devenv.* files to be unversioned, but I'm still seeing this error with custom nix modules I importing.

For instance, I have a python project that needs a more recent version of poetry than what is on the 23.11 channel (as well as requiring some plugins not on nixpkgs at all). I could be overlooking an easier way to fix this, since I'm only a few months into using nix, but I just have a .nix-custom/poetry/default.nix 1,2 in the repository I'm using devenv with, and I'm doing the following in my devenv.nix:

1: (sourced from the nixpkgs repo) 2: (with the whole .nix-custom directory also ignored by git)

{ pkgs, ... }:

let
  poetry-latest = pkgs.callPackage .nix-custom/poetry/default.nix { };
in
{
  ... # other options
  languages.python = {
    enable = true;
    version = "3.11.6";
    poetry = {
      enable = true;
      package = poetry-latest;
      activate.enable = true;
    };
  };
}
...
at /devenv.nix:4:19:
    3| let 
    4|   poetry-latest = pkgs.callPackage .nix-custom/poetry/default.nix { };
     |                   ^
    5| in
at «github:NixOS/nixpkgs/12430e43bd9b81a6b4e79e64f87c624ade701eaf»/lib/customisation.nix:141:35 ...
at «github:NixOS/nixpkgs/12430e43bd9b81a6b4e79e64f87c624ade701eaf»/lib/customisation.nix:154:10 ...
at «github:NixOS/nixpkgs/12430e43bd9b81a6b4e79e64f87c624ade701eaf»/lib/attrsets.nix:381:5 ...
at «github:NixOS/nixpkgs/12430e43bd9b81a6b4e79e64f87c624ade701eaf»/lib/customisation.nix:144:15 ...
at «github:NixOS/nixpkgs/12430e43bd9b81a6b4e79e64f87c624ade701eaf»/lib/trivial.nix:440:18 ...

error: path '/.nix-custom' does not exist in Git repository '/code/[...]/infrastructure-management'

× Command produced the following output:

Error:   × Command `/nix/store/v29lakrmjm66797m9pb1s96pqmz9dkaz-nix-devenv-2.21.0pre20240412_b24a931/bin/nix --show-trace --extra-experimental-features nix-command --extra-experimental-features flakes --option warn-dirty false --option eval-cache false --keep-going --max-jobs 12 print-dev-env --profile /
  │ code/[...]/infrastructure-management/.devenv/gc/shell --option extra-substituters https://nixpkgs-python.cachix.org https://devenv.cachix.org --option extra-trusted-public-keys nixpkgs-python.cachix.org-1:hxjI7pFxTyuTHn2NkvWCrAUcNZLNS3ZAvfYNuYifcEU= devenv.cachix.org-
  │ 1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw=` failed with with exit code 1

> devenv version
devenv 1.0.5 (x86_64-linux)
> # devenv was installed with:
> nix profile install --accept-flake-config 'tarball+https://github.com/cachix/devenv/tarball/v1.0.5'
zevisert commented 2 weeks ago

It's a tricky thing, since obviously I'm circumventing a reproducible environment by having ignored nix modules, but I'm the only one in this repository using nix; so I'm keeping it to myself. I have a solution I posted above, where I just run git config --local --unset core.excludesfile when changing or rebuilding my shell, then setting git config --local core.excludesfile ~/.devenv.gitignore when my shell is ready again. Devenv only seems to need these files to be unignored when building the state, if nothing's changed then having the files ignored again is fine, and they also don't need to be staged or committed in git either.

I can totally understand if devenv chooses to keep this behaviour / wontfix, since the whole idea is to make a reproducible environment - and the problem of users like me importing unversioned modules are totally circumventing that. It would be nice if that was a warning instead of an error though :)

hqm42 commented 2 weeks ago

please someone confirm using https://github.com/cachix/devenv/releases/tag/v1.0.5

This fixed the issue for me. Thanks!