Nixos: Basics - Oliver-Mustoe/Oliver-Mustoe-Tech-Journal GitHub Wiki
FOLLOWING IS IN JOURNAL FORMATTING - check the 'Nix: reference' section for just raw findings/reference
configuration.nix
NixOS uses the Nix package manager and makes heavy use of the Nix coding language. The basic is that you have a file in /etc/nixos/configuration.nix
that contains all of the configurations needed to make your system:
This file is EXTREMLY powerful and is the recommended primary way to edit the operating system by adding packages under enviroment.systemPackages
- my current usage below:
I am stilling very much a beginner in reading the Nix language, but I see it that the enviroment
above is the package/library and that systemPackages
is like a sub-function that allows certain things to happen. The with pkgs;
just saves having to put pkgs
before each of my packages and the brackets define the array of packages I want that it will query the Nixpkg store for.
A great resource for searching for what packages are native and what each of the configuration options means/what is available is search.nixos.org (use the above filters to specify either the sub-function I described above or packages:)
After settings up a config (which I have mostly done through google) you can set the config with:
sudo nixos-rebuild switch
Which will immediately apply your results AND make it the boot. sudo nixos-rebuild test
should apply it but not make it boot - it still seems to make it boot for me but I haven't really tested it much. I SHOULD ALSO NOTE THAT WHEN TRANSFERING CONFIGS REMEMBER TO EDIT THE USERS PROPERLY - IN SIMPLE TERMS HAVE THE USERNAME OF THE USER ON THE MACHINE IN THE CONFIG WHEN SWAPPING CONFIGS BETWEEN SYSTEMS FOR IT NOT TO BREAK!!! < Explore user management more in nix.
Apparently nixos-rebuild
can be used to set configs to remote systems, to quote nixos.wiki:
nixos-rebuild can also be used to build and deploy system configurations on remote hosts via SSH. To use a remote host to build your system and deploy it on the current host, use:
# nixos-rebuild --build-host [email protected] switch
To build the system locally and deploy it on a remote host, use:
$ nixos-rebuild --target-host [email protected] switch
Note that this will often require using a different configuration than the one in /etc/nixos. See the Specifying a different configuration location section for details. --build-host and --target-host can be used simultaneously, even with different hosts.
AND the specification that will prob be needed:
By default, nixos-rebuild builds the configuration in the file specified by the nixos-config field in the NIX_PATH environment variable, which is set to /etc/nixos/configuration.nix by default. This can be overwritten with:
# nixos-rebuild switch -I nixos-config=path/to/configuration.nix
I have not tested this option in NixOS BUT I hope to soon as this could REALLY give a reason to use NixOS as a server. It would be super sick to build a NixOS config > deploy it onto a remote machine > $profit. The other way around ALSO seems interesting where you could have a central NixOS server that you can pull configs from almost like a FOG server with images????? This REQUIRES some testing! Also their are a few projects like NixOps that may already have the deployment functionality all set!