How do I create a symlink for a file from a package

I’m having trouble installing zsh-syntax-highlighting , it does create a directory in /nix/store ( /nix/store/mgrkz162lqp7dcrgj9w3l8hx0n5hld2d-zsh-syntax-highlighting-0.7.1 ), but as far as I can tell, the crucial file zsh-syntax-highlighting.zsh is not actually linked anywhere.

I tried to look for it in the .nix files for the package, but unfortunately my knowledge of nix is too limited to understand what’s happening there.

I have two questions:

  • Is there any way I can find out if nix has created any symlinks for a particular package?
  • How can I manually tell nix to link a file from an existing package

I’m having similar problems with other packages as well, so this isn’t just about zsh-syntax-highlighting.

What was the “it” that created something in the store?

Personally I use Home-Manager to deal with my ZSH plugins, and nixos-config/default.nix at 98f43756c55406c93270e885ef94d1bb583c22ec · NobbZ/nixos-config · GitHub works for me.

In nixos it seems as if there is an option for the highlighting.

What was the “it” that created something in the store?

The package called zsh-syntax-highlighting, it’s directory in the nix store contains all the files I would expect, they just don’t seem to be symlinked to anywhere.

I want to keep using my existing config and have it be compatible with other distros. (At least for now)

As far as I understand it, for options like the ones you mentioned to actually work, you need to let nix manage the config file.

All I want is the file, currently located in /nix/store/mgrkz162lqp7dcrgj9w3l8hx0n5hld2d-zsh-syntax-highlighting-0.7.1/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh to be symlinked to either a custom path like ~/.locah/share, or to somewhere on my path.

Also, as I mentioned, I have this problem with other packages as well which currently aren’t supported by home manger, so it would be really great to have a generic solution for this.

Yeah, nix only ever creates things in the store, linking happens by auxiliary tools which appear to be nix, though actually are just shallow wrappers.

What I mean is, did you edit some file? If yes, which? Did you ran any commands? Which?

Nix does not manage your configuration, auxiliary tools do.

This is deemed to fail. Either use HM on the other distros or maintain seperate repositories.

I have decided to do the latter for the company owned mac I have to use at work, as the nix experience there was sub par.

Linking it "somewhere in PATH" doesn’t gain you anything. You need to source /nix/store/mgrkz162lqp7dcrgj9w3l8hx0n5hld2d-zsh-syntax-highlighting-0.7.1/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh or something that links to it.

And the link has to get updated everytime you rebuild the system. This again is one of the reasons why I asked how you built/installed in the first place, as further steps depend on this.

Yeah, nix only ever creates things in the store, linking happens by auxiliary tools which appear to be nix, though actually are just shallow wrappers.

I don’t have much experience with nix and honestly the terminology is a bit confusing, I was refering to something provided by nixos, not the nix package manager itself.

What I mean is, did you edit some file? If yes, which? Did you ran any commands? Which?

I added the package to environment.systemPackages, I think that’s what you mean. The command I use to build my config is sudo nixos-rebuild switch --flake .#.

Nix does not manage your configuration, auxiliary tools do.

I still think the dotfiles have to be managed by those tools in order to work, at least it didn’t have any effect when I tried it using home manager.

This is deemed to fail. Either use HM on the other distros or maintain seperate repositories.

If that was true I’d probably give up nixos tbh, but I’ve seen plenty of people talk about using your existing dots and I don’t see why this couldn’t work. (Almost all of my config works already, this is one of the few remaining problems)

Linking it "somewhere in PATH " doesn’t gain you anything.

Shouldn’t I be able to source it if it’s on my path? It’s my understanding that the shell would resolve the symlink.

And the link has to get updated everytime you rebuild the system.

Which is why I want to add this as part of my nix config, from what I’ve read on them, (which is not much) overlays or flakes seem like they might work, but since I’m very new to nix I don’t know how to use them properly.

This again is one of the reasons why I asked how you built/installed in the first place, as further steps depend on this.

As I said above, from the offical nixpkgs. (unstable channel)

Then the content of the package you added should be linked within the system mountpoint /run/current-system/sw, mixed with all the other stuff.

Resulting in /run/current-system/sw/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh being the link to source.

You are probably confusing PATH which is used to find executables and zshs FPATH which is used to discover functions for autoloading, though that would not help us here either, as we need to source a scpecial file.

For home dotfiles it might indeed work, though might require some extra effort within the dots to adjust some base paths to load scripts from, or manual effort to maintain links between the locations your scripts expect and the locations used in nixos.

This are just 2 random concepts which can be used individually or together with your system configuration. Not really anything meaningful in this context though.

:+1:

Then the content of the package you added should be linked within the system mountpoint /run/current-system/sw , mixed with all the other stuff.
Resulting in /run/current-system/sw/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh being the link to source.

This sounds like exactly what I need, unfortunately, that file doesn’t exist.

I’m really not sure what could be causing this, especially since /run/current-system/sw/share/doc/zsh-syntax-highlighting does exist. (The .zsh file is not in there)

I’ve tried installing from stable, unstable, with and without the programs.zsh.syntaxHighlighting.enable option, so I’m kind of lost as to what else to try.

Edit:

This are just 2 random concepts which can be used individually or together with your system configuration. Not really anything meaningful in this context though.

I thought I might be able to overwrite the output for the package using an overlay or manually install the plugin without the official package using a flake.

That option will only work, if you generally allow nixos to manage your config (programs.zsh.enable = true) and depending on how you currently have your user config set up you might also need to source the generated configuration manually.

For me it does.

diff --git a/nixos/configurations/mimas.nix b/nixos/configurations/mimas.nix
index 7cd26ab..d6697c9 100644
--- a/nixos/configurations/mimas.nix
+++ b/nixos/configurations/mimas.nix
@@ -51,6 +51,7 @@ in {
   environment.systemPackages = with pkgs; [
     virt-manager
     iptables
+    zsh-syntax-highlighting
   ];
 
   # Some programs need SUID wrappers, can be configured further or are
$ readlink -f /run/current-system/sw/shareyy/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
/nix/store/cz445a7h47dnzajamfgmlmdzpcv72sk8-zsh-syntax-highlighting-0.7.1/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

Okay so I set up a vm with a very minimal test configuration to check, and I don’t get that file there either. Here’s the configuration.nix:


{ config, pkgs, ... }:

{
  imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
    ];

  boot.loader.grub.enable = true;
  boot.loader.grub.version = 2;
  boot.loader.grub.device = "/dev/sda"; # or "nodev" for efi only

  i18n.defaultLocale = "en_UK.UTF-8";

  environment.systemPackages = with pkgs; [
      vim
      wget
      zsh
      zsh-syntax-highlighting
  ];

  system.stateVersion = "22.05"; # Did you read the comment?

}

Built using sudo nixos-rebuild switch.

I asked around in the nixos matrix channel and thanks to one symphorien I managed to get it working!

The solution is to add “/share” to environment.pathsToLink, which I suppose is something somebody more experienced than me would have realised right away.

Thanks for all your help!