Closed folke closed 3 years ago
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.
@cole-h that's exactly how I solved it :)
Closing this issue.
@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
You need to use a full path with home.file. That works in my case
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? 😄
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
This is what i use currently:
$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";
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
.Is there any way to do what I want with the
flake.nix
setup?