anyrun-org / anyrun

A wayland native, highly customizable runner.
GNU General Public License v3.0
687 stars 53 forks source link

[Help Wanted] `The option 'home' does not exist` when using anyrun home-manager module in `nixosConfigurations` #92

Open FirelightFlagboy opened 1 year ago

FirelightFlagboy commented 1 year ago

I'm trying to use anyrun home-manager module with home-manager configured as a nixos module (in nixosConfigurations) but with the following command:

sudo nixos-rebuild switch --flake .#thinkpad

I'm getting the following error:

error: The option `home' does not exist. Definition values:
       - In `/nix/store/iarm76b9p60gbkxs0n3dww1r2f4gs650-source/flake.nix':
           {
             _type = "if";
             condition = false;
             content = {
               packages = [
           ...

I've to point out that by using home-manager in a standalone manner don't cause any error:

home-manager switch --flake '.#redacted' -b backup

I would like to help to configure my flake.nix to be able to use the anyrun home-manager module in nixosConfiguration to be able to use it during nixos-rebuild.

I've opened an issue here because I was not able to find any example on google by searching for "anyrun.nixosModules.home-manager" or "anyrun.homeManagerModules.default"

Configurations

My current configuration look something like that:

flake.nix ```nix { description = "NixOS system configuration flake"; inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05"; nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable"; home-manager = { url = "github:nix-community/home-manager/release-23.05"; inputs.nixpkgs.follows = "nixpkgs"; }; anyrun = { url = "github:Kirottu/anyrun"; inputs.nixpkgs.follows = "nixpkgs"; }; }; outputs = { anyrun, nixpkgs, nixpkgs-unstable, nixos-hardware, home-manager, ... }@inputs: let system = "x86_64-linux"; pkgs-unstable = import nixpkgs-unstable { inherit system; config.allowUnfree = true; }; overlay-unstable = final: prev: { unstable = pkgs-unstable; }; pkgs = import nixpkgs { inherit system; config = { allowUnfree = true; packageOverrides = pkgs: { xdg-desktop-portal-hyprland = pkgs-unstable.xdg-desktop-portal-hyprland; hyprland = pkgs-unstable.hyprland; }; }; overlays = [ overlay-unstable ]; }; lib = nixpkgs.lib; in { # NixOS configuration entrypoint # Available through `nixos-rebuild --flake '.#key' nixosConfigurations = { thinkpad = lib.nixosSystem { inherit system pkgs; modules = [ ./nixos/configuration.nix home-manager.nixosModules.home-manager anyrun.nixosModules.home-manager { home-manager = { useGlobalPkgs = true; useUserPackages = true; users.redacted = import ./home-manager/home.nix; }; } ]; }; }; # Standalone home-manager configuration entrypoint # Available through `home-manager --flake '.#key' homeConfigurations = { redacted = home-manager.lib.homeManagerConfiguration { inherit pkgs; modules = [ anyrun.nixosModules.home-manager ./home-manager/home.nix ]; }; }; }; } ``` > As you can see, I've added `anyrun.nixosModules.home-manager` to `nixosConfiguration.thinkpad.modules` and `homeConfigurations.redacted.modules`

I don't include home.nix file because it don't contain configuration related to anyrun.

Sntx626 commented 1 year ago

So you are saying the error is thrown by just importing the anyrun hm module?

Can you try inputs.anyrun.nixosModules."${system}".home-manager?

FirelightFlagboy commented 1 year ago

Hello @Sntx626,

So you are saying the error is thrown by just importing the anyrun hm module?

Yes, just importing the module in nixosConfigurations give me erros.


Can you try inputs.anyrun.nixosModules."${system}".home-manager?

I've tried your suggestion:

diff --git a/flake.nix b/flake.nix
index 61b4a1f..9b8ec6c 100644
--- a/flake.nix
+++ b/flake.nix
@@ -58,7 +58,8 @@
                     ./nixos/configuration.nix
                     home-manager.nixosModules.home-manager
                     # anyrun.nixosModules.home-manager
-                    anyrun.homeManagerModules.default
+                    inputs.anyrun.nixosModules."${system}".home-manager
                     {
                         home-manager = {
                             useGlobalPkgs = true;

But it gave me the following error:

error: attribute 'x86_64-linux' missing

       at /nix/store/cb46jgw2xy9m57s4g94rrjw4l9fbdj81-source/flake.nix:62:21:

           61|                     # anyrun.homeManagerModules.default
           62|                     inputs.anyrun.nixosModules."${system}".home-manager
             |                     ^
           63|                     {
pchabros commented 1 year ago

Same issue here. @FirelightFlagboy do you have any progress with it?

FirelightFlagboy commented 1 year ago

Hello @pchabros, I've made no progress :(

Sntx626 commented 1 year ago

Can you try inputs.anyrun.nixosModules."${system}".home-manager?

My bad, I forked anyrun and forgot I changed the flake that much. The following is a reference on how I circumvented the problem.

You can take a look at my anyrun fork - specifically the flake of that fork.

And how I import that flake into my system flake and the anyrun system module I use to config anyrun and set the plugins.

Though I do not recommend running or depending on these forks, a I just wait for #87 to complete. My forks will be out-of-date most of the time.

Lord-Valen commented 10 months ago

Home-manager modules should be imported only in the home-manager portions of your configuration. When you import the anyrun module in the nixosConfigurations.<name>'s modules, the module tries to access home.* which does not exist and is not expected to exist. That only exists in homeConfigurations.<name>.

        nixosConfigurations = {
            thinkpad = lib.nixosSystem {
                inherit system pkgs;

                modules = [
                    ./nixos/configuration.nix
                    home-manager.nixosModules.home-manager
-                   anyrun.nixosModules.home-manager
                    {
                        home-manager = {
                            useGlobalPkgs = true;
                            useUserPackages = true;
                            users.redacted = import ./home-manager/home.nix;
                        };
                    }
                ];
            };
        };
FelixSchausberger commented 10 months ago

@Lord-Valen would you be so kind and give a minimal working example of how this would look in a flake.nix without using flake-parts? I'm just digging into flakes and have been trying to get anyrun to work for quite a while now but somehow can't get my head around it.

My current flake.nix looks something like that:

flake.nix ```nix { description = "Personal NixOS config"; inputs = { anyrun = { url = "github:Kirottu/anyrun"; inputs.nixpkgs.follows = "nixpkgs"; }; nixpkgs.url = "nixpkgs/nixos-23.11"; nixpkgs-unstable.url = "nixpkgs/nixpkgs-unstable"; home-manager = { url = "github:nix-community/home-manager/release-23.11"; inputs.nixpkgs.follows = "nixpkgs"; }; nur.url = "github:nix-community/NUR"; }; outputs = inputs@{ anyrun, home-manager, nixpkgs, nixpkgs-unstable, nur, self, ... }: let mkSystem = host: nixpkgs.lib.nixosSystem rec { system = "x86_64-linux"; specialArgs = { flake-inputs = inputs; inherit anyrun home-manager host; }; modules = [ nur.nixosModules.nur # Include custom configurations ./configuration.nix ./hosts/${host} # Configure Home Manager home-manager.nixosModules.home-manager { home-manager.useGlobalPkgs = true; home-manager.extraSpecialArgs = { # Read secrets from a JSON file secrets = builtins.fromJSON (builtins.readFile "${self}/secrets/secrets.json"); flake-inputs = inputs; inherit host nixpkgs nixpkgs-unstable; pkgs-unstable = nixpkgs-unstable.legacyPackages.${system}; }; } ]; }; in { # NixOS system configurations nixosConfigurations = { desktop = mkSystem "desktop"; surface = mkSystem "surface"; }; }; } ```
Lord-Valen commented 10 months ago

This will build the minimal install-iso with home-manager and the anyrun module. You can run it in a vm with nix run .#nixosConfigurations.some-configuration.config.system.build.vm (or the more easily remembered nixos-generators --run --flake .#some-configuration).

# flake.nix
{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
    home-manager = {
      url = "github:nix-community/home-manager/release-23.11";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    anyrun.url = "github:Kirottu/anyrun"; # Don't override nixpkgs if you want the binary cache to work
  };

  outputs = {
    nixpkgs,
    home-manager,
    anyrun,
    ...
  }: {
    nixosConfigurations.some-configuration = let
      system = "x86_64-linux";

      pkgs = import nixpkgs {inherit system;};
    in
      nixpkgs.lib.nixosSystem { # Configure the system environment
        inherit system pkgs;

        modules = [
          ({modulesPath, ...}: { # Base the MVE on the minimal install-iso
            imports = [
              (builtins.toString modulesPath + "/installer/cd-dvd/installation-cd-minimal.nix")
            ];
          })

          home-manager.nixosModules.home-manager # Import the home-manager nixos module

          ({pkgs, ...}: {
            users.users.nixos.isNormalUser = true; # Make sure the user exists
            home-manager = {
              # These two aren't necessary, but they sure are nice
              useGlobalPkgs = true; # Use the system `pkgs`
              useUserPackages = true; # Use `/etc/profile`

              users.nixos = { # Configure the user's environment
                imports = [
                  anyrun.homeManagerModules.anyrun # Import the anyrun home-manager module
                ];

                programs.anyrun = {
                  # Configure anyrun using the module's options
                  enable = true;
                  config = {
                    plugins = with anyrun.packages.${system}; [];
                  };
                };

                home.stateVersion = "23.11";
              };
            };

            system.stateVersion = "23.11";
          })
        ];
      };
  };
}