Skip to content

Instantly share code, notes, and snippets.

@mtrsk
Created May 6, 2021 01:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mtrsk/d1eab6842d2e903c4470145b06b6ca1f to your computer and use it in GitHub Desktop.
Save mtrsk/d1eab6842d2e903c4470145b06b6ca1f to your computer and use it in GitHub Desktop.
Migrate NixOS from channels to flakes
# https://www.tweag.io/blog/2020-07-31-nixos-flakes/
# To switch from channels to flakes execute:
# cd /etc/nixos
# sudo wget -O flake.nix https://gist.githubusercontent.com/misuzu/80af74212ba76d03f6a7a6f2e8ae1620/raw/flake.nix
# sudo sed -i "s/myhost/$(hostname)/g" flake.nix
# sudo git init
# sudo git add . # won't work without this
# nix run nixpkgs.nixFlakes -c sudo nix --experimental-features 'flakes nix-command' build .#nixosConfigurations.$(hostname).config.system.build.toplevel
# sudo ./result/bin/switch-to-configuration switch
# Now nixos-rebuild can use flakes:
# sudo nixos-rebuild switch --flake /etc/nixos
# To update flake.lock run:
# sudo nix flake update --recreate-lock-file --commit-lock-file /etc/nixos
{
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
inputs.home-manager.url = "github:nix-community/home-manager/master";
inputs.home-manager.inputs.nixpkgs.follows = "/nixpkgs";
outputs = inputs: {
nixosConfigurations.myhost = inputs.nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
# Things in this set are passed to modules and accessible
# in the top-level arguments (e.g. `{ pkgs, lib, inputs, ... }:`).
specialArgs = {
inherit inputs;
};
modules = [
inputs.home-manager.nixosModules.home-manager
({ pkgs, ... }: {
nix.extraOptions = "experimental-features = nix-command flakes";
nix.package = pkgs.nixFlakes;
nix.registry.nixpkgs.flake = inputs.nixpkgs;
home-manager.useGlobalPkgs = true;
})
./configuration.nix
];
};
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment