Skip to content

Commit

Permalink
Merge pull request #10 from thiagokokada/static-build-nix
Browse files Browse the repository at this point in the history
Add twenty-twenty-twenty-static to flake.nix
  • Loading branch information
thiagokokada authored Jan 10, 2024
2 parents 1dd295f + 56d563a commit a978335
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 36 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,8 @@ jobs:

- uses: DeterminateSystems/magic-nix-cache-action@main

- name: Check Flake
run: nix flake check

- name: Build
run: nix build
49 changes: 13 additions & 36 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,47 +19,24 @@
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; });
in
{
apps.default = forAllSystems (system: {
type = "app";
program = "${self.packages.${system}.twenty-twenty-twenty}/bin/twenty-twenty-twenty";
apps = forAllSystems (system: {
default = {
type = "app";
program = nixpkgs.lib.getExe self.packages.${system}.twenty-twenty-twenty;
};
});

packages = forAllSystems (system:
let pkgs = nixpkgsFor.${system};
in {
default = self.packages.${system}.twenty-twenty-twenty;
twenty-twenty-twenty = pkgs.buildGoModule {
pname = "twenty-twenty-twenty";
twenty-twenty-twenty = pkgs.callPackage ./twenty-twenty-twenty.nix { inherit version; };
twenty-twenty-twenty-static = (pkgs.callPackage ./twenty-twenty-twenty.nix rec {
inherit version;
src = ./.;
vendorHash = "sha256-3RtdnS4J7JbdU+jMTEzClSlDDPh6bWqbjchvrtS8HUc";

nativeBuildInputs = with pkgs; lib.optionals stdenv.hostPlatform.isLinux [
pkg-config
];

buildInputs = with pkgs;
lib.optionals stdenv.hostPlatform.isLinux [
alsa-lib
] ++
lib.optionals stdenv.hostPlatform.isDarwin [
darwin.apple_sdk_11_0.frameworks.MetalKit
darwin.apple_sdk_11_0.frameworks.UserNotifications
];

# Tests are mostly useful for development, not to ensure that
# program is running correctly.
doCheck = false;

ldflags = [ "-X=main.version=${version}" ];

meta = with pkgs.lib; {
description = "Alerts every 20 minutes to look something at 20 feet away for 20 seconds";
homepage = "https://github.com/thiagokokada/twenty-twenty-twenty";
license = licenses.mit;
mainProgram = "twenty-twenty-twenty";
};
};
inherit (pkgs.pkgsStatic) alsa-lib stdenv;
buildGoModule = pkgs.buildGoModule.override { inherit stdenv; };
extraLdflags = [ "-linkmode external" ''-extldflags "-static"'' ];
});
});

devShells = forAllSystems (system:
Expand All @@ -72,8 +49,8 @@
gnumake
go
gopls
]
++ lib.optionals stdenv.hostPlatform.isLinux [
] ++
lib.optionals stdenv.hostPlatform.isLinux [
alsa-lib
gcc
pkg-config
Expand Down
41 changes: 41 additions & 0 deletions twenty-twenty-twenty.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{ lib
, stdenv
, alsa-lib
, buildGoModule
, darwin
, pkg-config
, extraLdflags ? [ ]
, version ? "unknown"
}:

buildGoModule {
pname = "twenty-twenty-twenty";
inherit version;
src = lib.cleanSource ./.;
vendorHash = "sha256-3RtdnS4J7JbdU+jMTEzClSlDDPh6bWqbjchvrtS8HUc";

nativeBuildInputs = lib.optionals stdenv.hostPlatform.isLinux [
pkg-config
];

buildInputs = lib.optionals stdenv.hostPlatform.isLinux [
alsa-lib
] ++
lib.optionals stdenv.hostPlatform.isDarwin [
darwin.apple_sdk_11_0.frameworks.MetalKit
darwin.apple_sdk_11_0.frameworks.UserNotifications
];

# Tests are mostly useful for development, not to ensure that
# program is running correctly.
doCheck = false;

ldflags = [ "-X=main.version=${version}" ] ++ extraLdflags;

meta = with lib; {
description = "Alerts every 20 minutes to look something at 20 feet away for 20 seconds";
homepage = "https://github.com/thiagokokada/twenty-twenty-twenty";
license = licenses.mit;
mainProgram = "twenty-twenty-twenty";
};
}

0 comments on commit a978335

Please sign in to comment.