Search code examples
nixnixos

nix: where does the system variable get populated from?


In my flake.nix I have:

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

  outputs = {
    self, nixpkgs, disko, ...} @ inputs: {
    nixosConfigurations.HostName = nixpkgs.lib.nixosSystem {
      specialArgs = {inherit inputs;};
      modules = [
        ./hosts/HostName/configuration.nix
        inputs.home-manager.nixosModules.default
        disko.nixosModules.disko
      ];
    };
}

In configuration.nix I can access the current system like this:

{
  config,
  pkgs,
  inputs,
  scripts,
  ...
}: {
  <snip>

  environment.systemPackages = with pkgs; [
    inputs.scripts.packages.${system}.fooScript
    ];
}

But I don't understand how this works. Where does system come from, since I don't pass it in to the module?


Solution

  • It comes from pkgs, thanks to the with pkgs statement that you wrote.

    You should replace system with pkgs.system to make your code clearer; then you can remove with pkgs.