From 5993edf36b9cbb64d3e4286d560f09a6441d5c24 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sat, 4 Sep 2021 20:20:33 -0500 Subject: [PATCH] Revert auto-channel detection that produced irrecoverable edge-cases In more advanced usage scenarios, the guarantees of this code path are never strong enough and the error produced is non-recoverable. Sorry to lovers of "automagic". --- examples/exporters/flake.nix | 1 + examples/home-manager+nur+neovim/flake.nix | 1 + examples/minimal-multichannel/flake.nix | 2 ++ lib/mkFlake.nix | 26 ++++++++++++---------- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/examples/exporters/flake.nix b/examples/exporters/flake.nix index 6c8b480f..b212e0fa 100644 --- a/examples/exporters/flake.nix +++ b/examples/exporters/flake.nix @@ -16,6 +16,7 @@ inherit self inputs; # Channel specific overlays. Overlays `coreutils` from `unstable` channel. + channels.unstable = {}; channels.nixpkgs.overlaysBuilder = channels: [ (final: prev: { inherit (channels.unstable) ranger; }) ]; diff --git a/examples/home-manager+nur+neovim/flake.nix b/examples/home-manager+nur+neovim/flake.nix index 42496af5..7ece1e04 100644 --- a/examples/home-manager+nur+neovim/flake.nix +++ b/examples/home-manager+nur+neovim/flake.nix @@ -26,6 +26,7 @@ channelsConfig.allowUnfree = true; + channels.nixpkgs = {}; sharedOverlays = [ nur.overlay diff --git a/examples/minimal-multichannel/flake.nix b/examples/minimal-multichannel/flake.nix index ac58a02d..ac15eb41 100644 --- a/examples/minimal-multichannel/flake.nix +++ b/examples/minimal-multichannel/flake.nix @@ -16,6 +16,8 @@ # Channels are automatically generated from nixpkgs inputs # e.g the inputs which contain `legacyPackages` attribute are used. channelsConfig.allowUnfree = true; + channels.nixpkgs = {}; + channels.unstable = {}; # Modules shared between all hosts diff --git a/lib/mkFlake.nix b/lib/mkFlake.nix index 885cd1c5..32881066 100644 --- a/lib/mkFlake.nix +++ b/lib/mkFlake.nix @@ -105,6 +105,16 @@ let ]; getChannels = system: self.pkgs.${system}; + ensureChannelsWitsInputs = mapAttrs (n: v: + if (!v ? input) then + v // { + input = inputs.${n} or ( + throw '' + No input is inferable by name from flake inputs for channel "${n}" + ''); + } + else v + ) channels; getNixpkgs = host: (getChannels host.system).${host.channelName}; configurationBuilder = reverseDomainName: host': ( @@ -121,7 +131,7 @@ let selectedNixpkgs = getNixpkgs host; host = evalHostArgs (mergeAny hostDefaults host'); patchedChannel = selectedNixpkgs.path; - channels = getChannels host.system; + channels' = getChannels host.system; specialArgs = host.specialArgs // { channel = selectedNixpkgs; }; @@ -133,10 +143,10 @@ let nixosSpecialArgs = let f = channelName: - { "${channelName}ModulesPath" = toString (channels.${channelName}.input + "/nixos/modules"); }; + { "${channelName}ModulesPath" = toString (channels'.${channelName}.input + "/nixos/modules"); }; in # Add `ModulesPath`s - (foldl' (lhs: rhs: lhs // rhs) { } (map f (attrNames channels))) + (foldl' (lhs: rhs: lhs // rhs) { } (map f (attrNames channels'))) # Override `modulesPath` because otherwise imports from there will not use patched nixpkgs // { modulesPath = toString (patchedChannel + "/nixos/modules"); }; @@ -220,14 +230,6 @@ mergeAny otherArguments ( eachSystem supportedSystems (system: let - filterAttrs = pred: set: - listToAttrs (concatMap (name: let value = set.${name}; in if pred name value then [ ({ inherit name value; }) ] else [ ]) (attrNames set)); - - # Little hack, we make sure that `legacyPackages` contains `nix` to make sure that we are dealing with nixpkgs. - # For some odd reason `devshell` contains `legacyPackages` out put as well - channelFlakes = filterAttrs (_: value: value ? legacyPackages && value.legacyPackages.x86_64-linux ? nix) inputs; - channelsFromFlakes = mapAttrs (name: input: { inherit input; }) channelFlakes; - importChannel = name: value: (import (patchChannel system value.input (value.patches or [ ])) { inherit system; overlays = [ @@ -239,7 +241,7 @@ mergeAny otherArguments ( config = channelsConfig // (value.config or { }); }) // { inherit name; inherit (value) input; }; - pkgs = mapAttrs importChannel (mergeAny channelsFromFlakes channels); + pkgs = mapAttrs importChannel ensureChannelsWitsInputs; deprecatedBuilders = channels: { }