# Nixos-rebuild-ng: a nixos-rebuild rewrite

**URL:** https://discourse.nixos.org/t/nixos-rebuild-ng-a-nixos-rebuild-rewrite/55606
**Category:** Announcements
**Created:** [November 6, 2024, 3:52pm UTC](https://discourse.nixos.org/t/nixos-rebuild-ng-a-nixos-rebuild-rewrite/55606 "2024-11-06T15:52:39Z")
**Posts on this page:** 20
**Page:** 3

<div class="post-metadata">

### Author: ![eblechschmidt](https://discourse.nixos.org/user_avatar/discourse.nixos.org/eblechschmidt/32/27398_2.png) [@eblechschmidt](https://discourse.nixos.org/u/eblechschmidt)
#### Post date: [March 1, 2025, 7:03am UTC](https://discourse.nixos.org/t/nixos-rebuild-ng-a-nixos-rebuild-rewrite/55606/41 "2025-03-01T07:03:25Z")

</div>

@k0kada thanks for the great work. I’m using it since several weeks without any issues remote building for different machines with different architectures. Especially just having to provide the sudo password once increases efficiency a lot.

---

<div class="post-metadata">

### Author: ![AngryAnt](https://discourse.nixos.org/user_avatar/discourse.nixos.org/angryant/32/9830_2.png) [@AngryAnt](https://discourse.nixos.org/u/AngryAnt)
#### Post date: [March 8, 2025, 11:24pm UTC](https://discourse.nixos.org/t/nixos-rebuild-ng-a-nixos-rebuild-rewrite/55606/42 "2025-03-08T23:24:13Z")

</div>

> [@k0kada](#):
>
> Replace `nix-copy-closure` with `nix copy`, that supports using `--to` and `--from` together. It is still kinda sub-optimal because instead of having `alice` talking directly with `bob`, now the connection between the two seems to be done in the eval machine (I tested this with a Chromebook and it was really slow because the Wi-Fi connection in my Chromebook is poor), but not sure there is much we can do (and `--use-substitutes` still exist for those cases). This also would mean that any usage of `--to` and `--from` would need a newer version of Nix, and we try to be compatible to `nix` 2.3 since some folks still depends on it

Worth noting that while this was sub optimal in that scenario, it is quite optimal in the scenario where you have an admin machine able to (temporarily) access both builder and destination, but network segmentation means they cannot access one-another.

---

<div class="post-metadata">

### Author: ![k0kada](https://discourse.nixos.org/user_avatar/discourse.nixos.org/k0kada/32/12502_2.png) [@k0kada](https://discourse.nixos.org/u/k0kada)
#### Post date: [June 11, 2025, 10:15am UTC](https://discourse.nixos.org/t/nixos-rebuild-ng-a-nixos-rebuild-rewrite/55606/43 "2025-06-11T10:15:19Z")

</div>

So a few weeks after release 25.05 the amount of bug reports was surprisingly small, so I think we should make `nixos-rebuild-ng` the default in release 25.11 as soon as possible so we can iron any last remaining issues: [nixos-rebuild-ng: enable by default by thiagokokada · Pull Request #415640 · NixOS/nixpkgs · GitHub](https://github.com/NixOS/nixpkgs/pull/415640).

---

<div class="post-metadata">

### Author: ![sdht](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/s/8e8cbc/32.png) [@sdht](https://discourse.nixos.org/u/sdht)
#### Post date: [June 12, 2025, 5:52pm UTC](https://discourse.nixos.org/t/nixos-rebuild-ng-a-nixos-rebuild-rewrite/55606/44 "2025-06-12T17:52:45Z")

</div>

Thanks for seeing this through to the end @k0kada!

---

<div class="post-metadata">

### Author: ![chrism](https://discourse.nixos.org/user_avatar/discourse.nixos.org/chrism/32/6689_2.png) [@chrism](https://discourse.nixos.org/u/chrism)
#### Post date: [July 4, 2025, 4:03pm UTC](https://discourse.nixos.org/t/nixos-rebuild-ng-a-nixos-rebuild-rewrite/55606/45 "2025-07-04T16:03:07Z")

</div>

I’ve been using this since the 25.05 release, both locally and with a remote target, and I haven’t noticed anything not working, FWIW.

---

<div class="post-metadata">

### Author: ![hgl](https://discourse.nixos.org/user_avatar/discourse.nixos.org/hgl/32/31305_2.png) [@hgl](https://discourse.nixos.org/u/hgl)
#### Post date: [July 6, 2025, 11:19am UTC](https://discourse.nixos.org/t/nixos-rebuild-ng-a-nixos-rebuild-rewrite/55606/46 "2025-07-06T11:19:11Z")

</div>

Feature request: could nixos-rebuild-ng implement auto-rollback for remote deployments? By that I mean: after a remote deployment, the remote machine becomes inaccessible from ssh, it should automatically rollback.

---

<div class="post-metadata">

### Author: ![k0kada](https://discourse.nixos.org/user_avatar/discourse.nixos.org/k0kada/32/12502_2.png) [@k0kada](https://discourse.nixos.org/u/k0kada)
#### Post date: [July 14, 2025, 8:17pm UTC](https://discourse.nixos.org/t/nixos-rebuild-ng-a-nixos-rebuild-rewrite/55606/47 "2025-07-14T20:17:50Z")

</div>

This looks more of a feature for `switch-to-configuration` than `nixos-rebuild`. And what I mean by that is by the time `nixos-rebuild` loses connection to the remote host there is nothing it can do, however since `switch-to-configuration` actually runs in the target host it could have a timeout parameter that rollbacks the configuration (you would need to have some test for network connectivity though).

---

<div class="post-metadata">

### Author: ![hgl](https://discourse.nixos.org/user_avatar/discourse.nixos.org/hgl/32/31305_2.png) [@hgl](https://discourse.nixos.org/u/hgl)
#### Post date: [July 16, 2025, 2:26pm UTC](https://discourse.nixos.org/t/nixos-rebuild-ng-a-nixos-rebuild-rewrite/55606/48 "2025-07-16T14:26:39Z")

</div>

That’s a valid point, although it would be impossible for `switch-to-configuration` to tell if it’s executed remotely. If it’s locally executed, it shouldn’t care if it breaks networking.

`nixos-rebuild` however do have this information, and even though by the time it loses connection to the remote host there is nothing it can do, I wonder if it makes sense for it to start a systemd unit that listens _before_ it loses the connection, and make the deploying machine connects to it after activation has done. If that unit doesn’t get a connection after a certain amount of time, it should rollback _automatically_.

---

<div class="post-metadata">

### Author: ![k0kada](https://discourse.nixos.org/user_avatar/discourse.nixos.org/k0kada/32/12502_2.png) [@k0kada](https://discourse.nixos.org/u/k0kada)
#### Post date: [July 16, 2025, 6:09pm UTC](https://discourse.nixos.org/t/nixos-rebuild-ng-a-nixos-rebuild-rewrite/55606/49 "2025-07-16T18:09:11Z")

</div>

It is not impossible for `switch-to-configuration` to know if it is executed remotely. We could just pass this via an environment variable or an additional argument to `switch-to-configuration`.

> `nixos-rebuild` however do have this information, and even though by the time it loses connection to the remote host there is nothing it can do, I wonder if it makes sense for it to start a systemd unit that listens before it loses the connection, and make the deploying machine connects to it after activation has done. If that unit doesn’t get a connection after a certain amount of time, it should rollback automatically.

PRs are welcome, but I still think this functionality makes more sense in `switch-to-configuration`.

---

<div class="post-metadata">

### Author: ![silverhikari](https://discourse.nixos.org/user_avatar/discourse.nixos.org/silverhikari/32/32892_2.png) [@silverhikari](https://discourse.nixos.org/u/silverhikari)
#### Post date: [July 19, 2025, 11:09pm UTC](https://discourse.nixos.org/t/nixos-rebuild-ng-a-nixos-rebuild-rewrite/55606/50 "2025-07-19T23:09:09Z")

</div>

Howdy,  
i have recently tried enabling nixos-rebuild-ng as it is going to be default in the next release, Though having an issue when adding and running nixos rebuild as it complains:

```auto
warning: Git not found: cannot figure out revision of '/nix/store/ng0wvv11id68mqf1cb2a3223gfyps4hf-nixos-25.05/nixos'

```

i am using a legacy configuration.nix build system with no global flakes.  
here is a link to the configuration.nix i use: [configuraation.nix - Pastebin.com](https://pastebin.com/Kg6c1LFj)

---

<div class="post-metadata">

### Author: ![waffle8946](https://discourse.nixos.org/user_avatar/discourse.nixos.org/waffle8946/32/27221_2.png) [@waffle8946](https://discourse.nixos.org/u/waffle8946)
#### Post date: [July 19, 2025, 11:27pm UTC](https://discourse.nixos.org/t/nixos-rebuild-ng-a-nixos-rebuild-rewrite/55606/51 "2025-07-19T23:27:08Z")

</div>

Wasn’t this already fixed in [[Backport release-25.05] nixos-rebuild-ng: do not resolve Flake by nixpkgs-ci[bot] · Pull Request #423283 · NixOS/nixpkgs · GitHub](https://github.com/NixOS/nixpkgs/pull/423283) (stable) / [nixos-rebuild-ng: do not resolve Flake by thiagokokada · Pull Request #422971 · NixOS/nixpkgs · GitHub](https://github.com/NixOS/nixpkgs/pull/422971) (unstable)? You sure you have your channels updated?

---

<div class="post-metadata">

### Author: ![silverhikari](https://discourse.nixos.org/user_avatar/discourse.nixos.org/silverhikari/32/32892_2.png) [@silverhikari](https://discourse.nixos.org/u/silverhikari)
#### Post date: [July 19, 2025, 11:52pm UTC](https://discourse.nixos.org/t/nixos-rebuild-ng-a-nixos-rebuild-rewrite/55606/52 "2025-07-19T23:52:50Z")

</div>

i have refreshed channels a few times since getting this error. how do i check what commit my channels are at?

EDIT: ran nix-info and i am on nixos-25.05.806427.32a4e80794210

EDIT2: also checked the revision of nixos-25.05 and the svn-revision is .806427.32a4e8794210

---

<div class="post-metadata">

### Author: ![k0kada](https://discourse.nixos.org/user_avatar/discourse.nixos.org/k0kada/32/12502_2.png) [@k0kada](https://discourse.nixos.org/u/k0kada)
#### Post date: [July 20, 2025, 12:36am UTC](https://discourse.nixos.org/t/nixos-rebuild-ng-a-nixos-rebuild-rewrite/55606/53 "2025-07-20T00:36:46Z")

</div>

> [@silverhikari](#):
>
> I have recently tried enabling nixos-rebuild-ng as it is going to be default in the next release, Though having an issue when adding and running nixos rebuild as it complains:
> 
> ``

This warning is self describing, your current configuration has no git installed and legacy configurations use it to get the revision.

It is not hugely important though so you can ignore (this is why this is a warning), or just add git to your config.

---

<div class="post-metadata">

### Author: ![silverhikari](https://discourse.nixos.org/user_avatar/discourse.nixos.org/silverhikari/32/32892_2.png) [@silverhikari](https://discourse.nixos.org/u/silverhikari)
#### Post date: [July 20, 2025, 12:39am UTC](https://discourse.nixos.org/t/nixos-rebuild-ng-a-nixos-rebuild-rewrite/55606/54 "2025-07-20T00:39:04Z")

</div>

alright, i thought git was only required if using a flake based system.

---

<div class="post-metadata">

### Author: ![bme](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@bme](https://discourse.nixos.org/u/bme)
#### Post date: [July 20, 2025, 11:15am UTC](https://discourse.nixos.org/t/nixos-rebuild-ng-a-nixos-rebuild-rewrite/55606/55 "2025-07-20T11:15:35Z")

</div>

Is the plan for this to go live like this? I mean the point of nix/nixos is to not have to care about this kind of thing? Why doesn’t nixos-rebuild-ng depend on git if it depends on git?

---

<div class="post-metadata">

### Author: ![arthsmn](https://discourse.nixos.org/user_avatar/discourse.nixos.org/arthsmn/32/12439_2.png) [@arthsmn](https://discourse.nixos.org/u/arthsmn)
#### Post date: [July 20, 2025, 11:42am UTC](https://discourse.nixos.org/t/nixos-rebuild-ng-a-nixos-rebuild-rewrite/55606/56 "2025-07-20T11:42:15Z")

</div>

It doesn’t depend on it, but it can use it if it’s available and the user is using a git repository to manage the nix config.

---

<div class="post-metadata">

### Author: ![waffle8946](https://discourse.nixos.org/user_avatar/discourse.nixos.org/waffle8946/32/27221_2.png) [@waffle8946](https://discourse.nixos.org/u/waffle8946)
#### Post date: [July 20, 2025, 12:31pm UTC](https://discourse.nixos.org/t/nixos-rebuild-ng-a-nixos-rebuild-rewrite/55606/57 "2025-07-20T12:31:30Z")

</div>

> [@bme](#):
>
> I mean the point of nix/nixos is to not have to care about this kind of thing?

No, that’s not the point of NixOS. The point is a distro based on nix’s concept of _correct deployments_.

`nixos-rebuild` has _always_ behaved different in the presence of a git repo.

`nixos-rebuild`:

> <https://github.com/NixOS/nixpkgs/blob/f0faa55136e9e16987814d6f432322df76411ed3/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh#L589-L593>

vs `nixos-rebuild-ng`:

> <https://github.com/NixOS/nixpkgs/blob/f0faa55136e9e16987814d6f432322df76411ed3/pkgs/by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/nix.py#L397-L408>

There’s even an issue from 5 years ago from a user who was confused by the warning:

> <https://github.com/NixOS/nixpkgs/issues/91199>
>
> \*\*Describe the bug\*\*
> 
> nixos-rebuild tries to use git, but it is not a dependen…cy
> 
> \`\`\`
> building '/nix/store/0jlghfnbhn57dlnlys0ywsbgaywqcrx9-nixos-rebuild.drv'...
> building Nix...
> warning: Git not found; cannot figure out revision of /home/davidak/nixpkgs
> building the system configuration...
> \`\`\`
> 
> \*\*To Reproduce\*\*
> Steps to reproduce the behavior:
> 1. git clone nixpkgs
> 2. remove git
> 3. \`nixos-rebuild switch -I nixpkgs=~/nixpkgs/\`
> 
> \*\*Expected behavior\*\*
> nixos-rebuild should be pure and not depend on manually installed dependencies
> 
> \*\*Additional context\*\*
> building from master, not a problem for users of channels
> 
> \*\*Metadata\*\*
> - system: \`"x86\_64-linux"\`
> - host os: \`Linux 5.4.46, NixOS, 20.09pre-git (Nightingale)\`
> - multi-user?: \`yes\`
> - sandbox: \`yes\`
> - version: \`nix-env (Nix) 2.3.6\`
> - channels(root): \`"nixos-20.09pre230335.9480bae3370"\`
> - nixpkgs: \`/nix/var/nix/profiles/per-user/root/channels/nixos\`
> 
> ;)
> 
> Maintainer information:
> \`\`\`yaml
> \# a list of nixpkgs attributes affected by the problem
> attribute:
> \# a list of nixos modules affected by the problem
> module:
> \`\`\`

And we don’t bundle git by default because people complain about how big it is.

EDIT: discussion found - [Feedback wanted: Enable git by default · Issue #325924 · NixOS/nixpkgs · GitHub](https://github.com/NixOS/nixpkgs/issues/325924)

---

<div class="post-metadata">

### Author: ![bme](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@bme](https://discourse.nixos.org/u/bme)
#### Post date: [July 20, 2025, 12:46pm UTC](https://discourse.nixos.org/t/nixos-rebuild-ng-a-nixos-rebuild-rewrite/55606/58 "2025-07-20T12:46:24Z")

</div>

> [@waffle8946](#):
>
> No, that’s not the point of NixOS. The point is a distro based on nix’s concept of _correct deployments_.

Silly me, I didn’t realise that correctly deployed software spits out warnings about missing dependencies. I’ll write that down to make sure I remember it.

> [@waffle8946](#):
>
> `nixos-rebuild` has _always_ behaved different in the presence of a git repo.

I hadn’t noticed this. That’s fair.

> [@arthsmn](#):
>
> It doesn’t depend on it, but it can use it if it’s available and the user is using a git repository to manage the nix config.

If it doesn’t depend on it, and it isn’t necessary for it to function correctly imo, a warning log is the wrong log. Now, I will grant that I didn’t realise this was _also_ the previous behaviour.

I’ll see if I can find some time this weekend to open an MR discussing removing the warning log. I’d personally demote it to debug, but info I could also see.

---

<div class="post-metadata">

### Author: ![waffle8946](https://discourse.nixos.org/user_avatar/discourse.nixos.org/waffle8946/32/27221_2.png) [@waffle8946](https://discourse.nixos.org/u/waffle8946)
#### Post date: [July 20, 2025, 12:50pm UTC](https://discourse.nixos.org/t/nixos-rebuild-ng-a-nixos-rebuild-rewrite/55606/59 "2025-07-20T12:50:42Z")

</div>

> [@bme](#):
>
> Silly me, I didn’t realise that correctly deployed software spits out warnings about missing dependencies. I’ll write that down to make sure I remember it.

We don’t have a good concept of optional dependencies in NixOS. If you want to improve the situation, do so.

Anyway, turns out there was an existing PR to try to get git into the installer ISOs but it stalled. So, here’s a followup to try to get this moving again.

> <https://github.com/NixOS/nixpkgs/pull/426916>
>
> closes #314424 and includes feedback from there
> fixes #325924
> 
> 
> 
> \## Things done
> …
> 
> 
> \- Built on platform:
> - \[\] x86\_64-linux
> - \[\] aarch64-linux
> - \[\] x86\_64-darwin
> - \[\] aarch64-darwin
> \- Tested, as applicable:
> - \[\] \[NixOS tests\] in \[nixos/tests\].
> - \[\] \[Package tests\] at \`passthru.tests\`.
> - \[\] Tests in \[lib/tests\] or \[pkgs/test\] for functions and "core" functionality.
> \- \[\] Ran \`nixpkgs-review\` on this PR. See \[nixpkgs-review usage\].
> \- \[\] Tested basic functionality of all binary files, usually in \`./result/bin/\`.
> \- Nixpkgs Release Notes
> - \[\] Package update: when the change is major or breaking.
> \- NixOS Release Notes
> - \[\] Module addition: when adding a new NixOS module.
> - \[\] Module update: when the change is significant.
> \- \[x\] Fits \[CONTRIBUTING.md\], \[pkgs/README.md\], \[maintainers/README.md\] and others READMEs.
> 
> \[NixOS tests\]: https://nixos.org/manual/nixos/unstable/index.html#sec-nixos-tests
> \[Package tests\]: https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md#package-tests
> \[nixpkgs-review usage\]: https://github.com/Mic92/nixpkgs-review#usage
> 
> \[CONTRIBUTING.md\]: https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md
> \[lib/tests\]: https://github.com/NixOS/nixpkgs/blob/master/lib/tests
> \[maintainers/README.md\]: https://github.com/NixOS/nixpkgs/blob/master/maintainers/README.md
> \[nixos/tests\]: https://github.com/NixOS/nixpkgs/blob/master/nixos/tests
> \[pkgs/README.md\]: https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md
> \[pkgs/test\]: https://github.com/NixOS/nixpkgs/blob/master/pkgs/test
> 
> \---
> 
> Add a :+1: \[reaction\] to \[pull requests you find important\].
> 
> \[reaction\]: https://github.blog/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/
> \[pull requests you find important\]: https://github.com/NixOS/nixpkgs/pulls?q=is%3Aopen+sort%3Areactions-%2B1-desc

---

<div class="post-metadata">

### Author: ![bme](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@bme](https://discourse.nixos.org/u/bme)
#### Post date: [July 20, 2025, 12:56pm UTC](https://discourse.nixos.org/t/nixos-rebuild-ng-a-nixos-rebuild-rewrite/55606/60 "2025-07-20T12:56:02Z")

</div>

> [@waffle8946](#):
>
> We don’t have a good concept of optional dependencies in NixOS.

That’s true. We could do with some kind of a module system, with options.

[Previous page](https://discourse.nixos.org/t/nixos-rebuild-ng-a-nixos-rebuild-rewrite/55606.md?page=2)

[Next page](https://discourse.nixos.org/t/nixos-rebuild-ng-a-nixos-rebuild-rewrite/55606.md?page=4)
