From a65bd00f57daedc8f33e53f9401c32505d553128 Mon Sep 17 00:00:00 2001 From: zimbatm Date: Fri, 30 Aug 2024 19:50:25 +0200 Subject: [PATCH] feat(srvos.flake): export the flake further When `srvos.flake` is set, also set: * NIX_PATH to the flake's nixpkgs input * flake-registry to the flake's inputs --- nixos/common/flake.nix | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/nixos/common/flake.nix b/nixos/common/flake.nix index 2182d6a6..a5b5659d 100644 --- a/nixos/common/flake.nix +++ b/nixos/common/flake.nix @@ -7,6 +7,21 @@ let cfg = config.srvos; + + flake-registry = pkgs.writers.writeJSON "flake-registry.json" { + version = 2; + flakes = pkgs.lib.mapAttrsToList (name: value: { + exact = true; + from = { + id = name; + type = "indirect"; + }; + to = { + path = toString value; + type = "path"; + }; + }) ({ self = cfg.flake; } // cfg.flake.inputs); + }; in { options.srvos = { @@ -42,6 +57,9 @@ in }; }; config = lib.mkIf (cfg.flake != null) { + nix.settings.nix-path = lib.mkIf (cfg.flake.inputs ? nixpkgs) "nixpkgs=${cfg.flake.inputs.nixpkgs}"; + nix.settings.flake-registry = lib.mkDefault flake-registry; + system.extraSystemBuilderCmds = lib.optionalString cfg.symlinkFlake '' ln -s ${cfg.flake} $out/flake '';