Skip to content

Commit

Permalink
Allow building with a custom derivation
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksrutins committed Dec 28, 2023
1 parent 7ce29dc commit 08f3058
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 12 deletions.
155 changes: 155 additions & 0 deletions examples/custom-plan/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions examples/custom-plan/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
description = "A custom plan example for Packsnap";

inputs.packsnap.url = "../..";
inputs.flake-utils.url = "github:numtide/flake-utils";

outputs = { self, nixpkgs, flake-utils, packsnap }: flake-utils.lib.eachDefaultSystem (system:
let pkgs = (import nixpkgs) { inherit system; };
in {
packages.packsnap-custom-plan = packsnap.lib.${system}.buildCustomPlan {
name = "packsnap-custom-plan";
contents = [
(pkgs.stdenv.mkDerivation {
name = "packsnap-custom-plan";
inherit system;

src = ./.;
nativeBuildInputs = [
pkgs.gcc
pkgs.pkg-config
pkgs.meson
pkgs.ninja
];
})
];
start = "packsnap-custom-plan";
};
}
);
}
12 changes: 12 additions & 0 deletions examples/custom-plan/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <stdio.h>

#define PROJECT_NAME "packsnap-custom-plan"

int main(int argc, char **argv) {
if(argc != 1) {
printf("%s takes no arguments.\n", argv[0]);
return 1;
}
puts("Hello, Packsnap from C!");
return 0;
}
8 changes: 8 additions & 0 deletions examples/custom-plan/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
project('custom-plan', 'c',
version : '0.1',
default_options : ['warning_level=3'])

exe = executable('packsnap-custom-plan', 'main.c',
install : true)

test('basic', exe)
6 changes: 3 additions & 3 deletions examples/deno/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions examples/nextjs/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions examples/rust/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
, misc ? import ./misc.nix {}
, naersk
, npmlock2nix }:
let providers = import ./providers { inherit pkgs naersk npmlock2nix; };
let
providers = import ./providers { inherit pkgs naersk npmlock2nix; };
plan = import ./plan { inherit pkgs; };
in {
build = ({ name ? "packsnap-image", path }:
build = ({ name ? "packsnap-image", tag ? "latest", path }:
let provider = providers.planBuild path;
in pkgs.dockerTools.buildImage ((provider.plan path) // { name = name; tag = "latest"; })
in pkgs.dockerTools.buildImage ((provider.plan path) // { inherit name tag; })
);
buildCustomPlan = ({ name ? "packsnap-image", tag ? "latest", variables ? [], contents, libraries ? [], start }:
pkgs.dockerTools.buildImage ((plan.buildPlan variables contents libraries start) // { inherit name tag; }));
}

0 comments on commit 08f3058

Please sign in to comment.