Skip to content

Commit

Permalink
Revert auto-channel detection that produced irrecoverable edge-cases
Browse files Browse the repository at this point in the history
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".
  • Loading branch information
blaggacao committed Sep 5, 2021
1 parent daab9cb commit 5993edf
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
1 change: 1 addition & 0 deletions examples/exporters/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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; })
];
Expand Down
1 change: 1 addition & 0 deletions examples/home-manager+nur+neovim/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@


channelsConfig.allowUnfree = true;
channels.nixpkgs = {};

sharedOverlays = [
nur.overlay
Expand Down
2 changes: 2 additions & 0 deletions examples/minimal-multichannel/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 14 additions & 12 deletions lib/mkFlake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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': (
Expand All @@ -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; };

Expand All @@ -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 `<channelName>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"); };

Expand Down Expand Up @@ -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 = [
Expand All @@ -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: { }
Expand Down

0 comments on commit 5993edf

Please sign in to comment.