summaryrefslogtreecommitdiffstats
path: root/flake.nix
diff options
context:
space:
mode:
authorJade Lovelace <software@lfcode.ca>2024-01-03 17:41:57 +0100
committerJade Lovelace <software@lfcode.ca>2024-02-03 20:44:38 -0800
commite456032addae76701eb17e6c03fc515fd78ad74f (patch)
tree42bb5f4f2303202044989af20266b8905ef6caf7 /flake.nix
parenta9da154ccb5c561141cd8c04c8305c00a1676ede (diff)
nixos/flake: put nixpkgs in NIX_PATH and system registry for flake configs
Currently there are a bunch of really wacky hacks required to get nixpkgs path correctly set up under flake configs such that `nix run nixpkgs#hello` and `nix run -f '<nixpkgs>' hello` hit the nixpkgs that the system was built with. In particular you have to use specialArgs or an anonymous module, and everyone has to include this hack in their own configs. We can do this for users automatically. I have tested these manually with a basic config; I don't know if it is even possible to write a nixos test for it since you can't really get a string-with-context to yourself unless you are in a flake context.
Diffstat (limited to 'flake.nix')
-rw-r--r--flake.nix14
1 files changed, 13 insertions, 1 deletions
diff --git a/flake.nix b/flake.nix
index 580f572ff32c..d920d5d0ddda 100644
--- a/flake.nix
+++ b/flake.nix
@@ -27,7 +27,19 @@
# We set it to null, to remove the "legacy" entrypoint's
# non-hermetic default.
system = null;
- } // args
+
+ modules = args.modules ++ [
+ # This module is injected here since it exposes the nixpkgs self-path in as
+ # constrained of contexts as possible to avoid more things depending on it and
+ # introducing unnecessary potential fragility to changes in flakes itself.
+ #
+ # See: failed attempt to make pkgs.path not copy when using flakes:
+ # https://github.com/NixOS/nixpkgs/pull/153594#issuecomment-1023287913
+ ({ config, pkgs, lib, ... }: {
+ config.nixpkgs.flake.source = self.outPath;
+ })
+ ];
+ } // builtins.removeAttrs args [ "modules" ]
);
});