Skip to content

toSource, need alternative implementation #8

@qknight

Description

@qknight

Question

In the nix/derivations/default.nix there are several src= blocks:

  • Some use fixed paths to show that evaluation in principle works with fixed paths.
  • Some use relativeFileset as a hack to make toSource work with a dynamic project_root argument.
  • And then there is the naive attempt to use toSource with project_root without the relativeFileset hack, which fails...

https://github.com/NixOS/nixpkgs/blob/c385f4d30bb544e1c7b1a5d18a55e5379ebd3bc8/lib/fileset/default.nix#L420:C3

Can we add a variant of lib.fileset.toSource (like lib.fileset.toSourceRelative) which:

  • sees root as a baseDir and
  • fileset = lib.fileset.unions [ as a list of files relative to baseDir

Contrast: toSource sees root as a prefix which needs to be removed from all the entries in the given fileset.

project_root = /home/foo/myproject;
src = lib.fileset.toSourceRelative {
    root = project_root;
    fileset = lib.fileset.unions [
        src/main.rs
        src/build.rs
    ];
};

In case you want to reproduce / experiment with this, I've added this repository with all variants:

https://github.com/qknight/nix-toSource-need-help?tab=readme-ov-file#question

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions