diff --git a/template/package/flake.nix b/template/package/flake.nix new file mode 100644 index 0000000..385e6cb --- /dev/null +++ b/template/package/flake.nix @@ -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; + }; + }; + }; +} diff --git a/template/package/hello/hello.sh b/template/package/hello/hello.sh new file mode 100644 index 0000000..30a4bc0 --- /dev/null +++ b/template/package/hello/hello.sh @@ -0,0 +1,3 @@ +#!@shell@ + +echo Hello world diff --git a/template/package/hello/package.nix b/template/package/hello/package.nix new file mode 100644 index 0000000..cfc64bc --- /dev/null +++ b/template/package/hello/package.nix @@ -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 + ''; +}) diff --git a/template/package/hello/test.nix b/template/package/hello/test.nix new file mode 100644 index 0000000..424e4a8 --- /dev/null +++ b/template/package/hello/test.nix @@ -0,0 +1,12 @@ +{ hello, runCommand }: + +runCommand "test-hello" +{ + inherit hello; +} '' + ( + set -x + [[ "Hello world" == "$(${hello}/bin/hello)" ]] + ) + touch $out +''