# Need help on failure of building my configuration

**URL:** https://discourse.nixos.org/t/need-help-on-failure-of-building-my-configuration/16842
**Category:** Help
**Created:** [December 28, 2021, 7:47pm UTC](https://discourse.nixos.org/t/need-help-on-failure-of-building-my-configuration/16842 "2021-12-28T19:47:49Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![schuelermine](https://discourse.nixos.org/user_avatar/discourse.nixos.org/schuelermine/32/28728_2.png) [@schuelermine](https://discourse.nixos.org/u/schuelermine)
#### Post date: [December 28, 2021, 7:47pm UTC](https://discourse.nixos.org/t/need-help-on-failure-of-building-my-configuration/16842/1 "2021-12-28T19:47:49Z")

</div>

I got a confusing error after doing `sudo nixos-rebuild switch` for my flake-based configuration.

> **Click to expand**
>
> ```auto
> building the system configuration...
> Traceback (most recent call last):
> File "/nix/store/w9wk3m6aczb3v9nwj775n269ziw29z9b-systemd-boot", line 278, in main
> write_entry(*gen, machine_id)
> File "/nix/store/w9wk3m6aczb3v9nwj775n269ziw29z9b-systemd-boot", line 116, in write_entry
> kernel = copy_from_profile(profile, generation, specialisation, "kernel")
> File "/nix/store/w9wk3m6aczb3v9nwj775n269ziw29z9b-systemd-boot", line 90, in copy_from_profile
> copy_if_not_exists(store_file_path, "/boot%s" % (efi_file_path))
> File "/nix/store/w9wk3m6aczb3v9nwj775n269ziw29z9b-systemd-boot", line 25, in copy_if_not_exists
> shutil.copyfile(source, dest)
> File "/nix/store/k0z9n599k02hab8qjjp3ljw065iwjcvg-python3-3.9.6/lib/python3.9/shutil.py", line 264, in copyfile
> with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
> FileNotFoundError: [Errno 2] No such file or directory: '/nix/store/a1ycypk68q92m30dngkvk3wjrf68b71d-apostrophe-2.5/kernel'
> 
> During handling of the above exception, another exception occurred:
> 
> Traceback (most recent call last):
> File "/nix/store/w9wk3m6aczb3v9nwj775n269ziw29z9b-systemd-boot", line 314, in <module>
> main()
> File "/nix/store/w9wk3m6aczb3v9nwj775n269ziw29z9b-systemd-boot", line 284, in main
> print("ignoring profile '{}' in the list of boot entries because of the following error:\n{}".format(profile, e), file=sys.stderr)
> UnboundLocalError: local variable 'profile' referenced before assignment
> warning: error(s) occurred while switching to the new configuration
> 
> ```

I’m running (Nix) 2.6.0pre20211217\_6e6e998.

This error is very weird and it sounds like something in Nix’s state or store is in an unexpected configuration. Apostrophe is only specified in my home configuration (managed with home-manager), not my system configuration.  
I previously tried building an alternate version of Apostrophe via nix-repl, and was somewhat surprised by the behaviour. I imported my /etc/nixos flake and then used `pkgs = inputs.nixos.legacyPackages.x86_64-linux`, and was surprised when autocompleting “legacyPackages” caused a (re?-)download of nixpkgs. Maybe something was mistakenly overridden.

I’ve run `nix doctor` to no avail.

You can find my NixOS configuration here: [GitHub - schuelermine/configuration](https://github.com/schuelermine/nixos-configuration)  
You can find my home-manager configuration here: [GitHub - schuelermine/home-manager-configuration](https://github.com/schuelermine/home-manager-configuration)

---

<div class="post-metadata">

### Author: ![schuelermine](https://discourse.nixos.org/user_avatar/discourse.nixos.org/schuelermine/32/28728_2.png) [@schuelermine](https://discourse.nixos.org/u/schuelermine)
#### Post date: [December 28, 2021, 7:51pm UTC](https://discourse.nixos.org/t/need-help-on-failure-of-building-my-configuration/16842/2 "2021-12-28T19:51:02Z")

</div>

Please do not suggest upgrading to the newest nixpkgs and rebuilding everything, I doubt that’ll help and it’s not an option in my current situation because my internet connection at my current location is metered and I can’t do an 11GiB download. Regardless, it’d be nice to know where this error is coming from…

---

<div class="post-metadata">

### Author: ![ElvishJerricco](https://discourse.nixos.org/user_avatar/discourse.nixos.org/elvishjerricco/32/984_2.png) [@ElvishJerricco](https://discourse.nixos.org/u/ElvishJerricco)
#### Post date: [December 28, 2021, 8:16pm UTC](https://discourse.nixos.org/t/need-help-on-failure-of-building-my-configuration/16842/3 "2021-12-28T20:16:35Z")

</div>

This is the second time I’ve seen something similar in the past couple days; the other time was with someone on matrix, with a different package than `apostrophe`

I think somehow you’ve ended up with a package _other than_ your system configuration set as your `system` profile (`readlink -f /nix/var/nix/profiles/system`). I’m not sure how this is happening. Are you sure that `nix show-derivation .#nixosConfigurations.HOSTNAME.config.system.build.toplevel` is a nixos config?

EDIT: [Here’s the person on matrix discovering this problem](https://matrix.to/#/!KqkRjyTEzAGRiZFBYT:nixos.org/%24ZaDMZR65MIdTj9INHWShgyIF1Lsvz9uoGl-efW6Tpcw?via=nixos.org&via=matrix.org&via=nixos.dev).

---

<div class="post-metadata">

### Author: ![schuelermine](https://discourse.nixos.org/user_avatar/discourse.nixos.org/schuelermine/32/28728_2.png) [@schuelermine](https://discourse.nixos.org/u/schuelermine)
#### Post date: [December 29, 2021, 6:16pm UTC](https://discourse.nixos.org/t/need-help-on-failure-of-building-my-configuration/16842/4 "2021-12-29T18:16:53Z")

</div>

`/etc/nixos#nixosConfigurations.buggeryyacht-nixos.config.system.build.toplevel` is `«derivation /nix/store/aaplprbz9a0gq43k9dp4wdb8c84vyp6m-nixos-system-buggeryyacht-nixos-22.05.20211225.cb372c3.drv»`.

---

<div class="post-metadata">

### Author: ![schuelermine](https://discourse.nixos.org/user_avatar/discourse.nixos.org/schuelermine/32/28728_2.png) [@schuelermine](https://discourse.nixos.org/u/schuelermine)
#### Post date: [December 29, 2021, 6:18pm UTC](https://discourse.nixos.org/t/need-help-on-failure-of-building-my-configuration/16842/5 "2021-12-29T18:18:27Z")

</div>

```auto
anselmschueler@buggeryyacht-nixos /n/s/7np998x1qv79pm0l8zpwm1b35fm6dk8f-nixos-system-buggeryyacht-nixos-22.05.20211225.cb372c3> pwd
/nix/store/7np998x1qv79pm0l8zpwm1b35fm6dk8f-nixos-system-buggeryyacht-nixos-22.05.20211225.cb372c3
anselmschueler@buggeryyacht-nixos /n/s/7np998x1qv79pm0l8zpwm1b35fm6dk8f-nixos-system-buggeryyacht-nixos-22.05.20211225.cb372c3> ls
activate bin dry-activate extra-dependencies init initrd kernel-modules nixos-version sw systemd
append-initrd-secrets configuration-name etc firmware init-interface-version kernel kernel-params specialisation system  
anselmschueler@buggeryyacht-nixos /n/s/7np998x1qv79pm0l8zpwm1b35fm6dk8f-nixos-system-buggeryyacht-nixos-22.05.20211225.cb372c3> 

```

---

<div class="post-metadata">

### Author: ![schuelermine](https://discourse.nixos.org/user_avatar/discourse.nixos.org/schuelermine/32/28728_2.png) [@schuelermine](https://discourse.nixos.org/u/schuelermine)
#### Post date: [December 29, 2021, 6:20pm UTC](https://discourse.nixos.org/t/need-help-on-failure-of-building-my-configuration/16842/6 "2021-12-29T18:20:49Z")

</div>

Hmm, I tried running the config’s `./activate`… I didn’t get an error. Maybe something is wrong with this version of `nixos-rebuild`?

---

<div class="post-metadata">

### Author: ![ElvishJerricco](https://discourse.nixos.org/user_avatar/discourse.nixos.org/elvishjerricco/32/984_2.png) [@ElvishJerricco](https://discourse.nixos.org/u/ElvishJerricco)
#### Post date: [December 29, 2021, 6:22pm UTC](https://discourse.nixos.org/t/need-help-on-failure-of-building-my-configuration/16842/7 "2021-12-29T18:22:27Z")

</div>

Note, you’re probably supposed to run `bin/switch-to-configuration switch`, not `activate` 😛 Anway, yea I think there must be some bug in nixos-rebuild that causes it to sometimes set the system profile to the wrong thing. Doesn’t really make sense, but that’s all I can think of.

EDIT: Also note that just switching to the configuration won’t fix the system profile pointing to the wrong thing. `readlink -f /nix/var/nix/profiles/system` to verify it’s pointing to something wrong, then rollback the generation and delete the bad one.

---

<div class="post-metadata">

### Author: ![schuelermine](https://discourse.nixos.org/user_avatar/discourse.nixos.org/schuelermine/32/28728_2.png) [@schuelermine](https://discourse.nixos.org/u/schuelermine)
#### Post date: [December 29, 2021, 6:23pm UTC](https://discourse.nixos.org/t/need-help-on-failure-of-building-my-configuration/16842/8 "2021-12-29T18:23:00Z")

</div>

…but it only spat out `setting up /etc... `

---

<div class="post-metadata">

### Author: ![ElvishJerricco](https://discourse.nixos.org/user_avatar/discourse.nixos.org/elvishjerricco/32/984_2.png) [@ElvishJerricco](https://discourse.nixos.org/u/ElvishJerricco)
#### Post date: [December 29, 2021, 6:24pm UTC](https://discourse.nixos.org/t/need-help-on-failure-of-building-my-configuration/16842/9 "2021-12-29T18:24:13Z")

</div>

That would be because of the `switch-to-configuration` thing. Activation is only a subset of `switch-to-configuration`.

---

<div class="post-metadata">

### Author: ![schuelermine](https://discourse.nixos.org/user_avatar/discourse.nixos.org/schuelermine/32/28728_2.png) [@schuelermine](https://discourse.nixos.org/u/schuelermine)
#### Post date: [December 29, 2021, 6:27pm UTC](https://discourse.nixos.org/t/need-help-on-failure-of-building-my-configuration/16842/10 "2021-12-29T18:27:59Z")

</div>

I see. I tried `./bin/switch-to-configuration` and got the same error. Why is it trying to do anything with `/nix/store/a1ycypk68q92m30dngkvk3wjrf68b71d-apostrophe-2.5/kernel`?

Also, the error

```auto
Traceback (most recent call last):
  File "/nix/store/w9wk3m6aczb3v9nwj775n269ziw29z9b-systemd-boot", line 314, in <module>
    main()
  File "/nix/store/w9wk3m6aczb3v9nwj775n269ziw29z9b-systemd-boot", line 284, in main
    print("ignoring profile '{}' in the list of boot entries because of the following error:\n{}".format(profile, e), file=sys.stderr)
UnboundLocalError: local variable 'profile' referenced before assignment

```

is concerning…

---

<div class="post-metadata">

### Author: ![ElvishJerricco](https://discourse.nixos.org/user_avatar/discourse.nixos.org/elvishjerricco/32/984_2.png) [@ElvishJerricco](https://discourse.nixos.org/u/ElvishJerricco)
#### Post date: [December 29, 2021, 6:34pm UTC](https://discourse.nixos.org/t/need-help-on-failure-of-building-my-configuration/16842/11 "2021-12-29T18:34:24Z")

</div>

I think what happens is that the systemd-boot installation script goes through all the generations of the system profile and configures boot entries for them. So if any generation doesn’t point to a nixos configuration, then it’ll error because e.g. there’s no kernel in the output. Then this just cascades to other error messages like the `local variable 'profile'` one.

All that is to say: You need to delete the generation that is pointing to something that isn’t a nixos configuration. You can use `readlink /nix/var/nix/profiles/system-*` to figure out which one it is.

---

<div class="post-metadata">

### Author: ![schuelermine](https://discourse.nixos.org/user_avatar/discourse.nixos.org/schuelermine/32/28728_2.png) [@schuelermine](https://discourse.nixos.org/u/schuelermine)
#### Post date: [December 29, 2021, 6:37pm UTC](https://discourse.nixos.org/t/need-help-on-failure-of-building-my-configuration/16842/12 "2021-12-29T18:37:01Z")

</div>

That sounds plausible. I just tried doing `switch-to-configuration test` and it worked fine.

---

<div class="post-metadata">

### Author: ![ElvishJerricco](https://discourse.nixos.org/user_avatar/discourse.nixos.org/elvishjerricco/32/984_2.png) [@ElvishJerricco](https://discourse.nixos.org/u/ElvishJerricco)
#### Post date: [December 29, 2021, 6:37pm UTC](https://discourse.nixos.org/t/need-help-on-failure-of-building-my-configuration/16842/13 "2021-12-29T18:37:16Z")

</div>

Right, because that doesn’t run the systemd-boot installation stuff.

---

<div class="post-metadata">

### Author: ![schuelermine](https://discourse.nixos.org/user_avatar/discourse.nixos.org/schuelermine/32/28728_2.png) [@schuelermine](https://discourse.nixos.org/u/schuelermine)
#### Post date: [December 29, 2021, 6:37pm UTC](https://discourse.nixos.org/t/need-help-on-failure-of-building-my-configuration/16842/14 "2021-12-29T18:37:32Z")

</div>

OK, yeah, that’s what it is.

```auto
anselmschueler@buggeryyacht-nixos /e/nixos (b0) [1]> readlink /nix/var/nix/profiles/system-*
/nix/store/6d8vqn0ihf9qan1fjngxa7hwz3nsfd2c-nixos-system-buggeryyacht-nixos-22.05.20211224.eac07ed
/nix/store/azks0jca0kn0ykmrfbj6an50vp8qldmf-nixos-system-buggeryyacht-nixos-22.05.20211225.cb372c3
/nix/store/7np998x1qv79pm0l8zpwm1b35fm6dk8f-nixos-system-buggeryyacht-nixos-22.05.20211225.cb372c3
/nix/store/a1ycypk68q92m30dngkvk3wjrf68b71d-apostrophe-2.5
/nix/store/7np998x1qv79pm0l8zpwm1b35fm6dk8f-nixos-system-buggeryyacht-nixos-22.05.20211225.cb372c3

```

---

<div class="post-metadata">

### Author: ![schuelermine](https://discourse.nixos.org/user_avatar/discourse.nixos.org/schuelermine/32/28728_2.png) [@schuelermine](https://discourse.nixos.org/u/schuelermine)
#### Post date: [December 29, 2021, 6:38pm UTC](https://discourse.nixos.org/t/need-help-on-failure-of-building-my-configuration/16842/15 "2021-12-29T18:38:07Z")

</div>

I’m guessing `nix-repl` building `apostrophe` somehow managed to replace that symlink? Weird…

---

<div class="post-metadata">

### Author: ![ElvishJerricco](https://discourse.nixos.org/user_avatar/discourse.nixos.org/elvishjerricco/32/984_2.png) [@ElvishJerricco](https://discourse.nixos.org/u/ElvishJerricco)
#### Post date: [December 29, 2021, 6:38pm UTC](https://discourse.nixos.org/t/need-help-on-failure-of-building-my-configuration/16842/16 "2021-12-29T18:38:14Z")

</div>

I really wish I knew what was causing these spurious false generations. As I said, this is not the first time I’ve seen this in the past few days…

---

<div class="post-metadata">

### Author: ![ElvishJerricco](https://discourse.nixos.org/user_avatar/discourse.nixos.org/elvishjerricco/32/984_2.png) [@ElvishJerricco](https://discourse.nixos.org/u/ElvishJerricco)
#### Post date: [December 29, 2021, 6:38pm UTC](https://discourse.nixos.org/t/need-help-on-failure-of-building-my-configuration/16842/17 "2021-12-29T18:38:44Z")

</div>

That seems odd… You did build `apostrophe` in the repl at some point though?

---

<div class="post-metadata">

### Author: ![schuelermine](https://discourse.nixos.org/user_avatar/discourse.nixos.org/schuelermine/32/28728_2.png) [@schuelermine](https://discourse.nixos.org/u/schuelermine)
#### Post date: [December 29, 2021, 6:39pm UTC](https://discourse.nixos.org/t/need-help-on-failure-of-building-my-configuration/16842/18 "2021-12-29T18:39:46Z")

</div>

Maybe it has to do with flakes, I got an unexpected behaviour with them shortly before building apostrophe. I imported my /etc/nixos flake and tried getting the nixpkgs input from it, and, when autocompleting, `nix repl` for some reason re-downloaded nixpkgs, even though it seems like it should be available

---

<div class="post-metadata">

### Author: ![schuelermine](https://discourse.nixos.org/user_avatar/discourse.nixos.org/schuelermine/32/28728_2.png) [@schuelermine](https://discourse.nixos.org/u/schuelermine)
#### Post date: [December 29, 2021, 6:40pm UTC](https://discourse.nixos.org/t/need-help-on-failure-of-building-my-configuration/16842/19 "2021-12-29T18:40:14Z")

</div>

maybe that’s normal though—does the GC remove inputs to non-GC’ed flakes?

---

<div class="post-metadata">

### Author: ![schuelermine](https://discourse.nixos.org/user_avatar/discourse.nixos.org/schuelermine/32/28728_2.png) [@schuelermine](https://discourse.nixos.org/u/schuelermine)
#### Post date: [December 29, 2021, 6:47pm UTC](https://discourse.nixos.org/t/need-help-on-failure-of-building-my-configuration/16842/20 "2021-12-29T18:47:42Z")

</div>

OK, I removed old generations with `nix-collect-garbage --delete-old`. Now it works.

[Next page](https://discourse.nixos.org/t/need-help-on-failure-of-building-my-configuration/16842.md?page=2)
