Cannot run makes on NixOS systems which configure programs.git #979

Closed
opened 2022-11-19 20:16:24 +01:00 by kraftnix · 12 comments
kraftnix commented 2022-11-19 20:16:24 +01:00 (Migrated from github.com)

Problem

I am unable to run any makes commands in any NixOS system which uses NixOS to configure git (resulting in a read-only ~/.config/git/config file).

Reproduction Steps

  1. Have a read-only ~/.config/git/config or configure NixOS with programs.git.config.*
  2. Run nix run github:fluidattacks/makes -- m github:fluidattacks/makes /helloWorld 1 2 3
error: could not lock config file /home/kraftnix/.config/git/config: Read-only file system

if you remove/move .config/git/config then the command works as expected.

Expected Result

I should be able to run makes on NixOS under a user with a read-only config or NixOS configured config.

I looked through the current documentation and issues and found nothing related to this problem.

## Problem I am unable to run any makes commands in any NixOS system which uses NixOS to configure git (resulting in a read-only `~/.config/git/config` file). ## Reproduction Steps 1. Have a read-only `~/.config/git/config` or configure NixOS with `programs.git.config.*` 2. Run `nix run github:fluidattacks/makes -- m github:fluidattacks/makes /helloWorld 1 2 3` ``` error: could not lock config file /home/kraftnix/.config/git/config: Read-only file system ``` > if you remove/move `.config/git/config` then the command works as expected. ## Expected Result I should be able to run `makes` on NixOS under a user with a read-only `config` or NixOS configured `config`. I looked through the current documentation and issues and found nothing related to this problem.
dsalaza4 commented 2022-11-22 21:44:32 +01:00 (Migrated from github.com)

@kraftnix Thank you so much for this report!

This is most likely related to this change: github.com/fluidattacks/makes@0251c2a195 (diff-2c1c4ba253)

@jpverde Can you please provide more context on the Git issue that forced us to to this and possible workarounds?

Thanks!

@kraftnix Thank you so much for this report! This is most likely related to this change: https://github.com/fluidattacks/makes/commit/0251c2a1959445b5eba0df1c4e6b6c18a66bbd35#diff-2c1c4ba2536c6703404deca94474d191fa0297bc0ede8a6413ca3185d8cbb1fdR233 @jpverde Can you please provide more context on the Git issue that forced us to to this and possible workarounds? Thanks!
dsalaza4 commented 2022-11-22 21:49:16 +01:00 (Migrated from github.com)

@kraftnix By the way, I'm guessing you want to keep your git config read only for reproducibility reasons?

This is how I configure git using NixOS and Home Manager: https://github.com/dsalaza4/env/blob/main/modules/pkgs/git/default.nix

The git config is still writable.

@kraftnix By the way, I'm guessing you want to keep your git config read only for reproducibility reasons? This is how I configure git using NixOS and Home Manager: https://github.com/dsalaza4/env/blob/main/modules/pkgs/git/default.nix The git config is still writable.
kraftnix commented 2022-11-24 18:26:41 +01:00 (Migrated from github.com)

The git config is still writable.

Curious, I am also using home-manager to configure my .git/config, however the resulting config is a symlink to the nix store and is thus not writable.

@jpverde Can you please provide more context on the Git issue that forced us to to this and possible workarounds?

I remember the issue as well from other projects, here is the related nixpkgs issue: https://github.com/NixOS/nixpkgs/issues/169193

@kraftnix By the way, I'm guessing you want to keep your git config read only for reproducibility reasons?

I would prefer to keep it read-only for reproducibility reasons. I also am not a fan of tools reconfiguring my settings globally, so if we could find a solution which keeps the git config changes project local that would be ideal.

> The git config is still writable. Curious, I am also using `home-manager` to configure my `.git/config`, however the resulting config is a symlink to the nix store and is thus not writable. > @jpverde Can you please provide more context on the Git issue that forced us to to this and possible workarounds? I remember the issue as well from other projects, here is the related `nixpkgs` issue: https://github.com/NixOS/nixpkgs/issues/169193 > @kraftnix By the way, I'm guessing you want to keep your git config read only for reproducibility reasons? I would prefer to keep it read-only for reproducibility reasons. I also am not a fan of tools reconfiguring my settings globally, so if we could find a solution which keeps the git config changes project local that would be ideal.
dsalaza4 commented 2022-11-24 19:55:08 +01:00 (Migrated from github.com)

Curious, I am also using home-manager to configure my .git/config, however the resulting config is a symlink to the nix store and is thus not writable.

  1. I can confirm that my global git config is read only too.
  2. For some reason, when running makes with nix run github:fluidattacks/makes -- github:fluidattacks/makes@main /helloWorld 1 2 3, it works properly for me.
  3. If I run the git command that _add_safe_directory has, I get the error you reported:
    $ git config --global --add safe.directory /github/workspace
    error: could not lock config file /home/nixos/.config/git/config: Read-only file system
    
  4. I think this means that the Makes CLI is not executing the _add_safe_directory function for me. 🤔
  5. These are the conditions for calling _add_safe_directory: github.com/fluidattacks/makes@d24478d1e4/src/cli/main/cli.py (L122) I think I should be reaching the function here: github.com/fluidattacks/makes@d24478d1e4/src/cli/main/cli.py (L130) but for some reason i don't?

@jpverde

> Curious, I am also using home-manager to configure my .git/config, however the resulting config is a symlink to the nix store and is thus not writable. 1. I can confirm that my global git config is read only too. 2. For some reason, when running makes with `nix run github:fluidattacks/makes -- github:fluidattacks/makes@main /helloWorld 1 2 3`, it works properly for me. 3. If I run the git command that `_add_safe_directory` has, I get the error you reported: ``` $ git config --global --add safe.directory /github/workspace error: could not lock config file /home/nixos/.config/git/config: Read-only file system ``` 5. I think this means that the Makes CLI is not executing the `_add_safe_directory` function for me. 🤔 6. These are the conditions for calling `_add_safe_directory`: https://github.com/fluidattacks/makes/blob/d24478d1e41eb23d82ed4aad4a6a096d6cbbdb75/src/cli/main/cli.py#L122 I think I should be reaching the function here: https://github.com/fluidattacks/makes/blob/d24478d1e41eb23d82ed4aad4a6a096d6cbbdb75/src/cli/main/cli.py#L130 but for some reason i don't? @jpverde
dsalaza4 commented 2023-06-13 21:49:25 +02:00 (Migrated from github.com)

@kraftnix Hey!

Were you able to find a solution for this?

@kraftnix Hey! Were you able to find a solution for this?
kraftnix commented 2023-06-26 00:52:26 +02:00 (Migrated from github.com)

Unfortunately I never did seem to find a decent solution.

It appears I worked around it by setting git config options from within a script that needed to use git / whenever I ran into this issue.

Something like:

makeScript {
  ...
  entrypoint = ''
    require_env_var GIT_USER
    require_env_var GIT_EMAIL
   
    ...

    git config user.name $GIT_USER
    git config user.email $GIT_EMAIL
  '';
}

This is definitely a bad workaround but it's been working in my CI since so I haven't come back to this issue.

Unfortunately I never did seem to find a decent solution. It appears I worked around it by setting `git config` options from within a script that needed to use git / whenever I ran into this issue. Something like: ```nix makeScript { ... entrypoint = '' require_env_var GIT_USER require_env_var GIT_EMAIL ... git config user.name $GIT_USER git config user.email $GIT_EMAIL ''; } ``` This is definitely a bad workaround but it's been working in my CI since so I haven't come back to this issue.
dsalaza4 commented 2023-06-27 01:34:30 +02:00 (Migrated from github.com)

@kraftnix Oh wait a moment, this looks like a different problem!

makeScript does not inherit the $HOME envar used by git to get its global configs.

If you want to use your global git configurations from a makeScript context, you can use the $HOME_IMPURE envar like this:

HOME="${HOME_IMPURE}" git ...

@kraftnix Oh wait a moment, this looks like a different problem! `makeScript` does not inherit the `$HOME` envar used by git to get its global configs. If you want to use your global git configurations from a `makeScript` context, you can use the `$HOME_IMPURE` envar like this: `HOME="${HOME_IMPURE}" git ...`
kraftnix commented 2023-07-18 13:54:18 +02:00 (Migrated from github.com)

In the above script it is a different problem indeed. But nix run github:fluidattacks/makes -- m github:fluidattacks/makes /helloWorld 1 2 3 still fails with the same error as before if I configured my global git config with home-manager or NixOS.

In the above script it is a different problem indeed. But `nix run github:fluidattacks/makes -- m github:fluidattacks/makes /helloWorld 1 2 3` still fails with the same error as before if I configured my global git config with home-manager or NixOS.
pjjw commented 2023-07-27 05:43:13 +02:00 (Migrated from github.com)

yeah, just tacking on on this one, editing users' global config leaves a pretty terrible taste in the mouth of the evaluator. took me a while to even figure out what was going on here.

yeah, just tacking on on this one, editing users' global config leaves a pretty terrible taste in the mouth of the evaluator. took me a while to even figure out what was going on here.
pjjw commented 2023-07-27 05:48:08 +02:00 (Migrated from github.com)

my guess here is that there's something a bit broken about your "using stable nix" checks. i'm executing it from flakes (nix run -- github:fluidattacks/makes github:fluidattacks/makes) and it's trying to run that global config edit, which it shouldn't need to do.

my guess here is that there's something a bit broken about your "using stable nix" checks. i'm executing it from flakes (`nix run -- github:fluidattacks/makes github:fluidattacks/makes`) and it's trying to run that global config edit, which it shouldn't need to do.
dsalaza4 commented 2023-09-22 23:30:39 +02:00 (Migrated from github.com)

Hi everyone!

A fix for this has been merged: https://github.com/fluidattacks/makes/pull/1165/files

Make sure you update to the latest version.

Let me know if things work for you now.

Hi everyone! A fix for this has been merged: https://github.com/fluidattacks/makes/pull/1165/files Make sure you update to the latest version. Let me know if things work for you now.
kraftnix commented 2023-11-26 01:51:12 +01:00 (Migrated from github.com)

I had another look at the issue.

The main branch seems to resolve the git config issues, as initially reported

nix run github:fluidattacks/makes -- github:fluidattacks/makes@main /helloWorld 1 2 3

Happy to close the issue now.

I had another look at the issue. The `main` branch seems to resolve the git config issues, as initially reported ```sh nix run github:fluidattacks/makes -- github:fluidattacks/makes@main /helloWorld 1 2 3 ``` Happy to close the issue now.
This discussion has been locked. Commenting is limited to contributors.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
justin/makes#979
No description provided.