Ah Mr. Ringer, thank you! This is certainly a useful trick, and very good to know, but I don’t know if it bodes well for my use-case here. Now that I have access to the code I’m trying to write, let me elaborate, and provide the Y
to my X-Y Problem.
So, among others, I have a neovim config that I would like to be able to play/experiment with–without the need to constantly rebuild/reactivate my flake every change.
My directory layout is as follows:
flake.nix
modules/
home/
nvim/
default.nix
lua/
me/init.lua
The current strategy is to use the following in modules/home/nvim/default.nix
to symlink the neovim config in the store to an out-of-store file:
{ pkgs, config, lib, ... }:
#...
xdg.configFile."nvim/lua/me/init.lua".source =
config.lib.file.mkOutOfStoreSymlink(config.home.homeDirectory
+ "/path/to/flake/modules/home/nvim/lua/me/init.lua")
However now, I’ve seen explained before that doing this does defeat the purpose of flakes a little bit, making the config ultimately less declarative/robust, which makes sense. So, to remedy this (and also as a bit of an experiment to see if I can do it or not), I am trying to create something like the following in my flake.nix
:
#...
outputs = inputs@{ self, nixpkgs, home-manager, ... }:
let
repoDirName = "nix-home-redux";
homeRepoDirPath = "workbench/${repoDirName}"
linkConfig = rec {
liveConfig = true;
flakeRoot = self.outPath;
externalHomeRoot = "${config.home.homeDirectory}/${homeRepoDirPath}";
to = path: (
if liveConfig
then (config.lib.file.mkOutOfStoreSymlink "${externalHomeRoot}/${path}")
else "${flakeRoot}/${path}");
};
in
{
#...
homeManagerConfigurations.linux-server = home-manager.lib.homeManagerConfiguration rec {
system = "x86_64-linux";
username = "me";
homeDirectory = "/home/${username}";
extraSpecialArgs = { inherit inputs; };
stateVersion = "21.05";
configuration = { imports = [ ./modules/home/nvim ]; };
};
#...
}
Where I would then ideally be able to provide linkConfig
to ./modules/home/nvim
and be able to now rewrite the earlier xdg.config
setting as:
xdg.configFile."nvim/lua/me/init.lua".source = linkConfig.to "modules/home/nvim/lua/me/init.lua";
As you can tell, I’m still a few steps away from a final solution here.
My current hold-up is that I can’t actually reference config
at all in the let
bindings, is there anything that would allow me to get my hands on something like that there?