Skip to content

Commit

Permalink
Demo of an issue we just ran into
Browse files Browse the repository at this point in the history
  • Loading branch information
jfly committed Sep 26, 2024
0 parents commit c3147a8
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/result
93 changes: 93 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Diamond dependencies with the nixpkgs module system

This flake declares 2 `nixosConfigurations`:

- `.#nixosConfigurations.use-module-binding`
- `.#nixosConfigurations.use-module-filepath`

They both include the `./vim-option.nix` module twice (simulating a "diamond
dependency"), but in different ways:

`use-module-filepath.nix`:
```nix
{
imports = [
./vim-option.nix
./vim-option.nix
];
...
}
```

`use-module-binding.nix`:
```nix
let vim-option = import ./vim-option.nix;
in
{
imports = [
vim-option
vim-option
];
...
}
```

This "double import via a binding" feels like something that's more likely to
happen as the nix flake ecosystem evolves: someday you're going to end up using
module A and module B where module B itself uses module A.

Note that `.#nixosConfigurations.use-module-filepath` evaluates fine:

```shell
$ nix eval .#nixosConfigurations.use-module-filepath.config.system.build.toplevel
trace: declaring _includeVim
«derivation /nix/store/dmmxnrhn6c6yibzlcdlwjb1i5akdcjsi-nixos-system-nixos-24.11.20240923.30439d9.drv»
```

However, `.#nixosConfigurations.use-module-binding` fails to evaluate:

```shell
$ nix eval .#nixosConfigurations.use-module-binding.config.system.build.toplevel
trace: declaring _includeVim
trace: declaring _includeVim
error:
while calling the 'head' builtin
at /nix/store/p2hby44a0qzrnd1vxcpcgfav6160rmcv-source/lib/attrsets.nix:1575:11:
1574| || pred here (elemAt values 1) (head values) then
1575| head values
| ^
1576| else

while evaluating the attribute 'value'
at /nix/store/p2hby44a0qzrnd1vxcpcgfav6160rmcv-source/lib/modules.nix:821:9:
820| in warnDeprecation opt //
821| { value = addErrorContext "while evaluating the option `${showOption loc}':" value;
| ^
822| inherit (res.defsFinal') highestPrio;
while evaluating the option `system.build.toplevel':
… while evaluating definitions from `/nix/store/p2hby44a0qzrnd1vxcpcgfav6160rmcv-source/nixos/modules/system/activation/top-level.nix':
while evaluating the option `system.systemBuilderArgs':
… while evaluating definitions from `/nix/store/p2hby44a0qzrnd1vxcpcgfav6160rmcv-source/nixos/modules/system/activation/activatable-system.nix':
while evaluating the option `system.activationScripts.etc.text':
… while evaluating definitions from `/nix/store/p2hby44a0qzrnd1vxcpcgfav6160rmcv-source/nixos/modules/system/etc/etc-activation.nix':
while evaluating definitions from `/nix/store/p2hby44a0qzrnd1vxcpcgfav6160rmcv-source/nixos/modules/system/etc/etc.nix':
… while evaluating the option `environment.etc.dbus-1.source':
while evaluating the option `environment.systemPackages':
… while evaluating definitions from `/nix/store/vxrd24hjs9k56cjfhchyy57zs0n8kg84-source/use-module-binding.nix':
(stack trace truncated; use '--show-trace' to show the full, detailed trace)
error: The option `_includeVim' in `/nix/store/vxrd24hjs9k56cjfhchyy57zs0n8kg84-source/use-module-binding.nix' is already declared in `/nix/store/vxrd24hjs9k56cjfhchyy57zs0n8kg84-source/use-module-binding.nix'.
```
8 changes: 8 additions & 0 deletions base.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
nixpkgs.hostPlatform = "x86_64-linux";

boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;

system.stateVersion = "24.05";
}
27 changes: 27 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
description = "A very basic flake";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
};

outputs =
{ nixpkgs, ... }:
{
nixosConfigurations.use-module-binding = nixpkgs.lib.nixosSystem {
modules = [
"${nixpkgs}/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix"
./base.nix
./use-module-binding.nix
];
};
nixosConfigurations.use-module-filepath = nixpkgs.lib.nixosSystem {
modules = [
"${nixpkgs}/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix"
./base.nix
./use-module-filepath.nix
];
};
};
}
17 changes: 17 additions & 0 deletions use-module-binding.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
lib,
pkgs,
config,
...
}:
let
vim-option = import ./vim-option.nix;
in
{
imports = [
vim-option
vim-option
];

environment.systemPackages = lib.mkIf config._includeVim [ pkgs.vim ];
}
14 changes: 14 additions & 0 deletions use-module-filepath.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
lib,
pkgs,
config,
...
}:
{
imports = [
./vim-option.nix
./vim-option.nix
];

environment.systemPackages = lib.mkIf config._includeVim [ pkgs.vim ];
}
13 changes: 13 additions & 0 deletions vim-option.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{ lib, ... }:
{
options._includeVim = builtins.trace "declaring _includeVim" (
lib.mkOption {
internal = true;
default = false;
}
);

# Interestingly, this does not reproduce the same issue:
# options._includeVim = builtins.trace "declaring _includeVim" (lib.mkOption {internal = true;});
# config._includeVim = true;
}

0 comments on commit c3147a8

Please sign in to comment.