nix

Command

nix-copy

Tips

Changelog

2.19

Functions

Configuration

See config

Colors

stylix nix-colors

Services

Options. Most important options:

Tips

Timers

Source. Options. Important options:

Example

systemd.timers."hello-world" = {
  wantedBy = [ "timers.target" ];
    timerConfig = {
      OnBootSec = "5m";
      OnUnitActiveSec = "5m";
      Unit = "hello-world.service";
    };
};
systemd.services."hello-world" = {
  script = ''
    set -eu
    ${pkgs.coreutils}/bin/echo "Hello World"
  '';
  serviceConfig = {
    Type = "oneshot";
    User = "root";
  };
};

Commands

Examples

Installers

There are a couple installers and you can build your own. To create an installer provide a configuration through a flake or a nix file, which has some module from ${modulesPath}/installer/ as import. E.g. ${modulesPath}/installer/cd-dvd/installation-cd-minimal.nix - the one you would most commonly use. Example configuration:

{
  nixosConfigurations.installer = nixpkgs.lib.nixosSystem {
    system = "x86_64-linux";
    specialArgs = { inherit inputs; };
    modules = [
      ({ pkgs, modulesPath, lib, ... }: {
        imports = [
          "${modulesPath}/installer/cd-dvd/installation-cd-minimal.nix"
        ];
        boot.kernelPackages = pkgs.linuxPackages_latest;
        boot.supportedFilesystems = lib.mkForce [ "btrfs" "reiserfs" "vfat" "f2fs" "xfs" "ntfs" "cifs" ];
        users.users.nixos.openssh.authorizedKeys.keyFiles = [ ./ssh/mykey ];
      })
      ./modules/default/tools.nix
    ];
  };
}

Building configurations can be done with nixos-generate --flake .#installer --format iso -o result from nixos-generators. Beware that the process is quite slow due to squashfs generation and can take around 6 minutes. Try out your installer before flashing with nixos-rebuild build-vm --flake .#installer. Flash resulting iso with dd if=result/iso/nixos-smth.iso of=/dev/disk/by-id/usb-ID status=progress && sync.

Rerences