Skip to content

Instantly share code, notes, and snippets.

@icetan
Last active June 27, 2022 13:11
Show Gist options
  • Save icetan/5702517a3fb7d132c46dfa465ed42a12 to your computer and use it in GitHub Desktop.
Save icetan/5702517a3fb7d132c46dfa465ed42a12 to your computer and use it in GitHub Desktop.
Trying out subflakes and relative paths

Root flake file flake.nix:

{
  inputs = {
    utils.url = "github:numtide/flake-utils/bee6a7250dd1b01844a2de7e02e4df7d8a0a206c";
    sub1.url = "path:./sub1";
  };
  outputs = { nixpkgs, utils, sub1, ... }:
    utils.lib.eachDefaultSystem (system: {
      packages = {
        inherit (sub1.packages.${system}) hello;
      };
    });
}

Subflake file sub1/flake.nix:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/9a17f325397d137ac4d219ecbd5c7f15154422f4";
    utils.url = "github:numtide/flake-utils/bee6a7250dd1b01844a2de7e02e4df7d8a0a206c";
  };
  outputs = { nixpkgs, utils, ... }:
    utils.lib.eachDefaultSystem (system:
      let
        legacyPackages = import nixpkgs { inherit system; };
      in
      {
        packages = {
          inherit (legacyPackages) hello;
        };
      });
}

When I run nix flake show with latest from lazy-trees branch:

nix run github:edolstra/nix/04cb555aebfff68732cc7f0120def20449515eea -- flake show --show-trace

I get the output:

path:/home/icetan/src/nix/test-subflakes
└───packages
    ├───aarch64-darwin
error: in pure evaluation mode, 'fetchTree' requires a locked input, at (string):16:18

       … while realising the context of a path

       at «string»:20:19:

           19|
           20|           flake = import (sourceInfo + (if subdir != "" then "/" else "") + subdir + "/flake.nix");
             |                   ^
           21|

       … while evaluating anonymous lambda

       at «string»:10:13:

            9|     builtins.mapAttrs
           10|       (key: node:
             |             ^
           11|         let

       … from call site

       … while evaluating anonymous lambda

       at «string»:23:25:

           22|           inputs = builtins.mapAttrs
           23|             (inputName: inputSpec: allNodes.${resolveInput inputSpec})
             |                         ^
           24|             (node.inputs or {});

       … from call site

I expect something more like when running nix flake show using nix (Nix) 2.9.1:

path:/home/icetan/src/nix/test-subflakes?lastModified=1656334768&narHash=sha256-ODEqelm5y%2fVQkVkX11EWMWOHFpH+8wMZpEySuE0lPWY=
└───packages
    ├───aarch64-darwin
    │   └───hello: package 'hello-2.12'
    ├───aarch64-linux
    │   └───hello: package 'hello-2.12'
    ├───i686-linux
    │   └───hello: package 'hello-2.12'
    ├───x86_64-darwin
    │   └───hello: package 'hello-2.12'
    └───x86_64-linux
        └───hello: package 'hello-2.12'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment