-
Notifications
You must be signed in to change notification settings - Fork 0
NixOS
Andrew Parker edited this page Dec 21, 2019
·
14 revisions
Manual is here: https://nixos.org/nixos/manual/index.html
-
Declarative:
nixos-rebuildwill ensure that you get a consistent set of binaries corresponding toconfiguration.nix. Must be a root user to change. -
Ad hoc goes through
nix-envcommand, allows mixing packages from different Nixpkgs versions. This is the only way non-root users can add packages.
$ nix-env -qaP 'thunderbird' --description
nixos.thunderbird thunderbird-60.5.1 A full-featured e-mail clientenvironment.systemPackages = [ pkgs.thunderbird ];
$ nixos-rebuild switchIf you have a*.nix file, you can do this:
environment.systemPackages = [ (import ./my-hello.nix) ];
$ nix-build my-hello.nix
$ ./result/bin/hello
Hello, world!$ nix-env -Ai nixos.thunderbird$ nix-channel --update nixos # First update the channel.
$ nix-env -Ai nixos.thunderbird # Update just this package.$ nix-env -u '*'$ nix-env -e thunderbird$ nix-env --rollbackThe driver is under an "unfree" license, so you have to add the following to configuration.nix to allow it:
{ nixpkgs.config.allowUnfree = true; }
services.xserver.videoDrivers = [ "nvidia" ];
hardware.opengl.driSupport32Bit = true; # Enables support for 32-bit programs such as Wine.
$ nix-collect-garbage$ nix-collect-garbage -dAfter the system has booted, you can make the selected configuration the default for subsequent boots:
$ /run/current-system/bin/switch-to-configuration boot nixos-rebuild switch --rollback$ /nix/var/nix/profiles/system-N-link/bin/switch-to-configuration switchwhere N is the number of the NixOS system configuration.
$ ls -l /nix/var/nix/profiles/system-*-link
...
lrwxrwxrwx 1 root root 78 Aug 12 13:54 /nix/var/nix/profiles/system-268-link -> /nix/store/202b...-nixos-13.07pre4932_5a676e4-4be1055If the corruption is in a path in the closure of the NixOS system configuration, you can fix it by doing:
$ nixos-rebuild switch --repairnix-store --verify --check-contents --repairAny corrupt paths will be redownloaded if they’re available in a binary cache; otherwise, they cannot be repaired.
With multiple modules, it may not be obvious what the final value of a configuration option is. The command nixos-option allows you to find out:
$ nixos-option services.xserver.enable
true
$ nixos-option boot.kernelModules
[ "tun" "ipv6" "loop" ... ]nix repl brings up a read-eval-print loop to interactively explore the NixOS environment.
$ nix repl '<nixpkgs/nixos>'
nix-repl> config.networking.hostName
"mandark"
nix-repl> map (x: x.hostName) config.services.httpd.virtualHosts
[ "example.org" "example.gov" ]