Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add polyform to flake packages #54

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ cert.pem
key.pem

# nix
result
/result/
/result-.*/

Expand Down
119 changes: 38 additions & 81 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,65 +4,45 @@
utils.url = "github:numtide/flake-utils";
};

outputs =
{
self,
nixpkgs,
utils,
}:
utils.lib.eachDefaultSystem (
system:
outputs = inputs@{ nixpkgs, utils, ... }:
utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };

# Anytime dependencies update or change, we will need to update this.
# This ensures a package is reproducible.
vendorHash = "sha256-7V82ePT5So0dgoQfMUEncejO8gMjLoKRS1ixncSiSHA=";
vendorHash = "sha256-mTPSIwBNcZQm+YYrtHr6ed903KQYCN8U39lLAI/0ZWw=";

polywasm =
GOOS: GOARCH:
with pkgs;
polyform = with pkgs;
(buildGoModule {
inherit vendorHash;
name = "polywasm";
name = "polyform";
src = ./.;
CGO_ENABLED = 0;
subPackages = [ "cmd/polywasm" ];
subPackages = [ "cmd/polyform" ];
});

# uncomment to skip running tests as part of build
# doCheck = false;
}).overrideAttrs
(
old:
old
// {
inherit GOOS GOARCH;
CGO_ENABLED = 0;
}
);
examples = with pkgs;
lib.mapAttrs (name: path:
(buildGoModule {
inherit name vendorHash;
src = ./.;
CGO_ENABLED = 0;
subPackages = [ "examples/${name}" ];
})) (lib.filterAttrs (n: v: v == "directory")
(builtins.readDir ./examples));

examples =
GOOS: GOARCH:
mkExamplesCross = GOOS: GOARCH:
with pkgs;
lib.mapAttrs (
name: path:
lib.mapAttrs (name: path:
(buildGoModule {
inherit name vendorHash;
src = ./.;
CGO_ENABLED = 0;
subPackages = [ "examples/${name}" ];

# uncomment to skip running tests as part of build
# doCheck = false;
}).overrideAttrs
(
old:
old
// {
inherit GOOS GOARCH;
}
)
) (lib.filterAttrs (n: v: v == "directory") (builtins.readDir ./examples));
}).overrideAttrs (old: old // { inherit GOOS GOARCH; }))
(lib.filterAttrs (n: v: v == "directory")
(builtins.readDir ./examples));

supportedGoPlatforms = [
"linux/amd64"
Expand All @@ -73,57 +53,34 @@
"windows/amd64"
];

withEachPlatform =
module:
withEachPlatform = module:
with pkgs;
(lib.foldl lib.mergeAttrs { } (
map (
platform:
let
parts = lib.splitString "/" platform;
GOOS = builtins.elemAt parts 0;
GOARCH = builtins.elemAt parts 1;
in
{
${GOOS} = {
${GOARCH} = module GOOS GOARCH;
};
}
) supportedGoPlatforms
));
(lib.foldl lib.mergeAttrs { } (map (platform:
let
parts = lib.splitString "/" platform;
GOOS = builtins.elemAt parts 0;
GOARCH = builtins.elemAt parts 1;
in { ${GOOS} = { ${GOARCH} = module GOOS GOARCH; }; })
supportedGoPlatforms));

in
{
in {
packages = {
default = polywasm;
examples = examples;
crossBuild = {
polywasm = withEachPlatform polywasm;
examples = withEachPlatform examples;
};
inherit polyform examples;
default = polyform;
examplesCross = withEachPlatform mkExamplesCross;
};

apps = {
release = {
type = "app";
program = toString (
pkgs.writers.writeBash "release" ''
${pkgs.goreleaser}/bin/goreleaser release
''
);
program = toString (pkgs.writers.writeBash "release" ''
${pkgs.goreleaser}/bin/goreleaser release
'');
};
};

devShell = pkgs.mkShell {
packages = with pkgs; [
go
gopls
gotools
go-tools
goreleaser
];
packages = with pkgs; [ go gopls gotools go-tools goreleaser ];
};

}
);
});
}
Loading