nixfmt icon indicating copy to clipboard operation
nixfmt copied to clipboard

Nixfmt does overwrite symlinks with reformatted contents

Open NobbZ opened this issue 4 years ago • 3 comments

When I have a symlink and pass it to nixfmt (eg because of using globbing from the shell as in nixfmt **/*.nix) it gets overwritten by a regular file containing the formatted target.

nixfmt should either ignore symlinks or write to the symlinks target, rather than overwriting the symlink.

$ readlink -f default.nix
/home/nmelzer/.config/nixpkgs/hosts/vbox-arch.nix
$ nixfmt default.nix
$ readlink -f default.nix
/home/nmelzer/.config/nixpkgs/hosts/default.nix
$ nixfmt --version
Format Nix source code

Sadly it seems as if in my version of nixfmt #50 isn't fixed yet.

NobbZ avatar Feb 12 '20 10:02 NobbZ

Thanks for reporting! I made a PR with a fix that should be merged soon. Unfortunately, our releases go through hackage and that can be kind of slow. If you don't want to wait for those, the README contains instruction for installing nixfmt from master.

Lucus16 avatar Feb 14 '20 00:02 Lucus16

As far as I see, the version fix should already be available in latest release, at least according to the GitHub interface, though it doesn't seem to be in nixpkgs yet.

Though I might consider an installation from source, as in general the process behind updating something in nixpkgs seems to be quite slow.

NobbZ avatar Feb 14 '20 06:02 NobbZ

Is there still someone working on this?

felixscheinost avatar Jun 19 '22 07:06 felixscheinost