How to set same list as value of multiple fields on configuration.nix?

Is there a way to set a single list as value of diff parameters in configuration.nix? preferably without loading it from a file or using map

Use a let binding:

let foo = "bar"; in
{
  hostname = foo;
  username = foo;
  homefolder = "/home/${foo}";
}

or am I totally misunderstanding your question?

2 Likes

I think you can use let in this case:

{ inputs, lib, config, pkgs, ... }:  let 
  foo = ["x", "y", "z"];
in {
  bar = foo;
  baz = foo;
}

See the manual, or the pill for more info.

1 Like
  xdg.mime.defaultApplications = {
    let foo = [
      "sublime_text.desktop"
      "code.desktop"
      "org.kde.kate.desktop"
      "neovide.desktop"
      "micro.desktop"
      "emacs.desktop"
      "emacsclient.desktop"
    ];
    in {
      "text/x-python" = foo;
      "text/x-python3" = foo;
    }
  };

so this should work? Im getting the following error using it @LoganWalls

error: syntax error, unexpected LET

       at /etc/nixos/configuration.nix:776:5:

          775|   xdg.mime.defaultApplications = {
          776|     let foo = [
             |     ^
          777|       "sublime_text.desktop"
(use '--show-trace' to show detailed location information)

OH, I guess I fixed it:

  xdg.mime.defaultApplications = 
    let foo = 
      [
        "sublime_text.desktop"
        "code.desktop"
        "org.kde.kate.desktop"
        "neovide.desktop"
        "micro.desktop"
        "emacs.desktop"
        "emacsclient.desktop"
      ]; 
      in {

        "text/x-python" = foo;
        "text/x-python3" = foo;
        "text/org" = [
          "emacs.desktop"
          "emacsclient.desktop"
        ];
      }

Thanks for everyone’s help