# Nixos-rebuild: How to specify configuration.nix when attempting to build/deploy remotely

**URL:** https://discourse.nixos.org/t/nixos-rebuild-how-to-specify-configuration-nix-when-attempting-to-build-deploy-remotely/30979
**Category:** Help
**Created:** [July 26, 2023, 9:55pm UTC](https://discourse.nixos.org/t/nixos-rebuild-how-to-specify-configuration-nix-when-attempting-to-build-deploy-remotely/30979 "2023-07-26T21:55:06Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![jeremiah.emmer](https://discourse.nixos.org/user_avatar/discourse.nixos.org/jeremiah.emmer/32/10117_2.png) [@jeremiah.emmer](https://discourse.nixos.org/u/jeremiah.emmer)
#### Post date: [July 27, 2023, 12:46am UTC](https://discourse.nixos.org/t/nixos-rebuild-how-to-specify-configuration-nix-when-attempting-to-build-deploy-remotely/30979/2 "2023-07-27T00:46:16Z")

</div>

I’ll leave this here for anyone having this particular issue.

Had I turned on verbose mode (`-v`) when running `nixos-rebuild`, I would’ve noticed that it went into “flake mode” almost immediately, because I had a flake.nix file sitting in /etc/nixos. The following command

`nixos-rebuild -I nixos-config=$(pwd)/configuration.nix --build-host user@remote_ip --target-host user@remote_ip --fast --use-remote-sudo switch -v`

produced the following output with an empty flake.nix file present in /etc/nixos

```auto
building the system configuration...
Building in flake mode.
$ nix --extra-experimental-features nix-command flakes eval --raw /etc/nixos#nixosConfigurations."SYSTEM_NAME".config.system.build.toplevel.drvPath -I nixos-config=/home/user/Templates/configuration.nix -v

```

In this example, it immediately failed, since I merely put an empty flake.nix file there. During previous runs it attempted to use my system flake and completely ignored the nixos-config setting that you can see above.

It seems like that **_may_** be a bug? I honestly don’t know enough to present it as such.

In any event, the initial command I expected to work (below), did actually work once I temporarily moved my /etc/nixos/flake.nix file somewhere else.

**Working command**  
`nixos-rebuild -I nixos-config=$(pwd)/configuration.nix --build-host user@remote_ip --target-host user@remote_ip --fast --use-remote-sudo switch`

**Example config**

```auto
{ config, pkgs, lib, ... }:

let
  hostname = "nixos";
  user = "nixos";
  timeZone = "America/New_York";
  defaultLocale = "en_US.UTF-8";
in {
  nix.settings.experimental-features = ["nix-command" "flakes"];
  nixpkgs = {
    hostPlatform = "aarch64-linux";
    config = {
      allowUnfree = true;
    };
  };

  boot = {
    kernelPackages = pkgs.linuxKernel.packages.linux_rpi4;
    initrd.availableKernelModules = ["xhci_pci" "usbhid" "usb_storage"];
    loader = {
      grub.enable = false;
      generic-extlinux-compatible.enable = true;
    };
  };

  fileSystems = {
    "/" = {
      device = "/dev/disk/by-label/NIXOS_SD";
      fsType = "ext4";
      options = ["noatime"];
    };
  };

  networking.hostName = hostname;

  environment.systemPackages = with pkgs; [
  ];

  services.openssh.enable = true;

  time.timeZone = timeZone;

  i18n = {
    defaultLocale = defaultLocale;
    extraLocaleSettings = {
      LC_ADDRESS = defaultLocale;
      LC_IDENTIFICATION = defaultLocale;
      LC_MEASUREMENT = defaultLocale;
      LC_MONETARY = defaultLocale;
      LC_NAME = defaultLocale;
      LC_NUMERIC = defaultLocale;
      LC_PAPER = defaultLocale;
      LC_TELEPHONE = defaultLocale;
      LC_TIME = defaultLocale;
    };
  };

  users = {
    mutableUsers = false;
    users."${user}" = {
      isNormalUser = true;
      hashedPassword = "!";
      extraGroups = ["wheel"];

      openssh.authorizedKeys.keys = [
        "ssh-ed25519 ..."
      ];
    };
  };

  security.sudo.extraRules= [
  {
    users = [user];
    commands = [
    {
      command = "ALL" ;
      options= ["NOPASSWD"];
    }];
  }];

  
  system.stateVersion = "23.05";
}

```

---

_[View the full topic](https://discourse.nixos.org/t/nixos-rebuild-how-to-specify-configuration-nix-when-attempting-to-build-deploy-remotely/30979)._
