1
0
Fork 0
mirror of https://github.com/hercules-ci/flake-parts.git synced 2024-12-14 11:47:31 +00:00

Merge pull request #190 from hercules-ci/template-package

Add template/package
This commit is contained in:
Robert Hensing 2023-10-03 16:30:47 +02:00 committed by GitHub
commit c9afaba3df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 58 additions and 0 deletions

View file

@ -0,0 +1,21 @@
{
description = "Description for the project";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs = inputs@{ flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ];
perSystem = { config, pkgs, ... }: {
packages.default = config.packages.hello;
packages.hello = pkgs.callPackage ./hello/package.nix { };
checks.hello = pkgs.callPackage ./hello/test.nix {
hello = config.packages.hello;
};
};
};
}

View file

@ -0,0 +1,3 @@
#!@shell@
echo Hello world

View file

@ -0,0 +1,22 @@
{ stdenv, lib, runtimeShell }:
# Example package in the style that `mkDerivation`-based packages in Nixpkgs are written.
stdenv.mkDerivation (finalAttrs: {
name = "hello";
src = lib.cleanSourceWith {
src = ./.;
filter = path: type:
type == "regular" -> baseNameOf path == "hello.sh";
};
buildPhase = ''
# Note that Nixpkgs has builder functions for simple packages
# like this, but this template avoids it to make for a more
# complete example.
substitute hello.sh hello --replace '@shell@' ${runtimeShell}
cat hello
chmod a+x hello
'';
installPhase = ''
install -D hello $out/bin/hello
'';
})

View file

@ -0,0 +1,12 @@
{ hello, runCommand }:
runCommand "test-hello"
{
inherit hello;
} ''
(
set -x
[[ "Hello world" == "$(${hello}/bin/hello)" ]]
)
touch $out
''