Hyprland: nixpkgs.hostPlatform not set

I want to use Nixos module with flakes to build Hyprland, while got error with nixpkgs.hostPlatform not set.

Command I execute: sudo nixos-rebuild switch --flake '.#aimi'

Output:

[sudo] password for aimi:
error: Neither nixpkgs.hostPlatform nor the legacy option nixpkgs.system has been set.
       You can set nixpkgs.hostPlatform in hardware-configuration.nix by re-running
       a recent version of nixos-generate-config.
       The option nixpkgs.system is still fully supported for NixOS 22.05 interoperability,
       but will be deprecated in the future, so we recommend to set nixpkgs.hostPlatform.
(use '--show-trace' to show detailed location information

Expect output: Everything is ok.

Other message: NixOS version: NixOS 22.11 nix version: nix (Nix) 2.11.1 flake.nix:

# hyprland flake.nix
{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    hyprland.url = "github:hyprwm/Hyprland";
  };

  outputs = {nixpkgs, hyprland, ...}: {
    nixosConfigurations.aimi = nixpkgs.lib.nixosSystem {
      # ...
      modules = [
        hyprland.nixosModules.default
        {programs.hyprland.enable = true;}
        # ...
      ];
    };
  };
}

(the sample one in wiki)

flake.nix place: /etc/nixos/env/hyprland/flake.nix I run command in /etc/nixos/env/hyprland/

I checked my hardware-configuration.nix and fount nixpkgs.hostPlatform is ok: nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; And I’ve tried nixos-generate-config, still this error. Is this my personal environment bug?

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 15 (3 by maintainers)

Most upvoted comments

If you’re putting flake.nix and configuration.nix in the same place, make sure to import configuration.nix in flake.nix

Do you mind clarifying what you mean here? I am new to NixOS and can’t find an obvious way to import the configuration.nix in to the flake.nix.

Thanks!

Just add it to your nixosConfiguration modules is ok. such as this one (original flake comes from Hyprland Wiki)

# hyprland flake.nix
{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    hyprland.url = "github:hyprwm/Hyprland";
  };

  outputs = {nixpkgs, hyprland, ...}: {
    nixosConfigurations.aimi = nixpkgs.lib.nixosSystem {
      # ...
      modules = [
        hyprland.nixosModules.default
        {programs.hyprland.enable = true;}
        ./configuration.nix # Just like this, add the position of your configuration.nix to here
        # ...
      ];
    };
  };
}

Edit 2 Try adding this to your inputs

inputs.nixpkgs.follows = "nixpkgs";

Why, exactly? This means you no longer get cache hits.

Adding inputs.nixpkgs.follows = "nixpkgs"; to my flake file resulted in the following error

error: stack overflow (possible infinite recursion)

Edit because I’m dumb Is hardware-configuration.nix actually being imported by your flake? Running nixos-generate-config wouldn’t fix anything if /etc/nixos/hardware-configuration.nix isn’t actually imported by the flake.

Edit 2 Try adding this to your inputs

inputs.nixpkgs.follows = "nixpkgs";

Original Message: Do you have something like this in hardware-configuration.nix?

nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";