Error building config with absolute path

I’m getting an error when I run nixos-rebuild switch -I nixos-config=./configuration.nix after moving my config to a new location
Config is below

{ config, pkgs, ... }:

{
  imports =
    [ # Include the results of the hardware scan.
      /home/drif/nixos-config/hardware-configuration.nix
    ];


  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;
  boot.zfs.extraPools = [ "kyogre" ];

  networking.hostName = "nixos"; # Define your hostname.

  networking.networkmanager.enable = true;

  time.timeZone = "America/Los_Angeles";


  i18n.defaultLocale = "en_US.UTF-8";

  i18n.extraLocaleSettings = {
    LC_ADDRESS = "en_US.UTF-8";
    LC_IDENTIFICATION = "en_US.UTF-8";
    LC_MEASUREMENT = "en_US.UTF-8";
    LC_MONETARY = "en_US.UTF-8";
    LC_NAME = "en_US.UTF-8";
    LC_NUMERIC = "en_US.UTF-8";
    LC_PAPER = "en_US.UTF-8";
    LC_TELEPHONE = "en_US.UTF-8";
    LC_TIME = "en_US.UTF-8";
  };

  services.xserver.enable = true;


  services.xserver.displayManager.lightdm.enable = true;
  services.xserver.desktopManager.xfce.enable = true;

  services.xserver.xkb = {
    layout = "us";
    variant = "";
  };

  hardware.pulseaudio.enable = false;
  security.rtkit.enable = true;
  services.pipewire = {
    enable = true;
    alsa.enable = true;
    alsa.support32Bit = true;
    pulse.enable = true;

  };


  users.users.drif = {
    isNormalUser = true;
    description = "drif";
    openssh.authorizedKeys.keys = [""];
    extraGroups = [ "networkmanager" "wheel" "docker" ];
    packages = with pkgs; [

    ];
  };

  users.users.corvi = {
    name = "corvi";
    isNormalUser = true;
    password = "corvi";
    extraGroups = [ "networkmanager" "wheel" "docker" ];
  };

  services.displayManager.autoLogin.enable = true;
  services.displayManager.autoLogin.user = "drif";

  nix.settings.experimental-features = [ "nix-command" ];

  # Install firefox.
  programs = {
    firefox.enable = true;
    tmux = {
      enable = true;
      historyLimit = 10000;
      extraConfig = ''
	set -g prefix C-a
	unbind C-b
	bind-key C-a send-prefix

	setw -g mode-keys vi
	set-option -s set-clipboard off
	set -s escape-time 100
	unbind % 
	unbind '"'
	unbind h 
	unbind j 
	unbind k 
	unbind l 
	bind -r h select-pane -L
	bind -r j select-pane -D
	bind -r k select-pane -U
	bind -r l select-pane -R
        bind | split-window -h -c "#{pane_current_path}"
        bind - split-window -v -c "#{pane_current_path}"
        bind c new-window -c "#{pane_current_path}"
      '';
    };
    zsh = {
      enable = true;
      autosuggestions.enable = true;
      enableCompletion = true;
      syntaxHighlighting.enable = true;
      enableLsColors = true;
      histSize = 10000;
      shellInit = ''
      export NIX_PATH=/home/drif/nixos-config/configuration.nix:$PATH
      '';

      shellAliases = {
        ll = "ls -l";
        check = "sudo nixos-rebuild dry-activate";
      };
      };
    bash = {
      enableCompletion = true;
      shellAliases = {
        ll = "ls -l";
        check = "sudo nixos-rebuild dry-activate";
      };
    };
  };


  nixpkgs.config.allowUnfree = true;

  environment.variables = {
    NIXOS_CONFIG = "home/drif/nixos-config/configuration.nix";
    TEST_VAR = "hello";
  };

  environment.systemPackages = with pkgs; [
    ((vim_configurable.override {}).customize{
      name = "vim";
      vimrcConfig.packages.myplugins = with pkgs.vimPlugins; {
        start = [ vim-nix vim-nixhash vim-addon-nix ];
        opt = [];
      };
      vimrcConfig.customRC = ''
      set rnu nu hlsearch spell
      syntax on
      set belloff=all
      set vb t_vb=
      set noerrorbells
      set noexpandtab
      set shiftwidth=2
      '';
    })
  wget
  lshw
  git
  zfs
  tmuxPlugins.yank
  tmuxPlugins.resurrect
  ];


  # List services that you want to enable:

  services.openssh.enable = true;
  security.sudo.extraRules = [{
    users = ["drif" "corvi"];
    commands = [{
      command = "ALL";
      options = ["NOPASSWD"];
    }];
  }];

  networking = {
    nat.enable = true;
    firewall = {
      allowedTCPPorts = [ 53 8080 ];
      allowedUDPPorts = [ 53 51280 6881 ];
    };
    wireguard = {
      enable = false;
    };
  };


  networking.hostId = "ab90add0";


  system.stateVersion = "24.05"; # Did you read the comment?

}

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: string 'home/drif/nixos-config/configuration.nix' doesn't represent an absolute path
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: string 'home/drif/nixos-config/configuration.nix' doesn't represent an absolute path
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: string 'home/drif/nixos-config/configuration.nix' doesn't represent an absolute path

Stop using absolute paths. Use relative ones and keep all your config in the same dir, it’s best practice.

1 Like

Issue was that when sudo is passed my environment isn’t. Since I changed my NIXOS_CONFIG path to be something else, using sudo wasn’t changing that. It was fixed with the sudo -E command