Skip to content

Commit

Permalink
Basic Go provider
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksrutins committed Dec 29, 2023
1 parent 8c7a4dd commit e765d8e
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 0 deletions.
155 changes: 155 additions & 0 deletions examples/go/flake.lock

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

10 changes: 10 additions & 0 deletions examples/go/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
description = "A go 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: {
packages.packsnap-go = packsnap.lib.${system}.build { name = "packsnap-go"; path = ./.; };
});
}
3 changes: 3 additions & 0 deletions examples/go/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module packsnap.farthergate.com/example-go

go 1.16
Empty file added examples/go/go.sum
Empty file.
7 changes: 7 additions & 0 deletions examples/go/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "fmt"

func main() {
fmt.Println("Hello Nix!")
}
1 change: 1 addition & 0 deletions lib/providers/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ let
(import ./node.nix { inherit pkgs npmlock2nix; })
# Deno MUST come after Node!
(import ./deno.nix { inherit pkgs; })
(import ./go.nix { inherit pkgs; })
];
in with builtins;
{
Expand Down
29 changes: 29 additions & 0 deletions lib/providers/go.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{ pkgs }:
let plan = import ../plan { inherit pkgs; };
in {
detect = path:
(builtins.pathExists /./${path}/go.mod);

plan = path:
let derivation = pkgs.stdenv.mkDerivation {
name = "packsnap-build-" + (builtins.baseNameOf path);
src = path;

nativeBuildInputs = [pkgs.go];

configurePhase = ''
go mod download
'';

buildPhase = ''
# this line removes a bug where value of $HOME is set to a non-writable /homeless-shelter dir (see https://github.com/NixOS/nix/issues/670#issuecomment-1211700127)
export HOME=$(pwd)
go build -o packsnap-out
'';

installPhase = ''
mkdir -p $out && cp packsnap-out $out
'';
};
in plan.buildPlan [] [derivation] [] "${derivation}/packsnap-out";
}

0 comments on commit e765d8e

Please sign in to comment.