nix-community / home-manager

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

News cannot be read when using flakes only #2033

Open dschrempf opened 3 years ago

dschrempf commented 3 years ago

When using flakes, news cannot be read with the following error:

 + home-manager news
No configuration file found. Please create one at /home/dominik/.config/nixpkgs/home.nix

I can link the flake to ~/.config/nixpkgs to work around this issue, but in the long run, a consistent usage like so: home-manager --flake /path/to/directory COMMAND (like it is defined for the command switch already) would be preferrable.

x10an14 commented 2 years ago

I was linked here on suspicion that this might be the same bug I'm experiencing (on a pure flake config):

[2022-01-29 12:11:08] 0 x10an14@bits-laptop:~
-> $ home-manager --debug --verbose news
resolved search path element '/nix/var/nix/profiles/per-user/root/channels' to '/nix/var/nix/profiles/per-user/root/channels'
error: file 'home-manager/home-manager/home-manager.nix' was not found in the Nix search path (add it using $NIX_PATH or -I)
/home/x10an14/.nix-profile/bin/home-manager: line 424: /tmp/home-manager-build.8YKn0CUBhO/news-info.sh: No such file or directory
[2022-01-29 12:11:17] 0 x10an14@bits-laptop:~
-> $ home-manager --debug --verbose --flake ~/.config/nixpkgs news
resolved search path element '/nix/var/nix/profiles/per-user/root/channels' to '/nix/var/nix/profiles/per-user/root/channels'
error: file 'home-manager/home-manager/home-manager.nix' was not found in the Nix search path (add it using $NIX_PATH or -I)
/home/x10an14/.nix-profile/bin/home-manager: line 424: /tmp/home-manager-build.Az0e6aKX62/news-info.sh: No such file or directory
[2022-01-29 12:11:35] 0 x10an14@bits-laptop:~
-> $ la ~/.config/nixpkgs/
total 40K
   0 drwxr-xr-x 1 x10an14 x10an14  288 jan.  29 08:33 ./
   0 drwxr-xr-x 1 x10an14 x10an14  112 jan.  29 07:45 ../
4,0K -rw-r--r-- 1 x10an14 x10an14 1,5K jan.  28 10:42 flake.lock
4,0K -rw-r--r-- 1 x10an14 x10an14 1,6K jan.  28 23:51 flake.nix
4,0K -rw-r--r-- 1 x10an14 x10an14   56 jan.  27 20:47 .git
4,0K -rw-r--r-- 1 x10an14 x10an14   37 jan.  27 20:47 .gitignore
4,0K -rw-r--r-- 1 x10an14 x10an14  495 jan.  28 23:51 home.nix
< the rest omitted for brevity>
[2022-01-29 12:12:28] 0 x10an14@bits-laptop:~
-> $

Is this related? If so, what's the status (if there's anything changed since May) on this bug?

If not, I'll make a new issue^^

nixos-discourse commented 2 years ago

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

https://discourse.nixos.org/t/depreciate-the-use-of-nix-env-to-install-packages/20139/32

sullyj3 commented 1 year ago

This seems to be fixed for me in 23.11-pre.

nixos-discourse commented 1 year ago

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

https://discourse.nixos.org/t/home-manager-news-no-configuration-found/32170/2

NobbZ commented 1 year ago

It seems to be not fixed for me, and additional info, if I add --flake $location, I end up with this error instead:

home-manager news --flake github:nobbz/nixos-config
Home Manager not found at /nix/store/4jvg1mvyg9ah4la7wmwg08sifrd2w8ks-source.
error: file 'home-manager/home-manager/build-news.nix' was not found in the Nix search path (add it using $NIX_PATH or -I)

       at «none»:0: (source not available)
spikespaz commented 1 year ago

I would like the option to simply disable news. I don't like the time it takes to evaluate.

news.enable = false

jzbor commented 1 year ago

I get an error even when running home-manager switch:

error: file 'home-manager/home-manager/build-news.nix' was not found in the Nix search path (add it using $NIX_PATH or -I)

       at «none»:0: (source not available)
Dioprz commented 1 year ago

It seems to be not fixed for me, and additional info, if I add --flake $location, I end up with this error instead:

home-manager news --flake github:nobbz/nixos-config
Home Manager not found at /nix/store/4jvg1mvyg9ah4la7wmwg08sifrd2w8ks-source.
error: file 'home-manager/home-manager/build-news.nix' was not found in the Nix search path (add it using $NIX_PATH or -I)

       at «none»:0: (source not available)

Could you try again? I don't know if anything has changed, but a couple of hours ago I did:

home-manager news --flake ~/Nix/

And everything worked perfectly.

NobbZ commented 1 year ago

Yeah, seems to not be an issue right now.

nixos-discourse commented 1 year ago

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

https://discourse.nixos.org/t/how-would-i-open-home-manager-news-in-my-flake-setup/18572/2

Nairou commented 1 year ago

I get an error even when running home-manager switch:

error: file 'home-manager/home-manager/build-news.nix' was not found in the Nix search path (add it using $NIX_PATH or -I)

       at «none»:0: (source not available)

I get this fairly frequently, after modifying my config. Immediately running the command again always succeeds. Still, it's annoying to see the error come up, and I don't know what the fix is.

sersorrel commented 1 year ago

I got that error recently on the first rebuild after a garbage-collection; I wonder if that's related.

J-Swift commented 1 year ago

I got that error recently on the first rebuild after a garbage-collection; I wonder if that's related.

Same here

spikespaz commented 1 year ago
modules = [
  # It doesn't even work out of the box with flakes...
  # <https://github.com/nix-community/home-manager/issues/2033#issuecomment-1698406098>
  {
    # news.display = "silent";
    disabledModules = [ "misc/news.nix" ];
  }
  # ...
};

Unfortunately, this will make the command always exit with 1:

error: flake 'path:.' does not provide attribute 'packages.x86_64-linux.homeConfigurations."jacob".config.news.json.output', 'legacyPackages.x86_64-linux.homeConfigurations."jacob".config.news.json.output' or 'homeConfigurations."jacob".config.news.json.output'
NobbZ commented 1 year ago

@spikespaz how much does this change the behaviour of regular home-manager switch with and without flakes?

I'm a bit confused by your comment about always having an exit code of 1

spikespaz commented 1 year ago

@spikespaz how much does this change the behaviour of regular home-manager switch with and without flakes?

I'm a bit confused by your comment about always having an exit code of 1

When the home-manager script tries to evaluate news in presentNews, it exits with code 1.

I tried patching home-manager but was unsuccessful.

luisnquin commented 11 months ago

I've got the same error right now, using NixOS 23.11 and Flakes

home-manager switch --flake .

spikespaz commented 11 months ago

I was annoyed enough to look at this closer.

Here's a module that we can use to mitigate this issue (does not cause failure in CI):

# It doesn't even work out of the box with flakes...
# <https://github.com/nix-community/home-manager/issues/2033#issuecomment-1801557851>
#
# Include this in the `modules` passed to
# `inputs.home-manager.lib.homeManagerConfiguration`.
disableHomeManagerNews = {
  # disabledModules = [ "misc/news.nix" ];
  config = {
    news.display = "silent";
    news.json = lib.mkForce { };
    news.entries = lib.mkForce [ ];
  };
};
ian-h-chamberlain commented 3 months ago

I was annoyed enough to look at this closer.

Here's a module that we can use to mitigate this issue (does not cause failure in CI):

# It doesn't even work out of the box with flakes...
# <https://github.com/nix-community/home-manager/issues/2033#issuecomment-1801557851>
#
# Include this in the `modules` passed to
# `inputs.home-manager.lib.homeManagerConfiguration`.
disableHomeManagerNews = {
  # disabledModules = [ "misc/news.nix" ];
  config = {
    news.display = "silent";
    news.json = lib.mkForce { };
    news.entries = lib.mkForce [ ];
  };
};

In order to get this working on my system with a recent home-manager (e1391fb22e18a36f57e6999c7a9f966dc80ac073), I had to remove news.json from this example:

  news = {
    display = "silent";
    entries = lib.mkForce [ ];
  };

The output JSON file will still be created, just with empty contents:

{"display":"silent","entries":[]}