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:
commit
c9afaba3df
4 changed files with 58 additions and 0 deletions
21
template/package/flake.nix
Normal file
21
template/package/flake.nix
Normal 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;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
3
template/package/hello/hello.sh
Normal file
3
template/package/hello/hello.sh
Normal file
|
@ -0,0 +1,3 @@
|
|||
#!@shell@
|
||||
|
||||
echo Hello world
|
22
template/package/hello/package.nix
Normal file
22
template/package/hello/package.nix
Normal 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
|
||||
'';
|
||||
})
|
12
template/package/hello/test.nix
Normal file
12
template/package/hello/test.nix
Normal file
|
@ -0,0 +1,12 @@
|
|||
{ hello, runCommand }:
|
||||
|
||||
runCommand "test-hello"
|
||||
{
|
||||
inherit hello;
|
||||
} ''
|
||||
(
|
||||
set -x
|
||||
[[ "Hello world" == "$(${hello}/bin/hello)" ]]
|
||||
)
|
||||
touch $out
|
||||
''
|
Loading…
Reference in a new issue