Search code examples
nixnixos

How can I combine two lists in Nix?


I've currently got a list defined as:

   environment.systemPackages = with pkgs; [
     acpi
     ag
     alacritty
     audacity
     awscli
     bash
     breeze-gtk
     cabal-install
    ];

How would I go about defining two lists and then merging them to set the environment.systemPackages value?

I'd like to split the list so it's easier to manage groups of related packages.


Solution

  • From the Nix manual.

    The ++ list concatenation operator:

    nix-repl> [1 2 3]  ++ [5 6]
    [ 1 2 3 5 6 ]
    

    Code example:

    let
      unstable = import <unstable> {
        config = config.nixpkgs.config; 
      };
      examplePkgs = with pkgs; [
        bash
      ];
    in
    {
    
       environment.systemPackages = with pkgs; [
         google-chrome
       ]
       ++ examplePkgs;