63 lines
1.9 KiB
Nix
63 lines
1.9 KiB
Nix
{
|
|
# Packages a selected local source tree so the derivation only sees the
|
|
# files that the example deliberately includes.
|
|
description = "Package a local source tree with fileset";
|
|
|
|
inputs = {
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
|
};
|
|
|
|
outputs =
|
|
{ self, nixpkgs, ... }:
|
|
let
|
|
system = "x86_64-linux";
|
|
pkgs = import nixpkgs { inherit system; };
|
|
sourceFiles = pkgs.lib.fileset.unions [
|
|
./src/message.txt
|
|
./src/run.sh
|
|
];
|
|
selectedSource = pkgs.lib.fileset.toSource {
|
|
root = ./.;
|
|
fileset = sourceFiles;
|
|
};
|
|
in
|
|
{
|
|
packages.${system}.default = pkgs.stdenv.mkDerivation {
|
|
pname = "source-greet";
|
|
version = "0.1.0";
|
|
src = selectedSource;
|
|
dontBuild = true;
|
|
dontUnpack = true;
|
|
|
|
installPhase = ''
|
|
mkdir -p $out/bin $out/share/source-greet
|
|
cp $src/src/message.txt $out/share/source-greet/message.txt
|
|
cp $src/src/run.sh $out/bin/source-greet
|
|
chmod +x $out/bin/source-greet
|
|
|
|
substituteInPlace $out/bin/source-greet \
|
|
--replace-fail "@bash@" "${pkgs.bash}/bin/bash" \
|
|
--replace-fail "@message@" "$out/share/source-greet/message.txt"
|
|
'';
|
|
};
|
|
|
|
apps.${system}.default = {
|
|
type = "app";
|
|
program = "${self.packages.${system}.default}/bin/source-greet";
|
|
meta.description = "Run the package built from the selected local source tree.";
|
|
};
|
|
|
|
checks.${system}.selected-source = pkgs.runCommand "selected-source-check" { } ''
|
|
[ ! -e ${selectedSource}/ignored.txt ]
|
|
output="$(${self.packages.${system}.default}/bin/source-greet)"
|
|
|
|
if [ "$output" = "hello from the selected source tree" ]; then
|
|
echo ok > "$out"
|
|
else
|
|
echo "unexpected output: $output" >&2
|
|
exit 1
|
|
fi
|
|
'';
|
|
};
|
|
}
|