So I've installed Nix on Arch linux and I'm able to run nix-env -i example
, however how can I define a Nix configuration?
As I don't have any /nixos/configuration.nix
file present.
Is this possible?
My goal here is to be able to define a configuration which I could then use something like nixos-rebuild switch
to install and provision all the software.
I use NixOS, but I use /etc/nixos/configuration.nix
to describe my system; I keep it fairly minimal and prefer not to install "user" software by editing configuration.nix.
So what I do instead is use my ~/.nixpkgs/config.nix
(which I believe you also have an equivalent of even in a non-NixOS nix install? I've never actually used nix separately).
The basic structure I use is this:
{
packageOverrides = nixpkgs: with nixpkgs; rec {
mine = with pkgs; buildEnv {
name = "mine";
paths = [
# your packages here
];
};
};
}
buildEnv
is a convenience function from nix that makes an "environment" package out of a bunch of others; installing the package mine
depends on (and so installs) all of the things listed in paths
, and also makes sure they get included in PATH
and things like that.
Then I just use nix-env -riA nixos.mine
to deploy changes I've made to my environment description (or to rebuild my environment following channel updates). The -r
tells it to remove everything else other than mine
from the new generation of my profile, which means I can (ab?)use nix-env -i some-package
as a way of "temporarily" installing some-package
, and if I don't decide I like it enough to actually record it in my config.nix it'll just get removed anyway next time I deploy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With