nix-community / home-manager

Manage a user environment using Nix [maintainer=@rycee]
https://nix-community.github.io/home-manager/
MIT License
6.38k stars 1.7k forks source link

bug: Error installing file '.config/micro/settings.json' outside $HOME #5175

Open terxw opened 4 months ago

terxw commented 4 months ago

Are you following the right branch?

Is there an existing issue for this?

Issue description

I am trying to symlink my dotfiles to ~/.config folder, but I cannot get any combination of paths, strings, relative string path, absolute string path to workt with mkOutOfStoreSymlink.

I am using 23.11, flakes, impure

Example config:

{ config, lib, pkgs, inputs, ... }:

    {
    home = {
      file = {
        "./config/micro".source = config.lib.file.mkOutOfStoreSymlink "/home/kangus/.dotfiles/.config/micro";
      };
    };
}

Invoking command:

home-manager --show-trace switch --flake ~/nixos-config/flake_wimpy#kangus@nixos_vm  --impure'```

I get error:

error: builder for '/nix/store/5qqm9gyw7b5m35087wg31kdadgkyady1-home-manager-files.drv' failed with exit code 1; last 1 log lines:

   > Error installing file '.config/micro/settings.json' outside $HOME

   For full logs, run 'nix log /nix/store/5qqm9gyw7b5m35087wg31kdadgkyady1-home-manager-files.drv'.error: 1 dependencies of derivation '/nix/store/jm5pghaxg8lvyn032ibhsgjx9ky9dyib-home-manager-generation.drv' failed to build```

Troubleshooting I tried:

https://www.reddit.com/r/NixOS/comments/197wnuy/help_making_a_direct_symlink_from_config_repo_to/

https://github.com/nix-community/home-manager/issues/2085

Here are variants I tried:

    enable = true;
    configFile."micro".source  = config.lib.file.mkOutOfStoreSymlink "/home/kangus/.dotfiles/.config";
  };
home = {
  file.".config/micro" = {
    source = config.lib.file.mkOutOfStoreSymlink "/home/kangus/.dotfiles/.config/micro";
    recursive = true;
  };
# according to reddit forum its wrong because it translates to /home/kangus/home/kangus/.config/micro
home = {
  file."${config.home.homeDirectory}/.config/micro" = {
    source = config.lib.file.mkOutOfStoreSymlink ""${config.home.homeDirectory}/.dotfiles/.config/micro";
    recursive = true;
  };
# in flakes the target cannot be nix path type, but string, but probably same error as above, e.g.  /home/kangus/home/kangus/.config/micro

home = {
    file.".config/micro" = {
      source = config.lib.file.mkOutOfStoreSymlink  "${builtins.toString config.xdg.configHome}/.dotfiles/.config/micro";
      recursive = true;
    };
};

EDIT: This variant doesnt throw error, but creates read only link to store with two levels of indirection

home = {
    file.".config/micro" = {
      source = "/home/kangus/.dotfiles/.config/micro";
      recursive = true;
    };
};
lt ~/.config/micro
settings.json -> /nix/store/k1gx5nvlwc9b724aqyiv0y30vhv5n9yr-home-manager-files/.config/micro/settings.json
lt /nix/store/k1gx5nvlwc9b724aqyiv0y30vhv5n9yr-home-manager-files/.config/micro/settings.json
lrwxrwxrwx     - root  1 jan  1970   /nix/store/k1gx5nvlwc9b724aqyiv0y30vhv5n9yr-home-manager-files/.config/micro/settings.json -> /nix/store/fsw43b48qhqdkm363qdpnkrbp8wzr0b4-hm_micro/settings.json
lt /nix/store/fsw43b48qhqdkm363qdpnkrbp8wzr0b4-hm_micro/settings.json
Permissions Size User Date Modified Name
.r--r--r--   664 root  1 jan  1970   /nix/store/fsw43b48qhqdkm363qdpnkrbp8wzr0b4-hm_micro/settings.json    

Maintainer CC

No response

System information

- system: `"x86_64-linux"`
 - host os: `Linux 6.6.18, NixOS, 23.11 (Tapir), 23.11.20240301.79baff8`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.1`
 - nixpkgs: `/nix/store/3i3rncs75fid9hwai5p2nvwc4ngdnia7-source`
fl42v commented 1 month ago

Have you checked if the contents of the file match that of the file you're trying to source? I've just encountered the same issue with neovim, and it turned out the resulting file was generated by stylix instead of what I was trying to symlink. Disabling the stylix module fixed it.

On a side note, it'd be awesome if hm at least threw a warning in such situations.

miend commented 1 week ago

@fl42v Thank you! This was the cause of exactly the same issue I was experiencing which led me to this thread. To amplify the results in searches, the exact error I was investigating looked like: Error installing file '.config/nvim/init.lua' outside $HOME

As above, disabling stylix's handling of neovim config files solved it. You can disable neovim as a target specifically with stylix's Home Manager option:

stylix.targets.vim.enable = false;