Hi!
I am experimenting with Nix as a build tool for C programs. Simple flow (compile object files, then link) works fine. However, I got a problem with code generation.
When I define generator binary as a derivation and then use this derivation as a builder in another derivation, i get an error:
I uploaded MRE to GitHub: GitHub - maxxk/nix-build-with-generator
An here is a complete default.nix:
error: the string 'q2hpfyc1pn7v8c19g7hzzznmqqc2f6yw-generator-source.txt.c.o'
is not allowed to refer to a store path
(such as '!out!/nix/store/10y7a1vv8rxw2z0xb4x29aq1ghfrg9b9-generator-source.txt.c.drv')
{ pkgs ? import <nixpkgs> {}}:
let
link = { name, inputs, args ? []}: derivation {
inherit (pkgs) system;
inherit name;
builder = "${pkgs.stdenv.cc}/bin/cc";
args = [
"-o"
(placeholder "out")
] ++ inputs ++ args;
};
cc = { input, args ? [] }: link {
name = "${baseNameOf input}.o";
inputs = [ input ];
args = [ "-c" ] ++ args;
};
generator-bin = link ({ name = "generator"; inputs = [ ./generator.c ]; });
generate = { input }: derivation {
inherit (pkgs) system;
name = "${baseNameOf input}.c";
builder = generator-bin;
args = [
input
(placeholder "out")
];
};
hello-c = generate { input = ./generator-source.txt; };
sources = [ hello-c ./program.c ];
objs = map (source: cc { input = source; }) sources;
bin = link { name = "program"; inputs = objs; };
bin2 = link { name = "program2"; inputs = [ (cc { input = ./program.c; }) ]; };
in
bin
# bin2