英文:
Create a derivation in Nix to only copy some files
问题
我有一些文件在一个文件夹中,我想创建一个派生以将它们作为输入传递给后面的 dockerTools.buildImage
。
我不确定如何做这个。以下不起作用:
database = pkgs.stdenv.mkDerivation {
name = "database";
src = "./";
phases = [ "installPhase" ];
installPhase = ''
pwd
ls -al
echo $src
cp $src/.env $out
cp $src/20221002.sqlite $out
'';
};
因为 cp
找不到这些文件。
英文:
I have some files in a folder that I want to create a derivation out of to pass them as inputs to dockerTools.buildImage
later.
I'm not sure how to do this. This doesn't work:
database = pkgs.stdenv.mkDerivation {
name = "database";
src = "./";
phases = [ "installPhase" ];
installPhase = ''
pwd
ls -al
echo $src
cp $src/.env $out
cp $src/20221002.sqlite $out
'';
};
Because cp
can't find the files.
答案1
得分: 1
数据库 = pkgs.stdenv.mkDerivation {
名称 = "数据库";
src = ./.;
阶段 = [ "unpackPhase" "installPhase" ];
installPhase = '''
mkdir -p $out
cp $src/.env $out
cp $src/20221002.sqlite $out
''';
};
英文:
Turns out this is what's necessary for this to work:
database = pkgs.stdenv.mkDerivation {
name = "database";
src = ./.;
phases = [ "unpackPhase" "installPhase" ];
installPhase = ''
mkdir -p $out
cp $src/.env $out
cp $src/20221002.sqlite $out
'';
};
The src
attribute needs to point to the current directory and then everything in there will be copied over.
The copying only happens when unpackPhase
is part of the phases.
Then in the installPhase
we need to drop into shell to do the actual work. $out
means the output path of the derivation and $src
is set to the folder of the src
. In many cases $out is just a file but in this case since we want it to contain two files, we have to mkdir
it first and then we can cp
both files into it.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论