blueprint icon indicating copy to clipboard operation
blueprint copied to clipboard

Question: Is it possible to share inputs through a pulic blueprint flake

Open gaerfield opened this issue 6 months ago • 4 comments

I have problems sharing a flake publicly and I'm not sure if I misunderstood the concept or if it's a bug. I have a public flake like nixos-and-darwin-shared-homes that defines in the flake nix an additional input:

nix-index-database = {
  url = "github:nix-community/nix-index-database";
  inputs.nixpkgs.follows = "nixpkgs";
};

And a module that sets it up my-nix-index:

{ inputs, ... }: {
  imports = [
    inputs.nix-index-database.hmModules.nix-index
  ];
  # more config here
}

When pulling this public flake into my private flake:

my-public-flake = {
  url = "git+file:///home/user/my-public-flake";
  inputs.nixpkgs.follows = "nixpkgs";
};

and pulling it into one of my configurations:

{ inputs, ... }: {
  import = [
    inputs.my-public-flake.homeModules.my-nix-index
  ]
}

a nix flake check on this private repo will fail with:

       error: attribute 'nix-index-database' missing
       at /nix/store/yxndvw7rnr3l7vbchrvlv0fblch05b42-source/modules/home/my-nix-index/default.nix:5:15:
            4| {
            5|   imports = [  inputs.nix-index-database.hmModules.nix-index ];

How do I import a flake in my public flake so that is usable in a private one?

gaerfield avatar Jul 04 '25 08:07 gaerfield

It should work.

Can you give me the output of nix flake show of your public flake?

zimbatm avatar Jul 04 '25 08:07 zimbatm

Hi @zimbatm ... thx for your support! I reduced the example, the public flake is the one here: https://github.com/gaerfield/nixos-modules The command fails on the current commit because of stylix (I'm currently experimenting with it). But the commit b8a5499 does not yet contain stylix and lists the following:

╰─ nix flake show
git+file:///home/user/nixos-modules?rev=b8a549956c41a2ebde6b35ffc293d66a14117b3a
├───__functor: unknown
├───checks
│   ├───aarch64-darwin
│   │   └───pkgs-formatter omitted (use '--all-systems' to show)
│   ├───aarch64-linux
│   │   └───pkgs-formatter omitted (use '--all-systems' to show)
│   ├───x86_64-darwin
│   │   └───pkgs-formatter omitted (use '--all-systems' to show)
│   └───x86_64-linux
│       ├───nixos-vm: derivation 'nixos-system-nixos-25.11.20250624.30a61f0'
│       └───pkgs-formatter: derivation 'treefmt'
├───darwinConfigurations: unknown
├───darwinModules: unknown
├───formatter
│   ├───aarch64-darwin omitted (use '--all-systems' to show)
│   ├───aarch64-linux omitted (use '--all-systems' to show)
│   ├───x86_64-darwin omitted (use '--all-systems' to show)
│   └───x86_64-linux: package 'treefmt'
├───homeModules: unknown
├───legacyPackages
│   ├───aarch64-darwin omitted (use '--legacy' to show)
│   ├───aarch64-linux omitted (use '--legacy' to show)
│   ├───x86_64-darwin omitted (use '--legacy' to show)
│   └───x86_64-linux omitted (use '--legacy' to show)
├───lib: unknown
├───modules: unknown
├───nixosConfigurations
│   └───vm: NixOS configuration
├───nixosModules
│   ├───appimage: NixOS module
│   ├───containers: NixOS module
│   ├───gnm: NixOS module
│   ├───gui: NixOS module
│   ├───hardware: NixOS module
│   ├───networking: NixOS module
│   ├───nix: NixOS module
│   ├───os: NixOS module
│   └───virtualisation: NixOS module
├───packages
│   ├───aarch64-darwin
│   │   └───formatter omitted (use '--all-systems' to show)
│   ├───aarch64-linux
│   │   └───formatter omitted (use '--all-systems' to show)
│   ├───x86_64-darwin
│   │   └───formatter omitted (use '--all-systems' to show)
│   └───x86_64-linux
│       └───formatter: package 'treefmt'
├───systemConfigs: unknown
└───templates

The problematic configuration is in nix.nix (awkward name, I know).

And the output of nix flake show on my private flake:

╰─ nix flake show
warning: Git tree '/home/user/nixos-config' is dirty
git+file:///home/blaschke/nixos-config
├───__functor: unknown
├───checks
│   └───x86_64-linux
error:
       … while calling the 'head' builtin
         at /nix/store/h2bn031b0fj0ymv9v7bv5rcdjx58y2l9-source/lib/attrsets.nix:1534:13:
         1533|           if length values == 1 || pred here (elemAt values 1) (head values) then
         1534|             head values
             |             ^
         1535|           else

       … while evaluating the attribute 'value'
         at /nix/store/h2bn031b0fj0ymv9v7bv5rcdjx58y2l9-source/lib/modules.nix:1086:7:
         1085|     // {
         1086|       value = addErrorContext "while evaluating the option `${showOption loc}':" value;
             |       ^
         1087|       inherit (res.defsFinal') highestPrio;

       … while evaluating the option `system.build.toplevel':

       … while evaluating definitions from `/nix/store/h2bn031b0fj0ymv9v7bv5rcdjx58y2l9-source/nixos/modules/system/activation/top-level.nix':

       … while evaluating the option `assertions':

       … while evaluating definitions from `/nix/store/kdb4bks7yxcgh2nyyjmpm2x8zpb56ifn-source/nixos/common.nix':

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: attribute 'nix-index-database' missing
       at /nix/store/0wwhvbpgwf4j9x9b64y93mvdlmz3gl87-source/modules/home/base/nix.nix:12:5:
           11|   imports = [
           12|     inputs.nix-index-database.hmModules.nix-index
             |     ^
           13|   ];

gaerfield avatar Jul 04 '25 09:07 gaerfield

Interestingly nix flake show lists homeModules as unknown. When using nix repl they got listed:

╰─ nix repl
Nix 2.28.4
Type :? for help.
nix-repl> :lf .
Added 27 variables.

nix-repl> homeModules
{
  base = "/nix/store/0wwhvbpgwf4j9x9b64y93mvdlmz3gl87-source/modules/home/base";
  chromium = "/nix/store/0wwhvbpgwf4j9x9b64y93mvdlmz3gl87-source/modules/home/chromium";
  cloud = "/nix/store/0wwhvbpgwf4j9x9b64y93mvdlmz3gl87-source/modules/home/cloud";
  firefox = "/nix/store/0wwhvbpgwf4j9x9b64y93mvdlmz3gl87-source/modules/home/firefox";
  git = "/nix/store/0wwhvbpgwf4j9x9b64y93mvdlmz3gl87-source/modules/home/git";
  gnome = "/nix/store/0wwhvbpgwf4j9x9b64y93mvdlmz3gl87-source/modules/home/gnome";
  java-development = "/nix/store/0wwhvbpgwf4j9x9b64y93mvdlmz3gl87-source/modules/home/java-development";
  shell = "/nix/store/0wwhvbpgwf4j9x9b64y93mvdlmz3gl87-source/modules/home/shell";
  terminal = "/nix/store/0wwhvbpgwf4j9x9b64y93mvdlmz3gl87-source/modules/home/terminal";
  track-working-day = "/nix/store/0wwhvbpgwf4j9x9b64y93mvdlmz3gl87-source/modules/home/track-working-day";
  virtualisation = "/nix/store/0wwhvbpgwf4j9x9b64y93mvdlmz3gl87-source/modules/home/virtualisation";
  vscode = "/nix/store/0wwhvbpgwf4j9x9b64y93mvdlmz3gl87-source/modules/home/vscode";
}

gaerfield avatar Jul 04 '25 09:07 gaerfield

It should work.

Can you give me the output of nix flake show of your public flake?

@zimbatm I got curious and tried a minimum reproducing example:

  • https://github.com/gaerfield/blueprint-120-public
  • https://github.com/gaerfield/blueprint-120-consumer

And I wasn't able to reproduce this there. What have I messed up in my repo? Anyway, I'm going to close this issue. No need to invest time in this further. I will give an update as soon as I have identified the root cause in my config.

gaerfield avatar Jul 04 '25 19:07 gaerfield