Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert auto-channel detection that produced irrecoverable edge-cases #89

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ jobs:

# Execute /tests/*
- run: nix develop --command check-derivation-outputs
- run: nix develop --command check-derivation-outputs-old
- run: nix develop --command check-channel-patching
- run: nix develop --command check-overlays-flow
- run: nix develop --command check-hosts-config
Expand Down
3 changes: 1 addition & 2 deletions devShell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ devshell.mkShell {

(test "channel-patching")
(test "derivation-outputs")
(test "derivation-outputs-old")
(test "hosts-config")
(test "overlays-flow")
(test "all" // { command = "check-channel-patching && check-derivation-outputs && check-derivation-outputs-old && check-hosts-config && check-overlays-flow"; })
(test "all" // { command = "check-channel-patching && check-derivation-outputs && check-hosts-config && check-overlays-flow"; })

(dry-nixos-build "minimal-multichannel" "Hostname1")
(dry-nixos-build "minimal-multichannel" "Hostname2")
Expand Down
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
12 changes: 1 addition & 11 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,16 @@
rec {
inherit overlay;

# Deprecated in favor of 'nix.generateRegistryFromInputs = true;'
nixosModules.saneFlakeDefaults = { nix.generateRegistryFromInputs = true; };
nixosModules.autoGenFromInputs = import ./lib/options.nix;

devShell.x86_64-linux = import ./devShell.nix { system = "x86_64-linux"; };

lib = flake-utils.lib // {
inherit mkFlake exportModules exportOverlays exportPackages;

# Deprecated - should use top-level functions instead
exporters = {
inherit modulesFromList fromOverlays internalOverlays;
};
inherit systemFlake modulesFromList;
inherit mkFlake exportModules exportOverlays exportPackages systemFlake modulesFromList;

# DO NOT USE - subject to change without notice
internal = internal-functions;

repl = ./lib/repl.nix;

# merge nested attribute sets and lists
mergeAny = lhs: rhs:
lhs // mapAttrs
Expand Down
74 changes: 22 additions & 52 deletions lib/mkFlake.nix
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
{ flake-utils-plus }:

{ self
, defaultSystem ? "x86_64-linux" # will be deprecated soon use hostDefaults.system instead
, supportedSystems ? flake-utils-plus.lib.defaultSystems
, inputs

, channels ? { }
, channelsConfig ? { }
, sharedOverlays ? [ ]

, nixosProfiles ? { } # will be deprecated soon, use hosts, instead.
, hosts ? nixosProfiles
, sharedExtraArgs ? { } # deprecate soon, prefer hostDefaults
, sharedModules ? [ ] # deprecate soon, prefer hostDefaults
, hosts ? { }
, hostDefaults ? {
system = defaultSystem;
modules = sharedModules;
extraArgs = sharedExtraArgs;
system = "x86_64-linux";
modules = [ ];
extraArgs = { };
}

, outputsBuilder ? null

, packagesBuilder ? null
, defaultPackageBuilder ? null
, appsBuilder ? null
, defaultAppBuilder ? null
, devShellBuilder ? null
, checksBuilder ? null
, outputsBuilder ? _: { }
, ...
}@args:

Expand Down Expand Up @@ -82,29 +68,30 @@ let
optionalAttrs = check: value: if check then value else { };

otherArguments = removeAttrs args [
"defaultSystem" # TODO: deprecated, remove
"sharedExtraArgs" # deprecated
"inputs"
"hosts"
"hostDefaults"
"nixosProfiles"
"channels"
"channelsConfig"
"self"
"sharedModules" # deprecated
"sharedOverlays"
"supportedSystems"

"outputsBuilder"
"packagesBuilder"
"defaultPackageBuilder"
"appsBuilder"
"defaultAppBuilder"
"devShellBuilder"
"checksBuilder"
];

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 +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; };

Expand All @@ -133,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 `<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 +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 = [
Expand All @@ -239,18 +218,9 @@ mergeAny otherArguments (
config = channelsConfig // (value.config or { });
}) // { inherit name; inherit (value) input; };

pkgs = mapAttrs importChannel (mergeAny channelsFromFlakes channels);


deprecatedBuilders = channels: { }
// optionalAttrs (packagesBuilder != null) { packages = packagesBuilder channels; }
// optionalAttrs (defaultPackageBuilder != null) { defaultPackage = defaultPackageBuilder channels; }
// optionalAttrs (appsBuilder != null) { apps = appsBuilder channels; }
// optionalAttrs (defaultAppBuilder != null) { defaultApp = defaultAppBuilder channels; }
// optionalAttrs (devShellBuilder != null) { devShell = devShellBuilder channels; }
// optionalAttrs (checksBuilder != null) { checks = checksBuilder channels; };
pkgs = mapAttrs importChannel ensureChannelsWitsInputs;

systemOutputs = (if outputsBuilder == null then deprecatedBuilders else outputsBuilder) pkgs;
systemOutputs = outputsBuilder pkgs;

mkOutputs = attrs: output:
attrs //
Expand Down
91 changes: 0 additions & 91 deletions tests/derivation-outputs-old/flake.nix

This file was deleted.