Skip to content

nixos-generate-config does not set nixpkgs.system (purity, flakes) #177664

Closed

Description

@roberth

Describe the bug

Observing that

  • We try to avoid currentSystem these days.
  • The CPU platform is part of the hardware

it would seem logical to set nixpkgs.system in hardware-configuration.nix.

Steps To Reproduce

Steps to reproduce the behavior:

  1. apply flake.lib.nixosSystem: Allow nixpkgs.system to be set modularly; improve error message #177012
  2. write a flake with nixosSystem { modules = [ ./configuration.nix ./hardware-configuration.nix ]; }
  3. 💥

Expected behavior

hardware-configuration.nix records the system.

Additional context

I tried to perl, but I can't. I was almost there.

nixos-generate-config.pl:

# nixpkgs.system
my ($status, @systemLines) = runCommand("nix-instantiate --impure --eval --expr builtins.currentSystem");
if ($status != 0 || join("", @systemLines) =~ /error/) {
    die "Failed to retrieve current system type from nix.\n";
}
my $system = chomp(@systemLines[0]);
push @attrs, "nixpkgs.system = lib.mkDefault $system;";

It generates the following, if you would believe it.

  nixpkgs.system = lib.mkDefault 1;

Notify maintainers

Many people maintain NixOS. I know @grahamc knows perl.

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
output here

Activity

  1. added
    0.kind: bug
    6.topic: nixos
    6.topic: user experience
    on Jun 14, 2022
  2. pennae commented on Jun 15, 2022

    @pennae
    Contributor

    chomp(my $system = $systemLines[0]); should be the thing you're looking for? 🤔

  3. roberth commented on Jun 21, 2022

    @roberth
    MemberAuthor

    Thanks, pennae. I've incorporated your suggestion: 82da079

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    0.kind: bug6.topic: nixos6.topic: user experience

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions