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

mkOutOfStoreSymlink doesn't work as expected with a flake setup #2085

Closed
folke opened this issue Jun 8, 2021 · 7 comments
Closed

mkOutOfStoreSymlink doesn't work as expected with a flake setup #2085

folke opened this issue Jun 8, 2021 · 7 comments

Comments

@folke
Copy link

folke commented Jun 8, 2021

Issue description

I'm currently migrating my dotfiles to Nix using nix-darwin and the home-manager module.

One problem I'm having is that mkOutOfStoreSymlink doesn't seem to work when using flakes.

In the example below, the .config/alacritty directory will link to the flake sources (/nix/store/54vrjl9afxg7ckb5waxy3w521f3mpi3j-hm_alacritty) instead of the original directory in my ~/projects/dot/config/alacritty.

 xdg.configFile."alacritty".source = config.lib.file.mkOutOfStoreSymlink ../../config/alacritty;

Is there any way to do what I want with the flake.nix setup?

@cole-h
Copy link
Member

cole-h commented Jun 8, 2021

mkOutOfStoreSymlink also supports strings, so you can hardcode it as mkOutOfStoreSymlink "${config.home.homeDirectory}/projects/dot/config/alacritty". If the location ever changes, you'll have to change it then as well.

@folke
Copy link
Author

folke commented Jun 8, 2021

@cole-h that's exactly how I solved it :)

Closing this issue.

@folke folke closed this as completed Jun 8, 2021
@andyrichardson
Copy link

andyrichardson commented Jun 15, 2021

@folke when providing a string argument, the link would then point to the source file within your home directory?

I've tried using a string but it's making no difference (NixOS)

xdg.configFile."Code/User/settings.json".source = config.lib.file.mkOutOfStoreSymlink  "${config.home.homeDirectory}/dev/dotfiles/nix/config/settings.json";
ls -l /home/andy/.config/Code/User/settings.json 
lrwxrwxrwx 1 andy users 94 Jun 15 12:39 /home/andy/.config/Code/User/settings.json -> /nix/store/9qqncknpzrfhw21kwa9k634ady5lm0bk-home-manager-files/.config/Code/User/settings.json

Edit: Looks like, when using a string, the link eventually points to the file in the home directory (with correct read/write permissions)

 /home/andy/.config/Code/User/settings.json -> /nix/store/3c2spxdxgcfqw1k01lm27s6n15amx79d-home-manager-files/.config/Code/User/settings.json -> /nix/store/dawm1s7974fa512h95sw4a4w1jymj54a-hm_settings.json -> /home/andy/dev/dotfiles/nix/config/settings.json

@folke
Copy link
Author

folke commented Jun 15, 2021

You need to use a full path with home.file. That works in my case

@Lillecarl
Copy link
Contributor

I scratched my head for awhile about how to get the absolute path of the flake. It ended up being quite dirty. I run my builds through a script. This scripts writes the path to a file within the flake repo, this file is ignored with git update-index --skip-worktree ".flakepath" after an initial commit so that Nix doesn't complain it's not in the repo.

At this point I guess I could just make the script make the symlinks too, but it's pretty nice to have them activated and deactivated through Nix.

Does anyone have a better solution 2023? 😄

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/how-to-manage-dotfiles-with-home-manager/30576/5

@amardeep
Copy link

This is what i use currently:

  • My flakes git repo is generally checkout in $HOME/.dotfiles. I create an option for this location which gives me the flexibility to override it for a particular host if needed:
  options = {
    dotfiles = lib.mkOption {
      type = lib.types.path;
      apply = toString;
      default = "${config.home.homeDirectory}/.dotfiles";
      example = "${config.home.homeDirectory}/.dotfiles";
      description = "Location of the dotfiles working copy";
    };
  };

Then, I use this option whenever i want to create a symlink to a file, for eg.

xdg.configFile."wezterm".source = config.lib.file.mkOutOfStoreSymlink "${config.dotfiles}/config/wezterm";

home.file.".p10k.zsh".source = config.lib.file.mkOutOfStoreSymlink "${config.dotfiles}/config/zsh/p10k.zsh";

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

No branches or pull requests

6 participants