There are some articles you want to read first:
- https://www.tweag.io/blog/2020-05-25-flakes/
- https://www.tweag.io/blog/2020-06-25-eval-cache/
- https://www.tweag.io/blog/2020-07-31-nixos-flakes/
Nix Flakes is currently an experimental feature, so this tutorial assumes that you are using the unstable
channel.
First, add the following to the system configuration:
{
nix = {
package = pkgs.nixUnstable;
extraOptions = ''
experimental-features = nix-command flakes
'';
};
}
Switch to the new system configuration using nixos-rebuild
.
After that, create /etx/nixos/flake.nix
with the following content:
{
inputs = {
nixpkgs.url = github:NixOS/nixpkgs-channels/nixos-unstable;
# nur.url = github:nix-community/NUR;
};
outputs = { nixpkgs, nix, self, ... }@inputs: {
nixosConfigurations.nixos = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules =
[ (import ./configuration.nix) ];
specialArgs = { inherit inputs; };
};
};
}
Run cd /etc/nixos ; nix flake update
to create the /etc/nixos/flake.lock
file. Now your system uses Flakes.
Run nixos-rebuld switch
to insure that everything works normaly.
Removing /etc/nixos/flake.nix
with switch nixos-rebuild
back to using /etc/configuration.nix
directly.
Create the following flake:
{
description = "A home flake";
inputs = {
system.url = "self";
};
outputs = { self, nixpkgs, system }: {
packages.x86_64-linux = system.legacyPackages.x86_64-linux;
defaultPackage.x86_64-linux = with self.packages.x86_64-linux; buildEnv {
name = "home-env";
paths = [ <package list> ];
};
legacyPackages.x86_64-linux = system.legacyPackages.x86_64-linux;
};
}
Then install it with nix profile install .
.
- Upgrade the system:
nixos-rebuild --recreate-lock-file
- Find a package:
nix search self «query»
- Install package:
- From the system flake:
nix profile install self#«package name»
- From nixpkgs master:
nix profile install github:NixOS/nixpkgs/master#«package name»
- From the system flake:
- Update all packages in the profile:
nix profile update '.*'