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

modules/nixpkgs: Make customizable & support multiple evaluations #137

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
6 changes: 5 additions & 1 deletion dev/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@

# Separate `dev` flake

Wouldn't recommend this pattern normally, but I'm trying to keep
deps low for `flake-parts` until we have split dev inputs
that don't carry over to dependent lock files.

```sh
nix develop --impure -f './dev' 'mySystem.devShells.default'
nix repl -f './dev'
```
46 changes: 33 additions & 13 deletions dev/default.nix
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
let
flake-parts = builtins.getFlake (toString ../.);
lib = flake-parts.inputs.nixpkgs-lib.lib;
sourceInfo = inputs.flake-parts.sourceInfo; # used by pre-commit module, etc
flake = builtins.getFlake (toString ./.);
fmc-lib = (builtins.getFlake (toString ../.)).lib;
args = {
inherit self;
} // flake.inputs;
self = {
inherit (flake) inputs;
outPath = ../.; # used by pre-commit module, etc
outputs = self.config.flake;
} //
fmc-lib.mkFlake
{ inputs = args; }
./flake-module.nix;
inputs = flake.inputs // { inherit flake-parts; };
makeResult = specialArgs: flakeModule: result:
let
outputs = flake.outputs // flake-parts.lib.mkFlake
{
inputs = inputs // { self = result; };
# debugging tool
specialArgs = {
replaceSpecialArgs = newSpecialArgs:
let
newSpecialArgs' =
if lib.isFunction newSpecialArgs
then newSpecialArgs specialArgs
else newSpecialArgs;
newResult = makeResult newSpecialArgs' flakeModule newResult;
in
newResult;
} // specialArgs;
}
flakeModule;
in
outputs // sourceInfo // {
inherit inputs outputs sourceInfo;
_type = "flake";
};
in
self.config.flake // { inherit (flake) inputs; }
let
# eagerly import to reproduce inline evaluation
result = makeResult { } (import ./flake-module.nix) result;
in
result
35 changes: 24 additions & 11 deletions dev/flake-module.nix
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
{ config, lib, inputs, withSystem, ... }:

{
{ config, inputs, lib, options, specialArgs, withSystem, ... } @ args:
let
rootArgs = args;
rootConfig = config;
rootOptions = options;
rootSpecialArgs = specialArgs;
in
# debugging tool
specialArgs.flakeModuleTransformer or (args: flakeModule: flakeModule) args {
imports = [
inputs.pre-commit-hooks-nix.flakeModule
inputs.hercules-ci-effects.flakeModule # herculesCI attr
];
systems = [ "x86_64-linux" "aarch64-darwin" ];
config.systems = [ "x86_64-linux" "aarch64-darwin" ];

hercules-ci.flake-update = {
config.hercules-ci.flake-update = {
enable = true;
autoMergeMethod = "merge";
when.dayOfMonth = 1;
};

perSystem = { config, pkgs, ... }: {
config.perSystem = { config, pkgs, ... }: {

devShells.default = pkgs.mkShell {
nativeBuildInputs = [
Expand All @@ -38,11 +44,18 @@
in tests.runTests pkgs.emptyFile // { internals = tests; };

};
flake = {
# for repl exploration / debug
config.config = config;
options.mySystem = lib.mkOption { default = config.allSystems.${builtins.currentSystem}; };
config.effects = withSystem "x86_64-linux" ({ pkgs, hci-effects, ... }: {
config.flake = { config, options, specialArgs, ... } @ args: {
# for REPL exploration / debugging
config.allFlakeModuleArgs = args // config._module.args // specialArgs;
config.allRootModuleArgs = rootArgs // rootConfig._module.args // rootSpecialArgs;
config.transformFlakeModule = flakeModuleTransformer:
rootSpecialArgs.replaceSpecialArgs (prevSpecialArgs: prevSpecialArgs // {
inherit flakeModuleTransformer;
});
options.mySystem = lib.mkOption {
default = rootConfig.allSystems.${builtins.currentSystem};
};
config.effects = withSystem "x86_64-linux" ({ hci-effects, pkgs, ... }: {
tests = {
template = pkgs.callPackage ./tests/template.nix { inherit hci-effects; };
};
Expand Down
Loading