From 3a735ce70b49774e9ea35acded53163d89c4c4b1 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Sun, 14 Feb 2021 15:50:49 -0700 Subject: [PATCH] core: pin registry by ref Users may wish to change the default value of override and nixos inputs. If they do so, we want the registry listing to reflect the proper ref names afterwards. Also create a shell alias to easily search every flake in nix.registry. --- hosts/default.nix | 69 +++++++++++++++++++++++++++------------ profiles/core/default.nix | 19 +++++++++-- 2 files changed, 65 insertions(+), 23 deletions(-) diff --git a/hosts/default.nix b/hosts/default.nix index b5e31a63..6bc06e4d 100644 --- a/hosts/default.nix +++ b/hosts/default.nix @@ -1,11 +1,12 @@ -{ lib +{ extern +, home +, lib , nixos -, override , nixos-hardware +, override , pkgs , self , system -, extern , ... }: let @@ -36,29 +37,57 @@ let modules; }; - global = { - home-manager.useGlobalPkgs = true; - home-manager.useUserPackages = true; + global = + let + inherit (lock) nodes; - hardware.enableRedistributableFirmware = lib.mkDefault true; + lock = builtins.fromJSON (builtins.readFile ../flake.lock); + in + { + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; - networking.hostName = hostName; - nix.nixPath = [ - "nixos-unstable=${override}" - "nixos=${nixos}" - "nixpkgs=${nixos}" - ]; + hardware.enableRedistributableFirmware = lib.mkDefault true; - nixpkgs = { inherit pkgs; }; + networking.hostName = hostName; - nix.registry = { - nixflk.flake = self; - nixpkgs.flake = nixos; + nix.nixPath = [ + "nixpkgs=${nixos}" + "nixos-config=${self}/compat/nixos" + "home-manager=${home}" + ]; + + nixpkgs = { inherit pkgs; }; + + nix.registry = { + flk.flake = self; + + nixos = { + exact = true; + from = nodes.nixos.original; + to = { + inherit (nixos) lastModified narHash rev; + + path = override.outPath; + type = "path"; + }; + }; + + override = { + exact = true; + from = nodes.override.original; + to = { + inherit (override) lastModified narHash rev; + + path = override.outPath; + type = "path"; + }; + }; + }; + + system.configurationRevision = lib.mkIf (self ? rev) self.rev; }; - system.configurationRevision = lib.mkIf (self ? rev) self.rev; - }; - local = { require = [ (import "${toString ./.}/${hostName}.nix") diff --git a/profiles/core/default.nix b/profiles/core/default.nix index 51099554..bf96b266 100644 --- a/profiles/core/default.nix +++ b/profiles/core/default.nix @@ -65,8 +65,8 @@ in nr = "np remove"; ns = "n search --no-update-lock-file"; nf = "n flake"; - nepl = "n repl ''"; - srch = "ns nixpkgs"; + nepl = "n repl ''"; + srch = "nsni"; nrb = ifSudo "sudo nixos-rebuild"; mn = '' manix "" | grep '^# ' | sed 's/^# \(.*\) (.*/\1/;s/ (.*//;s/^# //' | sk --preview="manix '{}'" | xargs manix @@ -93,7 +93,20 @@ in dn = ifSudo "s systemctl stop"; jtl = "journalctl"; - }; + } // lib.mapAttrs' + (n: v: + let + prefix = lib.concatStrings (lib.take 2 (lib.stringToCharacters n)); + ref = from: + if from ? ref + then "ns ${from.id}/${from.ref}" + else "ns ${from.id}"; + in + lib.nameValuePair + "ns${prefix}" + (ref v.from) + ) + config.nix.registry; };