chaotic-cx/nyx

Add instructions for non-NixOS home-manager users

bayazidbh opened this issue · 8 comments

Hi, I still don't really get how to use flakes, I put in the flake configs in ~/.config/home-manager/flake.nix and I got the following output:

warning: creating lock file '/home/fenglengshun/.config/home-manager/flake.lock'
error: flake 'path:/home/fenglengshun/.config/home-manager' does not provide attribute 'packages.x86_64-linux.homeConfigurations', 'legacyPackages.x86_64-linux.homeConfigurations' or 'homeConfigurations'
error: flake 'path:/home/fenglengshun/.config/home-manager' does not provide attribute 'packages.x86_64-linux.homeConfigurations', 'legacyPackages.x86_64-linux.homeConfigurations' or 'homeConfigurations'
error: flake 'path:/home/fenglengshun/.config/home-manager' does not provide attribute 'packages.x86_64-linux.homeConfigurations."fenglengshun".activationPackage', 'legacyPackages.x86_64-linux.homeConfigurations."fenglengshun".activationPackage' or 'homeConfigurations."fenglengshun".activationPackage'

Currently, I only understand using import <channel>, builtins.fetchTarball, and builtins.fetchGit. Could an example for home-manager flake config be added please? Or maybe a simpler import set-up that could be added to instructions?

Currently, we don't have a home-manager-specific module. But the overlay should still work as desired:

  1. Add the inputs to the flake.nix:
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
+    chaotic.url = "github:chaotic-cx/nyx/nyxpkgs-unstable";
  };
  1. You still need to get the chaotic from the output's parameter's attrset:
-  outputs = { nixpkgs, ... }: {
+  outputs = { nixpkgs, chaotic, ... }: {
  1. Now you have to add our overlay:
    3.a. Option A: Add it to home-manager's nixpkgs.overlays option, inside one of your modules:
+nixpkgs.overlays = [ chaotic.overlays.default ];

3.b. Option B: Add it to import nixpkgs:

  pkgs = import nixpkgs {
+    overlays = [ chaotic.overlays.default ];
    system = "x86_64-linux"
  1. After this, you shall be able to install our packages as if they were from nixpkgs:
{
  home.packages = with pkgs; [ yuzu-early-access_git ];
}

Please, let me know if it worked out.

@bayazidbh bumping you to know if it worked. (So I can add it to the README)

Uh, I'm still very new to Nix, so I'm not entirely sure what I'm supposed to do, maybe an example of the whole flakes.nix? Otherwise, I'll try this out when I have the time this weekend. Sorry about that...

Alright, I tested it out, but I think there are some additions needed to be added to this repo's flake.nix.

Currently, this is my flake.nix:

My flake.nix

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; # use nixpkgs-unstable as main nixpkgs source
    home-manager = {
      url = "github:nix-community/home-manager"; # home-manager unstable url
      inputs.nixpkgs.follows = "nixpkgs"; # inherit nixpkgs-unstable as main nixpkgs source
    };
    flatpaks.url = "github:GermanBread/declarative-flatpak/stable"; # declarative-flatpak, still WIP
    chaotic.url = "github:chaotic-cx/nyx/nyxpkgs-unstable"; # https://github.com/chaotic-cx/nyx#how-to-use-it
    # Add other inputs if needed
  };

  outputs = { self, nixpkgs, home-manager, flatpaks }:
  let
    # Generate a user-friendly version number.
    # version = builtins.substring 0 2 self.lastModifiedDate;

    # System types to support.  [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
    supportedSystems = [ "x86_64-linux" ];

    # Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'.
    forAllSystems = nixpkgs.lib.genAttrs supportedSystems;

    # Nixpkgs instantiated for supported system types.
    nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; });

  in
  {
    # Standalone home-manager configuration entrypoint
    homeConfigurations = {
    # declare a "username" or "username@hostname" specific configuration
      "fenglengshun@ostree-pc" = home-manager.lib.homeManagerConfiguration {
        pkgs = nixpkgs.legacyPackages.x86_64-linux; # Home-manager requires 'pkgs' instance
        modules = [
          ./pc/home.nix # device specific home.nix
          flatpaks.homeManagerModules.default # import declarative-flatpak module
          chaotic.nixosModules.default # default nix
        ];
      };
      "fenglengshun@neon-laptop" = home-manager.lib.homeManagerConfiguration {
        pkgs = nixpkgs.legacyPackages.x86_64-linux; # Home-manager requires 'pkgs' instance
        modules = [
          ./laptop/home.nix # device specific home.nix
          flatpaks.homeManagerModules.default # import declarative-flatpak module
        ];
      };
    };
  };
}

Remove the two lines about chaotic, and it works. So the minimum to get chaotic-nyx working on non-NixOS home-manager should be:

minimum flake.nix for future instruction

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; # use nixpkgs-unstable as main nixpkgs source
    home-manager = {
      url = "github:nix-community/home-manager"; # home-manager unstable url
      inputs.nixpkgs.follows = "nixpkgs"; # inherit nixpkgs-unstable as main nixpkgs source
    };
    chaotic.url = "github:chaotic-cx/nyx/nyxpkgs-unstable"; # add chaotic's github url
    # Add your other inputs
  };

  outputs = { self, nixpkgs, home-manager, flatpaks }:
  {
    # Standalone home-manager configuration entrypoint
    homeConfigurations = {
    # declare a "username" or "username@hostname" specific configuration
      ">INSERT YOUR USERNAME + OPTIONALLY HOSTNAME<" = home-manager.lib.homeManagerConfiguration {
        pkgs = nixpkgs.legacyPackages.x86_64-linux; # Home-manager requires 'pkgs' instance
        modules = [
          ./<folder>/home.nix # location to home.nix relative to flake.nix path, use ./home.nix if in the same folder
          chaotic.homeManagerModules.default # default chaotic-nyx module
        ];
      };
    };
  };
}

However, switching to the flakes using chaotic's default module gets me the error:

nixosModules

home-manager switch
error: undefined variable 'chaotic'

       at /nix/store/mwh336zsyvhg95xicdqdf6yxbmc2ca6q-source/flake.nix:37:11:

           36|           flatpaks.homeManagerModules.default # import declarative-flatpak module
           37|           chaotic.nixosModules.default # default chaotic-nyx module
             |           ^
           38|         ];
error: undefined variable 'chaotic'

       at /nix/store/mwh336zsyvhg95xicdqdf6yxbmc2ca6q-source/flake.nix:37:11:

           36|           flatpaks.homeManagerModules.default # import declarative-flatpak module
           37|           chaotic.nixosModules.default # default chaotic-nyx module
             |           ^
           38|         ];
error: undefined variable 'chaotic'

       at /nix/store/mwh336zsyvhg95xicdqdf6yxbmc2ca6q-source/flake.nix:37:11:

           36|           flatpaks.homeManagerModules.default # import declarative-flatpak module
           37|           chaotic.nixosModules.default # default chaotic-nyx module
             |           ^
           38|         ];

Looking at declarative-flatpak's flake.nix, it seems you guys would need separate module for handling home-manager? Based on what I've learned, you'd probably need to make a separate section for home-manager in flake.nix, or import it from a separate file.

One of the headache as I was trying to get a flake working, aside for scattered documentation and guides (don't use ChatGPT, it hallucinates WAY too much for Nix), is that I don't have nixosSystem and any variables involving nixos. Instead of nixosConfigurations I have to use homeConfigurations or home-manager.lib.homeManagerConfiguration. That's probably the blocker.

Also would probably need to make a list for actual home-manager pkgs and Options -- they're packages and configs that would be installed, set, and operates properly purely through /home/$USER. For pkgs and Options that needs root access, if you want to support them for non-NixOS then you can have a separate instruction, list, and module for system-manager.

So for now, I would suggest just adding "non-NixOS home-manager users are not currently supported". You'd have to make separate section for HM, shedding all the NixOS assumptions.

(At least from what I've learned anyways - I could be wrong tbh)

Looking at declarative-flatpak's flake.nix, it seems you guys would need separate module for handling home-manager? Based on what I've learned, you'd probably need to make a separate section for home-manager in flake.nix, or import it from a separate file.****

You should be able to use it without a module and referring to the flake's packages directly. But yeah, we could make one HM module to make things easier too.

To be more specific on the "you should be able to use it without a module":

{ chaotic, ... }:
{
  programs.yt-dlp.package = chaotic.packages.x86-64-linux.yt-dlp_git;
}

Okay, that works. I found what I needed to do:

1.) NOT forgetting to add chaotic into the opening statement of outputs on nix
2.) Add extraSpecialArgs = { inherit chaotic; }; to home-manager.lib.homeManagerConfiguration as you say
3.) Add the full chaotic.packages.x86_64-linux.<pkgs-name> when adding to home.packages, following what you said. chaotic.packages.${pkgs.hostPlatform.system}.<pkgs-name> also works when adding to home.packages in the main home.nix file.

So, I would say the instruction could be something like:

instruction draft

Put in ~/.config/home-manager/flake.nix :

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; # use nixpkgs-unstable as main nixpkgs source
    home-manager = {
      url = "github:nix-community/home-manager"; # home-manager unstable url
      inputs.nixpkgs.follows = "nixpkgs"; # inherit nixpkgs-unstable as main nixpkgs source
    };
    chaotic.url = "github:chaotic-cx/nyx/nyxpkgs-unstable"; # add chaotic's github url
    # Add your other inputs
  };

  outputs = { self, nixpkgs, home-manager, flatpaks, chaotic }:
  {
    # Standalone home-manager configuration entrypoint
    homeConfigurations = {
    # declare a "username" or "username@hostname" specific configuration
      ">INSERT YOUR USERNAME + OPTIONALLY HOSTNAME<" = home-manager.lib.homeManagerConfiguration {
        pkgs = nixpkgs.legacyPackages.x86_64-linux; # Home-manager requires 'pkgs' instance
        extraSpecialArgs = { inherit chaotic; }; # so that home-manager can correctly read chaotic.packages
        modules = [
          ./<folder>/home.nix # location to home.nix relative to flake.nix path, use ./home.nix if in the same folder
          ./<folder>/chaotic.nix # if you prefer a separate file for chaotic-nyx configs
          # chaotic.nixosModules.default # do not add the module, it does not currently work outside of NixOS - either don't write it, or comment it out
        ];
      };
    };
  };
}

Then, if you just use the one home.nix file:

{ config, pkgs, chaotic, ... }:

{

home.packages = with pkgs; [
    chaotic.packages.${pkgs.hostPlatform.system}.fastfetch # you may also use absolute system platform such as `x86_64-linux`
    # ... your other packages
    ];
}

Or, if you have a separate chaotic.nix file:

{ chaotic, ... }:
{
  home.packages = [
    chaotic.packages.x86_64-linux.fastfetch # `${pkgs.hostPlatform.system}` may not work, unless you have manually adjusted it for this file
  ];
}

And yeah, the module doesn't work, adding chaotic.nixosModules.default results in:

Details

home-manager switch
error:
       … while evaluating a branch condition

         at /nix/store/8dq1grzr2g9ghh8nrwh15mn65pnp9qb1-source/lib/lists.nix:57:9:

           56|       fold' = n:
           57|         if n == len
             |         ^
           58|         then nulwhile calling the 'length' builtin

         at /nix/store/8dq1grzr2g9ghh8nrwh15mn65pnp9qb1-source/lib/lists.nix:55:13:

           54|     let
           55|       len = length list;
             |             ^
           56|       fold' = n:

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: attribute 'steam' missing

       at /nix/store/j5c9cby4i29zsjgfkzz6vdhaiw7cc6ag-source/modules/steam-compat-tools.nix:7:14:

            6| with lib; let
            7|   steamCfg = config.programs.steam;
             |              ^
            8|   cfg = config.chaotic.steam;

Great, I'll make a module with it, but I'll add your instructions meanwhile.

Also, you can use with to shorten repeating our "full" path:

{ config, pkgs, chaotic, ... }:

{
  home.packages = with chaotic.packages.${pkgs.hostPlatform.system}; [
    fastfetch
    firedragon
  ];
}