tpwrules / nixos-apple-silicon

Resources to install NixOS bare metal on Apple Silicon Macs
MIT License
757 stars 76 forks source link

How to avoid --impure with flakes? #59

Closed ingenieroariel closed 1 year ago

ingenieroariel commented 1 year ago

I have been using the flake distro for a few weeks and consider it fantastic. However I do not know how to avoid using --impure when building the system.

I get the following error when --impure is not passed:

error: cannot look up '<nixos-config>' in pure evaluation mode (use '--impure' to override)

       at /nix/store/ld9ihawdpciw50x3h0kzjzk4c8vy0vkb-source/nixos/modules/system/activation/top-level.nix:317:68:

          316|         config.system.copySystemConfiguration
          317|         ''ln -s '${import ../../../lib/from-env.nix "NIXOS_CONFIG" <nixos-config>}' \
             |                                                                    ^
          318|             "$out/configuration.nix"
(use '--show-trace' to show detailed location information)
tpwrules commented 1 year ago

I don't think this is an issue in nixos-apple-silicon. The context suggests that you have system.copySystemConfiguration enabled somewhere in your config. This is not enabled in my modules.

ingenieroariel commented 1 year ago

I don't have access to that specific system but if it does not happen for you I will close it out.

I thought it was related to the firmware files not being accessible in the Nix sandbox. Perhaps I should just add the firmware files to the private git repo that manages my flake. I will likely get to this in the next few weeks with a different machine and update this issue if I find a solution.

tpwrules commented 1 year ago

Please see the information about hardware.asahi.peripheralFirmwareDirectory in the guide.

MaximilianGaedig commented 3 months ago

I just wanted to mention a solution for people wondering how to keep your flake pure and not commit your firmware:

  inputs = {
    nixpkgs.url = "nixpkgs/nixos-23.11";
    apple-silicon-support.url = "github:tpwrules/nixos-apple-silicon";
    # add such a local input:
    asahi-firmware = {
      url="/etc/nixos/firmware";
      flake = false;
    };
  };

then, whereever you configure hardware, for example configuration.nix:

# at the top make sure to include inputs
{ [...], inputs, ... }:

{
[...]
# then you can use the input as the firmware directory like this:
    hardware.asahi.peripheralFirmwareDirectory = inputs.asahi-firmware;
[...]
}

this hashes your firmware directory contents into the lock, when for some reason you want to update the firmware you need to copy the firmware into /etc/nixos/firmware (be warned this gets replaced on boot so you need to get this trough some other way than relying on the installer putting it there), then run nix flake update to update the hash