# Configuration for any flake-based NixOS system # Try our darndest to get nixpkgs into path & registry properly # # Maybe write a blog post about it? # # In theory NixOS 24.05 does this for us? # > On flake-based NixOS configurations using nixpkgs.lib.nixosSystem, NixOS will automatically set NIX_PATH and the system-wide flake registry (/etc/nix/registry.json) to point and the unqualified flake path nixpkgs to the version of nixpkgs used to build the system. # > This makes nix run nixpkgs#hello and nix-build '' -A hello work out of the box with no added configuration, reusing dependencies already on the system. # > This may be undesirable if nix commands are not going to be run on the built system since it adds nixpkgs to the system closure. For such closure-size-constrained non-interactive systems, this setting should be disabled. # > To disable this, set nixpkgs.flake.setNixPath and nixpkgs.flake.setFlakeRegistry to false. # https://nixos.org/manual/nixos/unstable/release-notes#sec-release-24.05-highlights # # Some reading: # https://nixos-and-flakes.thiscute.world/best-practices/nix-path-and-flake-registry#custom-nix-path-and-flake-registry-1 # https://github.com/NixOS/nix/issues/9574 # # https://discourse.nixos.org/t/questions-on-using-nixos-desktop-with-flakes/16285/5 # # I think there are two separate problems. # # # Getting lookup paths (like ) to resolve # # This comment mentions how they work: # https://discourse.nixos.org/t/nix-path-is-not-recognized/38404/6 # # # Getting `indirect` flake refs (like "nixpkgs") to resolve # ยท indirect: Indirections through the flake registry. These have the form # # | [flake:](/(/rev)?)? # # These perform a lookup of in the flake registry. For example, nixpkgs and nixpkgs/release-20.09 are indirect flake references. The specified rev and/or ref are merged with the entry in # the registry; see nix registry for details. { inputs, lib, ... }: let inherit (inputs) nixpkgs; in { # Enable flake features nix.settings.experimental-features = ["nix-command" "flakes"]; nix.channel.enable = false; # remove nix-channel related tools & configs, we use flakes instead. programs.command-not-found.enable = false; # Doesn't work well past channels nix.registry.nixpkgs.flake = nixpkgs; # but NIX_PATH is still used by many useful tools, so we set it to the same value as the one used by this flake. # Make `nix repl ''` use the same nixpkgs as the one used by this flake. environment.etc."nix/inputs/nixpkgs".source = "${nixpkgs}"; # https://github.com/NixOS/nix/issues/9574 nix.settings.nix-path = lib.mkForce "nixpkgs=/etc/nix/inputs/nixpkgs"; }