Skip to content
This repository has been archived by the owner on Jun 8, 2024. It is now read-only.

Usage with nix #90

Open
DieracDelta opened this issue Sep 9, 2023 · 15 comments
Open

Usage with nix #90

DieracDelta opened this issue Sep 9, 2023 · 15 comments

Comments

@DieracDelta
Copy link

DieracDelta commented Sep 9, 2023

I added pre-commit to my package list, and pre-commit install && pre-commit autoupdate to my nix-shell shellHook. I created a default config (typstfmt --make-default-config), then echoed into the pre-commit config per the readme. When I commit, I get the following error:

[WARNING] Unstaged files detected.
[INFO] Stashing unstaged files to /home/jrestivo/.cache/pre-commit/patch1694283539-3337861.
[INFO] Installing environment for https://github.com/astrale-sharp/typstfmt.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Restored changes from /home/jrestivo/.cache/pre-commit/patch1694283539-3337861.
An unexpected error has occurred: CalledProcessError: command: ('/nix/store/hrpvwkjz04s9i4nmli843hyw9z4pwhww-bash-4.4-p23/bin/bash', '-e', '/home/jrestivo/.nix-profile/bin/cargo', 'install', '--bins', '--root', '/home/jrestivo/.cache/pre-commit/repodr4sbjo2/rustenv-system', '--path', '.')
return code: 101
stdout: (none)
stderr:
    error: failed to parse manifest at `/home/jrestivo/.cache/pre-commit/repodr4sbjo2/Cargo.toml`

    Caused by:
      invalid type: map, expected a sequence for key `package.authors`
Check the log at /home/jrestivo/.cache/pre-commit/pre-commit.log

I'm not sure what to make of this. Advice would be appreciated!

Note: I am on NixOS.

@PgBiel
Copy link

PgBiel commented Sep 9, 2023

The problem here seems to be related to Cargo, not to Nix. It seems a command is being used which does not support workspaces, or is not expecting a workspace, but rather a regular, single crate. This is especially true for the current setup, which includes a top-level Cargo.toml with specs for both the binary crate and the workspace itself.

A possible solution would be for @astrale-sharp to add a separate Cargo.toml for just the binary crate. Perhaps moving both the binary and library crates into a single crates directory - as Typst did in typst/typst@ebfdb1d - would be ideal, and then you'd be able to point cargo install to just the binary crate's folder under crates.

@astrale-sharp
Copy link
Owner

Hey there! Can I get reproducable steps to investigate? I can't exactly pinpoint what's happening yet

@astrale-sharp
Copy link
Owner

Thanks for your report btw !

@astrale-sharp
Copy link
Owner

Using the same steps I end up with something working so I don't know what the problem is.

Do you have other pre-commit installed?
I used pre-commit 2.17.0, what about you?

@DieracDelta
Copy link
Author

DieracDelta commented Sep 10, 2023

Ah, that might be it. I'm pulling pre-commit from nixpkgs which has it on version 3.3.3. I can confirm I only have one version of it on my PATH.

@DieracDelta
Copy link
Author

DieracDelta commented Sep 10, 2023

I added you to a private repo that I'm using for note-taking. To reproduce, git clone [email protected]:DieracDelta/typst_notes.git && git submodule init && git submodule update && nix develop. Then make a change and try to commit. NOTE: if you rather, I can also strip that repo down to a minimal reproducible example and publick it. I'm just being lazy since this is a bit easier. There's really not much in there.

@astrale-sharp
Copy link
Owner

nix develop fails

❯ nix develop
error: experimental Nix feature 'nix-command' is disabled; use '--extra-experimental-features nix-command' to override

@astrale-sharp
Copy link
Owner

nix (Nix) 2.6.0

@DieracDelta
Copy link
Author

Try: nix develop --extra-experimental-features nix-commands --extra-experimental-features flakes to get into a nix shell

@DieracDelta
Copy link
Author

What architecture are you on? If you're on a arm mbp, you may need to run nix develop --extra-experimental-features nix-commands --extra-experimental-features flakes .#devShells.aarch64-darwin.default

@astrale-sharp
Copy link
Owner

x86_64 !

@astrale-sharp
Copy link
Owner

using your new command I get

error: experimental Nix feature 'nix-command' is disabled; use '--extra-experimental-features nix-command' to override

even tho extra-experimental-features nix-command is in the command 🤔

@DieracDelta
Copy link
Author

Oops I think I typoed and put nix-commands instead of nix-command. So something like nix develop --extra-experimental-features nix-command --extra-experimental-features flakes .#devShells.x86_64-linux.default might work?

@PgBiel
Copy link

PgBiel commented Sep 11, 2023

In order to not require the --extra-experimental-features flags all the time, you can also write to your user's local Nix settings:

mkdir -p ~/.config/nix
echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf

Source: NixOS wiki

@astrale-sharp
Copy link
Owner

I don't have considerable time for this atm, if someone else is ready to investigate what's happening there that would be nice

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants