ryan4yin / nixos-and-flakes-book

:hammer_and_wrench: :heart: Want to know NixOS & Flakes in detail? Looking for a beginner-friendly tutorial? Then you've come to the right place! 想要学习使用 NixOS 与 Flakes 吗?在寻找一份新手友好的教程?那你可来对地方了!
https://nixos-and-flakes.thiscute.world
Creative Commons Attribution Share Alike 4.0 International
2.05k stars 104 forks source link

Failed to switch to flake in virtualbox envrionment #164

Closed longfeiss closed 4 months ago

longfeiss commented 5 months ago

newbie here and would appreciate it if anybody could explain this to me

error is

cannot lookup '<nixpkgs/nixos/modules/installer/virtualbox-demo.nix>' in pure evaluation mode ( use '--impure' to override)

ryan4yin commented 5 months ago

<xxx> is a nix lookup path, as Lookup paths - nix.dev said:

While you will encounter many such examples, we recommend to avoid lookup paths in production code, as they are impurities which are not reproducible.

That's to say, lookup paths are impurities, and flake are pure by default, so flake will not accept it.

As the error suggest, you can add --impure at the end of your nix command to avoid this error.

A better solution is to switch to modulePaths - A parameter available only in NixOS, which is a path pointing to nixpkgs/nixos/modules. An example: hardware-configuration.nix

longfeiss commented 4 months ago

thanks

Ryan Yin @.***>于2024年6月24日 周一上午9:07写道:

is a nix lookup path, as Lookup paths - nix.dev said: While you will encounter many such examples, we recommend to avoid lookup paths in production code, as they are impurities which are not reproducible. That's to say, lookup paths are impurities, and flake are pure by default, so flake will not accept it. As the error suggest, you can add --impure at the end of your nix command to avoid this error. A better solution is to switch to modulePaths - A parameter available only in NixOS, which is a path pointing to nixpkgs/nixos/modules . An example: hardware-configuration.nix — Reply to this email directly, view it on GitHub , or unsubscribe . You are receiving this because you authored the thread.Message ID: ***@***.***>