GermanBread / declarative-flatpak

127 stars 4 forks source link

[Help/Question] Using with home-manager #24

Closed Guz013 closed 9 months ago

Guz013 commented 9 months ago

Hi! I'm new to NixOS, and I was trying to configure my home-manager config so flatpaks could be used in a declarative using this module, so installed it on flake.nix, using the home-manager module as it shows in the repo:

{
  # ...
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    flatpaks.url = "github:GermanBread/declarative-flatpak/stable";
  };

  outputs = { self, nixpkgs, home-manager, flatpaks, ... }@inputs:
    let
      system = "x86_64-linux";
      pkgs = nixpkgs.legacyPackages.${system};
    in
    {
      nixosConfigurations.default = nixpkgs.lib.nixosSystem {
          specialArgs = {inherit inputs;};
          modules = [ 
            ./hosts/default/configuration.nix
            inputs.home-manager.nixosModules.default
          ];
        };
      homeConfiguration."guz" = home-manager.lib.homeManagerConfiguration {
        inherit pkgs;
        extraSpecialArgs = { inherit inputs; };
        modules = [
            flatpaks.homeManagerModules.default
        ];
      };
    };
}

And then on my home.nix added:

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

{
  # ...
  services.flatpak = {
    enable = true;
    remotes = {
      "flathub" = "https://dl.flathub.org/repo/flathub.flatpakrepo";
      "flathub-beta" = "https://dl.flathub.org/beta-repo/flathub-beta.flatpakrepo";
    };
    packages = [
      "flathub:app/org.mozilla.Thunderbird//stable"
    ];
  };
  # ...
}

And it gave me this error:

error: The option `home-manager.users.guz.services.flatpak' does not exist. Definition values:
       - In `/nix/store/w7f636q9ipaybinvis23x7p6m7lqyrsv-source/hosts/default/configuration.nix':
           {
             enable = true;
             packages = [
               "flathub:app/org.mozilla.Thunderbird//stable"
             ];
           ...

Could you help me with what I'm doing wrong? The documentation isn't so clear for where I should put the services.flatpak when it's related to home-manager. I was able to make it work with the NixOS module, and putting services.flatpak on configuration.nix, but it would be great to have all my user applications under home.nix.

More details and attempts I thought on changing from `services.flatpak` to `config.services.flatpak` and it gives me this error: ``` error: Module `:anon-6:anon-1' has an unsupported attribute `home'. This is caused by introducing a top-level `config' or `options' attribute. Add configuration attributes immediately on the top level instead, or move all of them (namely: home programs) into the explicit `config' attribute ``` On my `configuration.nix` is just (in summary for this issue): ```nix { config, pkgs, inputs, lib, ... }: { imports = [ # Include the results of the hardware scan. ./hardware-configuration.nix inputs.home-manager.nixosModules.default ]; # ... home-manager = { extraSpecialArgs = { inherit inputs; }; users = { "guz" = import ./home.nix; }; }; } ``` The file structure is: ``` |- hosts \ - default |- configuration.nix |- hardware-configuration.nix \- home.nix |- flake.lock |- flake.nix ```

Thanks in advance!

GermanBread commented 9 months ago

You are importing the hm module in your nixos config.

Add it to your hm import array, not the nixos import array

GermanBread commented 9 months ago

I was wrong about the above.

Seems like you are declaring your hm config in two places. Please just put your imports in one place, import order is important.

Guz013 commented 9 months ago

Can you provide the code to fix or tell the line where this happens..? I just followed Vimjoyer's guide about configuring Nix, and I'm still trying to learn it, so it's kinda hard to understand where's the problem. Home-manager itself seems to be working fine at the moment, the problem just started when I tried to customize it with the module.

GermanBread commented 9 months ago

Try this:

Remove the import from here

homeConfiguration."guz" = home-manager.lib.homeManagerConfiguration {
  inherit pkgs;
  extraSpecialArgs = { inherit inputs; };
  modules = [
    flatpaks.homeManagerModules.default
  ];
};

And put it here (and restructure)

home-manager = {
  extraSpecialArgs = { inherit inputs; };
  users = {
    "guz".imports = [ flatpaks.homeManagerModules.default ./home.nix ];
  };
};
Guz013 commented 9 months ago

I changed it so it looks like:

flake.nix

{
  # ...
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";

    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    flatpaks.url = "github:GermanBread/declarative-flatpak/stable";
  };

  outputs = { self, nixpkgs, home-manager, ... }@inputs:
    let
      system = "x86_64-linux";
      pkgs = nixpkgs.legacyPackages.${system};
    in
    {
      nixosConfigurations.default = nixpkgs.lib.nixosSystem {
          specialArgs = {inherit inputs;};
          modules = [ 
            inputs.home-manager.nixosModules.default
            ./hosts/default/configuration.nix
          ];
        };
      homeConfiguration."guz" = home-manager.lib.homeManagerConfiguration {
        inherit pkgs;
        extraSpecialArgs = { inherit inputs; };
      };
    };
}

configuration.nix

{ config, pkgs, inputs, lib, ... }:
{
  imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
      inputs.home-manager.nixosModules.default
    ];
  # ...
  home-manager = {
    extraSpecialArgs = { inherit inputs; };
    users = {
      "guz".imports = [
        inputs.flatpaks.homeManagerModules.default
        ./home.nix
      ];
    };
  };
}

And it gives me:

error: The option `home-manager.users.guz.services.flatpak.enable' does not exist. Definition values:
       - In `/nix/store/8w63xz4vhzwlzdqqparkwl0if2zfnlw4-source/hosts/default/home.nix': true
I tried to import `flatpaks` on `configuration.nix`, so it would be `configuration.nix` ```nix { config, pkgs, flatpaks, inputs, lib, ... }: { imports = [ # Include the results of the hardware scan. ./hardware-configuration.nix inputs.home-manager.nixosModules.default ]; # ... home-manager = { extraSpecialArgs = { inherit inputs; }; users = { "guz".imports = [ flatpaks.homeManagerModules.default ./home.nix ]; }; }; } ``` And it gives me: ``` error: attribute 'flatpaks' missing at /nix/store/lrmxkfadhlcrakza60w0mc8sc327a5qg-source/lib/modules.nix:508:28: 507| builtins.addErrorContext (context name) 508| (args.${name} or config._module.args.${name}) | ^ 509| ) (lib.functionArgs f); ``` --- `home.nix` is still: ```nix { config, pkgs, lib, ... }: { # ... services.flatpak = { enable = true; remotes = { "flathub" = "https://dl.flathub.org/repo/flathub.flatpakrepo"; "flathub-beta" = "https://dl.flathub.org/beta-repo/flathub-beta.flatpakrepo"; }; packages = [ "flathub:app/org.mozilla.Thunderbird//stable" ]; }; # ... } ```
Guz013 commented 9 months ago

Sorry if I did it wrong, I really am trying to understand.

GermanBread commented 9 months ago

Right.

I forgot that services.flatpak.enable is not present in the hm version (because the nixos version uses the option I do not want to overwrite)

Use enableModule instead

My bad, sorry!

GermanBread commented 9 months ago

https://github.com/GermanBread/declarative-flatpak/blob/dev/docs/definition.md#servicesflatpakenablemodule

Guz013 commented 9 months ago

Changing to services.flatpak.enableto services.flatpak.enableModule on home.nix fixed the issue! Thank you very much for the help and quick replies, sorry for the inconvenience 😅

Many thanks for this module also! Really helps me create my NixOS exactly I want now!

GermanBread commented 9 months ago

sorry for the inconvenience

I like helping. Have fun messing with the module!

Guz013 commented 9 months ago

Hey! I was just thinking, wouldn't it be better if in the documentation there was a note warning/informing that in the home-manager module the service.flatpak.enableModule needs to be used instead of the service.flatpak.enable? I would be willing to open a small PR for it.

GermanBread commented 9 months ago

Uhh sure. I will add it, one sec