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

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

Closed
hqm42 opened this issue Mar 28, 2024 · 8 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@hqm42
Copy link

hqm42 commented Mar 28, 2024

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 hqm42 added the bug Something isn't working label Mar 28, 2024
@hqm42
Copy link
Author

hqm42 commented Mar 28, 2024

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
Copy link
Member

Hmmm, I'll look into this.

@domenkozar domenkozar self-assigned this Apr 1, 2024
@zevisert
Copy link

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
Copy link

@domenkozar this is still occurring in 1.0.4
image

@domenkozar
Copy link
Member

domenkozar commented Apr 29, 2024 via email

@zevisert
Copy link

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
Copy link

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
Copy link
Author

hqm42 commented May 2, 2024

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

This fixed the issue for me. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants