How to make the `let` keyword work in the config.nix?

That’s what I’ve tried to add to my config:

let 
    nixvim = import (builtins.fetchGit {
        url = "https://github.com/nix-community/nixvim";
        # When using a different channel you can use `ref = "nixos-<version>"` to set it here
    });
in

That’s the Error:

error:
       … while evaluating the attribute 'config'

         at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:322:9:

          321|         options = checked options;
          322|         config = checked (removeAttrs config [ "_module" ]);
             |         ^
          323|         _module = checked (config._module);

       … while calling the 'seq' builtin

         at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:322:18:

          321|         options = checked options;
          322|         config = checked (removeAttrs config [ "_module" ]);
             |                  ^
          323|         _module = checked (config._module);

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: syntax error, unexpected LET

       at /home/azrael/dotfiles/configuration.nix:6:3:

            5|   ];
            6|   let
             |   ^
            7|     nixvim = import (builtins.fetchGit {
building Nix...
error:
       … while evaluating the attribute 'config'

         at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:322:9:

          321|         options = checked options;
          322|         config = checked (removeAttrs config [ "_module" ]);
             |         ^
          323|         _module = checked (config._module);

       … while calling the 'seq' builtin

         at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:322:18:

          321|         options = checked options;
          322|         config = checked (removeAttrs config [ "_module" ]);
             |                  ^
          323|         _module = checked (config._module);

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: syntax error, unexpected LET

       at /home/azrael/dotfiles/configuration.nix:6:3:

            5|   ];
            6|   let
             |   ^
            7|     nixvim = import (builtins.fetchGit {
building the system configuration...
error:
       … while evaluating the attribute 'config.system.build.toplevel'

         at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:322:9:

          321|         options = checked options;
          322|         config = checked (removeAttrs config [ "_module" ]);
             |         ^
          323|         _module = checked (config._module);

       … while calling the 'seq' builtin

         at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:322:18:

          321|         options = checked options;
          322|         config = checked (removeAttrs config [ "_module" ]);
             |                  ^
          323|         _module = checked (config._module);

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: syntax error, unexpected LET

       at /home/azrael/dotfiles/configuration.nix:6:3:

            5|   ];
            6|   let
             |   ^
            7|     nixvim = import (builtins.fetchGit {

I have followed the installation instructions for Nixvim as described in the official documentation. What am I doing wrong?

You may need to share your whole config.nix before someone can really say for sure how correct the syntax, but:

The error message indicates that you’re trying to use let after a semicolon, and a semicolon terminates each key-value pair in an attrset. If you’re in an attrset, nix is expecting either a key (some_identifier = or the end of the attrset (}) to come next.

3 Likes
{ config, pkgs, builtins,stdenv, ... }:
let
  nixvim = import (builtins.fetchGit {
    url = "https://github.com/nix-community/nixvim";
    # If you are not running an unstable channel of nixpkgs, select the corresponding branch of nixvim.
    # ref = "nixos-23.05";
  });
in
{
  imports = [
    /etc/nixos/hardware-configuration.nix
    nixvim.nixosModules.nixvim
  ];
        # When using a different channel you can use `ref = "nixos-<version>"` to set it here
  nix={
    gc = {
      automatic = true;
      dates = "daily";
    };
    settings.auto-optimise-store=true;
  };

  # paste your boot config here...
  boot.loader = {
    systemd-boot.enable = true;
    efi.canTouchEfiVariables = true;
    };

  virtualisation.docker.enable = true;
  networking = {
    firewall = {
      enable = true;
      allowedTCPPorts = [];
      allowedUDPPorts = [];
    };
    hostName = "Azrael";
    networkmanager.enable = true;
  };

  # edit as per your location and timezone
  time.timeZone = "Europe/Berlin";

  i18n = {
    defaultLocale = "en_GB.UTF-8";
    extraLocaleSettings = {
      LC_ADDRESS = "de_DE.UTF-8";
      LC_IDENTIFICATION = "de_DE.UTF-8";
      LC_MEASUREMENT = "de_DE.UTF-8";
      LC_MONETARY = "de_DE.UTF-8";
      LC_NAME = "de_DE.UTF-8";
      LC_NUMERIC = "de_DE.UTF-8";
      LC_PAPER = "de_DE.UTF-8";
      LC_TELEPHONE = "de_DE.UTF-8";
      LC_TIME = "de_DE.UTF-8";
      LC_CTYPE="en_US.utf8"; # required by dmenu don't change this
    };
  };

  sound.enable = true;

	services = {

	  printing.enable = true;

	  xserver = {
	    xkb={
	      layout = "eu";
	      variant = "";
	      };
      libinput.enable = true;
	    enable = true;
	    windowManager.i3 = {
	      enable = true;
	      };
      desktopManager = {
		    xterm.enable = true;
		    xfce = {
		      enable = true;
		      noDesktop = true;
		      enableXfwm = false;
		    };
	    };
	    displayManager = {
		    lightdm.enable = true;
		    defaultSession = "xfce+i3";
	    };
	  }; # xserver
	    gvfs.enable = true;
	    gnome.gnome-keyring.enable = true;
	    blueman.enable = true;
	    pipewire = {
	      enable = true;
	      alsa = {
		      enable = true;
		      support32Bit = true;
	      };
	      pulse.enable = true;
	    };
	  };
	  nixpkgs = {
	    config = {
	      allowUnfree = true;
	      pulseaudio = true;
	    };
	  };

	  users.users.azrael = {
	    isNormalUser = true;
	    description = "azrael";
	    extraGroups = [ "networkmanager" "wheel" "docker" ];
	  }; # services

	environment = {
	  variables= {
	    SRC_ENDPOINT = "https://sourcegraph.example.com";
	    SRC_SRC_ACCESS_TOKEN="'cat ${config.users.users.azrael.home}/sourcegraphToken'";
	  };
	  systemPackages = with pkgs; [
	    alacritty
      catimg
      curl
	    cargo
	    clang
	    dmenu
	    docker
	    firefox
	    fuse
	    gcc
      git
      gimp
	    gnome.gnome-keyring
	    gr-framework
	    i3
	    i3status
	    inkscape
	    jabref
	    julia
	    just
	    kate
	    lazygit
	    libclang
	    nerdfonts
      networkmanagerapplet
	    neovim
	    nitrogen
	    pasystray
	    obsidian
	    openjdk
	    openscad-unstable
	    picom
	    pkg-config
	    polkit_gnome
	    pulseaudioFull
	    python311
	    python311Packages.polars
	    python311Packages.numpy
      python311Packages.scipy
      python311Packages.pip
      rofi
	    roboto
	    rustc
	    rustup
	    steam
	    tectonic
	    thunderbird
	    unrar
	    unzip
	    ucs-fonts
	    vcstool
	    vim
	    vscode
	    wget
	    xclip
	    xorg.xhost
	    xorg.libX11
	    x11docker
	    zip
	    (vscode-with-extensions.override {
        vscodeExtensions = with vscode-extensions; [
          bbenoist.nix
          ms-azuretools.vscode-docker
          ms-python.python
          ms-toolsai.jupyter
          ms-toolsai.jupyter-keymap
          ms-toolsai.jupyter-renderers
          ms-toolsai.vscode-jupyter-slideshow
          ms-toolsai.vscode-jupyter-cell-tags
          ms-vscode-remote.remote-ssh
          serayuzgur.crates
          tamasfe.even-better-toml
          ] ++ pkgs.vscode-utils.extensionsFromVscodeMarketplace [{
            name = "remote-ssh-edit";
            publisher = "ms-vscode-remote";
            version = "0.47.2";
            sha256 = "1hp6gjh4xp2m1xlm1jsdzxw9d8frkiidhph6nvl24d0h8z34w49g";
          }];
      })
	  ];
  }; # environment

	programs = {
    thunar.enable = true;
	  dconf.enable = true;
	  bash.shellAliases = {
	    sudo="sudo ";
	    sshEval="eval $(ssh-agent -s)";
	    nixos_list_generations="sudo nix-env --list-generations --profile /nix/var/nix/profiles/system";
	    nixosRebuild="sudo nixos-rebuild switch";
	    dockerRmContainters="docker ps -a | awk '{print $NF}' | while read -r container_name; do docker rm $container_name; done";
	    dockerRmImages="docker image ls --quiet --no-trunc | while read -r image_id; do docker image rm $image_id; done";
	    	  };
	  git.enable = true;
	  neovim = {
	    enable = true;
	    defaultEditor = true;
	  };
	  steam = {
	    enable = true;
	    remotePlay.openFirewall = true;
	    dedicatedServer.openFirewall = true;
	  }; 
	};

	security = {
    polkit.enable = true;
	  rtkit.enable = true;
  };

  systemd={
    tmpfiles.settings = {
      "ros2_docker_folders" = {
        "${config.users.users.azrael.home}/ros2_ws/src" = {d.mode = "0777";};
        "${config.users.users.azrael.home}/microros_ws/src" = {d.mode = "0777";};
        "${config.users.users.azrael.home}/ros2_debug/src"= {d.mode = "0777";};
      };
      "projects_folders"={
        "${config.users.users.azrael.home}/projects"= {d.mode = "0777";};
        "${config.users.users.azrael.home}/projects/rust"= {d.mode = "0777";};
        "${config.users.users.azrael.home}/projects/julia"= {d.mode = "0777";};
        "${config.users.users.azrael.home}/projects/python"= {d.mode = "0777";};
        "${config.users.users.azrael.home}/projects/latex"= {d.mode = "0777";};
        "${config.users.users.azrael.home}/projects/java"= {d.mode = "0777";};
      };
    };
    user.services.polkit-gnome-authentication-agent-1 = {
      description = "polkit-gnome-authentication-agent-1";
      wantedBy = [ "graphical-session.target" ];
      wants = [ "graphical-session.target" ];
      after = [ "graphical-session.target" ];
      serviceConfig = {
        Type = "simple";
        ExecStart =
          "${pkgs.polkit_gnome}/libexec/polkit-gnome-authentication-agent-1";
        Restart = "on-failure";
        RestartSec = 1;
        TimeoutStopSec = 10;
      };
    };
  };
  
  hardware.bluetooth.enable = true;

  # Don't touch this
  system={
    activationScripts={
    script.text =
    ''
       echo "Udo!"
    '';
    };
    stateVersion = "unstable";
    };
}
sudo nixos-rebuild switch 
[sudo] password for azrael: 
error:
       … while evaluating the attribute 'config'

         at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:322:9:

          321|         options = checked options;
          322|         config = checked (removeAttrs config [ "_module" ]);
             |         ^
          323|         _module = checked (config._module);

       … while calling the 'seq' builtin

         at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:322:18:

          321|         options = checked options;
          322|         config = checked (removeAttrs config [ "_module" ]);
             |                  ^
          323|         _module = checked (config._module);

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: infinite recursion encountered

       at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:508:28:

          507|         builtins.addErrorContext (context name)
          508|           (args.${name} or config._module.args.${name})
             |                            ^
          509|       ) (lib.functionArgs f);
building Nix...
error:
       … while evaluating the attribute 'config'

         at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:322:9:

          321|         options = checked options;
          322|         config = checked (removeAttrs config [ "_module" ]);
             |         ^
          323|         _module = checked (config._module);

       … while calling the 'seq' builtin

         at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:322:18:

          321|         options = checked options;
          322|         config = checked (removeAttrs config [ "_module" ]);
             |                  ^
          323|         _module = checked (config._module);

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: infinite recursion encountered

       at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:508:28:

          507|         builtins.addErrorContext (context name)
          508|           (args.${name} or config._module.args.${name})
             |                            ^
          509|       ) (lib.functionArgs f);
building the system configuration...
error:
       … while evaluating the attribute 'config.system.build.toplevel'

         at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:322:9:

          321|         options = checked options;
          322|         config = checked (removeAttrs config [ "_module" ]);
             |         ^
          323|         _module = checked (config._module);

       … while calling the 'seq' builtin

         at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:322:18:

          321|         options = checked options;
          322|         config = checked (removeAttrs config [ "_module" ]);
             |                  ^
          323|         _module = checked (config._module);

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: infinite recursion encountered

       at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:508:28:

          507|         builtins.addErrorContext (context name)
          508|           (args.${name} or config._module.args.${name})
             |                            ^
          509|       ) (lib.functionArgs f);

The let statement itself works now. Importing it to the config doesn’t…

1 Like

builtins is part of the nix language, not a module argument, remove it from the parameters on line one

1 Like