diff --git a/examples/exporters/flake.nix b/examples/exporters/flake.nix index 09a25cbb..5f1db630 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 e4cf40d9..4482c56c 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 56e5109d..8283579d 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 79b5e3b0..b5779cd2 100644 --- a/lib/mkFlake.nix +++ b/lib/mkFlake.nix @@ -80,6 +80,18 @@ 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': ( @@ -96,7 +108,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; }; @@ -108,10 +120,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"); }; @@ -195,14 +207,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 = [ @@ -214,7 +218,7 @@ mergeAny otherArguments ( config = channelsConfig // (value.config or { }); }) // { inherit name; inherit (value) input; }; - pkgs = mapAttrs importChannel (mergeAny channelsFromFlakes channels); + pkgs = mapAttrs importChannel ensureChannelsWitsInputs; systemOutputs = outputsBuilder pkgs;