nix-channel
- impure; nixpkgs may change at any time
- Local nixpkgs checkout
- this can be quite unreliable. Alternatively you can include a git-submodule or git-subtree in your configuration repository.
- Niv
- Similar to flakes in a lot of ways, but much smaller in scope. Developed by community members https://github.com/nmattia/niv
- Flakes
- The hot new shit that everyone is talking about
- Lock a specific configuration state to a particular nixpkgs version.
- Rolling back configuration also rolls back nixpkgs automatically.
- Subtrees can be heavy on a repository, because the entire
history is merged
- They do potentially make upstream contributions easier though.
- Developed by Nix community since 2019
- Specify dependencies via
sources.json
file
{
"nixpkgs": {
"branch": "nixos-unstable",
"description": "Nix Packages collection",
"homepage": "",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "79d3ca08920364759c63fd3eb562e99c0c17044a",
"sha256": "1zz72k161yl9dxs5nxgy5p6nh8zsz4fbpclm99r12jw39zrlzhhw",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/79d3ca08920364759c63fd3eb562e99c0c17044a.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
}
}
{ overlays ? [], ... } @ args:
let
sources = import nix/sources.nix;
my-overlays = [ /* ... */ ];
in
import sources.nixpkgs(args // {
overlays = overlays ++ my-overlays;
})
❤ (theia) ~/sys> niv update nixpkgs
Update nixpkgs-unstable
Done: Update nixpkgs-unstable
Flakes allow you to specify your Nix dependencies in a declarative way.
# flake.nix
{
inputs = {
home-manager.url = "github:nix-community/home-manager";
};
}
❤ (theia) ~> nix flake lock --update-input home-manager
{
description = "hello-flake";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
};
}
{
# ...
outputs = { self, nixpkgs, ... }:
let system = "x86_64-linux";
in
{
defaultPackage."${system}" = (import nixpkgs { inherit system; }).hello;
};
}
❤ (theia) ~> nix flake lock
...
❤ (theia) ~> ls
flake.lock flake.nix
❤ (theia) ~> nix build
❤ (theia) ~> ls
flake.lock flake.nix result
❤ (theia) ~> result/bin/hello
Hello, world!
{
# ...
outputs = { self, nixpkgs, home-manager, ... }:
{
nixosConfiguration."hyperion" = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
home-manager.nixosModules.home-manager
./roots/hyperion.nix
];
};
};
}
- Flakes are still being developed
- NixOS/rfcs#49 (initial RFC which didn’t land)
- Work ongoing behind
--experimental-features flake
argument- (or via
nix.conf
configuration file)
- (or via
- More RFCS: RFC#123, RFC#105, probably more to come :)
- https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html#flake-references