Curious about system.nix

I deal with NIX_PATH like this:

let
  nixpkgs = builtins.fetchTarball { ... };
in
  import "${nixpkgs}/nixos" {
    configuration = {
      imports = [ ./configuration.nix ];
      nix.nixPath = [
        "nixos-config=${toString ./configuration.nix}"
        "nixos-system=${toString ./system.nix}"
        "nixpkgs=/run/current-system/nixpkgs"
      ];
      system.systemBuilderCommands = "ln -s ${nixpkgs} $out/nixpkgs";
    };
  }
  • nixos-config so that nixos-rebuild edit works,
  • nixos-system so I can run nixos-rebuild anywhere,
  • nixpkgs so Nix uses the same Nixpkgs that was used to build the system,
  • and the link to /run/current-system so it doesn’t get gc’ed.
7 Likes