-
-
Notifications
You must be signed in to change notification settings - Fork 16.5k
Open
hercules-ci/flake-parts
#251Labels
0.kind: bugSomething is brokenSomething is broken6.topic: flakesThe experimental Nix featureThe experimental Nix feature6.topic: nixosIssues or PRs affecting NixOS modules, or package usability issues specific to NixOSIssues or PRs affecting NixOS modules, or package usability issues specific to NixOS
Description
Describe the bug
Importing multiple times a given NixOS module exposed by a flake is not allowed. Nix complains about options being already declared.
Steps To Reproduce
- Define a flake that expose a NixOS module which declare at least one option:
flake.nix:{ outputs = { self }: { nixosModules.debug = { config, lib, ... }: { options = { debug = { enable = lib.mkOption { type = lib.types.bool; default = false; description = '' Whether to enable debug. ''; }; }; }; config = lib.mkIf config.debug.enable { systemd.globalEnvironment = { SYSTEMD_LOG_LEVEL = "debug"; }; }; }; }; }
- Define another flake that uses the previous flake:
flake.nix:{ inputs.nixpkgs.url = github:NixOS/nixpkgs/nixos-22.05; inputs.debug.url = path:/home/me/flakes/debug; outputs = inputs@{ self, nixpkgs, ... }: { nixosConfigurations.mymachine = nixpkgs.lib.nixosSystem { system = "x86_64-linux"; modules = [ (import ./configuration.nix) ]; specialArgs = { inherit inputs; }; }; }; }
configuration.nix:{ config, pkgs, inputs, ... }: { imports = [ ./hardware-configuration.nix inputs.debug.nixosModules.debug inputs.debug.nixosModules.debug ]; # here goes the rest of the config }
- Build the configuration and notice the error
$ nixos-rebuild switch --flake .#mymachine building the system configuration... error: The option `debug.enable' in `/nix/store/da9dyx30lsdgw2x2gnxkc88aq1d9fwik-source/flake.nix' is already declared in `/nix/store/da9dyx30lsdgw2x2gnxkc88aq1d9fwik-source/flake.nix'. (use '--show-trace' to show detailed location information)
Expected behavior
It should be allowed to import multiple times a NixOS module that declare options. It already works today unless this module is exposed by a flake.
Importing multiple times into the same module is not very useful. What is useful is to import the same module (i.e.: D) into several modules (i.e.: B, C) which are themselves imported into one final module (i.e.: A):
- A import B
- A import C
- B import D
- C import D
nix-env --version output
nix-env (Nix) 2.11.0
dixslyf, bzm3r, ngkz, 3Dcube, Bohreromir and 3 more
Metadata
Metadata
Assignees
Labels
0.kind: bugSomething is brokenSomething is broken6.topic: flakesThe experimental Nix featureThe experimental Nix feature6.topic: nixosIssues or PRs affecting NixOS modules, or package usability issues specific to NixOSIssues or PRs affecting NixOS modules, or package usability issues specific to NixOS