2022-03-12 10:29:25 +01:00
|
|
|
{
|
|
|
|
description = "an offline-capable xkcd webcomic reader written in Go";
|
|
|
|
|
2022-04-27 02:56:01 +02:00
|
|
|
inputs = {
|
2022-05-02 14:39:31 +02:00
|
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
2022-05-03 20:22:43 +02:00
|
|
|
nixgl.url = "github:guibou/nixGL";
|
|
|
|
nixgl.inputs.nixpkgs.follows = "nixpkgs";
|
2022-04-27 02:23:31 +02:00
|
|
|
flake-compat = {
|
|
|
|
url = "github:edolstra/flake-compat";
|
|
|
|
flake = false;
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
2022-04-26 15:08:36 +02:00
|
|
|
};
|
2022-03-12 10:29:25 +01:00
|
|
|
|
2022-05-03 20:22:43 +02:00
|
|
|
outputs = { self, nixgl, nixpkgs, ... }:
|
2022-03-12 10:29:25 +01:00
|
|
|
let
|
|
|
|
|
|
|
|
# to work with older version of flakes
|
2022-04-27 02:56:01 +02:00
|
|
|
lastModifiedDate =
|
|
|
|
self.lastModifiedDate or self.lastModified or "19700101";
|
2022-03-12 10:29:25 +01:00
|
|
|
|
|
|
|
# Generate a user-friendly version number.
|
2022-05-03 20:22:43 +02:00
|
|
|
# version = builtins.substring 0 8 lastModifiedDate;
|
2022-05-15 11:27:48 +02:00
|
|
|
version = "v0.0.13";
|
2022-03-12 10:29:25 +01:00
|
|
|
|
|
|
|
# System types to support.
|
2022-04-27 02:56:01 +02:00
|
|
|
supportedSystems =
|
|
|
|
[ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
|
2022-03-12 10:29:25 +01:00
|
|
|
|
|
|
|
# Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'.
|
|
|
|
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
|
|
|
|
|
|
|
|
# Nixpkgs instantiated for supported system types.
|
2022-05-20 19:52:31 +02:00
|
|
|
nixpkgsFor = forAllSystems (system: import nixpkgs {
|
|
|
|
inherit system;
|
|
|
|
overlays = [
|
|
|
|
(import ./overlay.nix)
|
|
|
|
];
|
|
|
|
});
|
2022-03-12 10:29:25 +01:00
|
|
|
in
|
2022-05-03 20:22:43 +02:00
|
|
|
rec {
|
2022-03-12 10:29:25 +01:00
|
|
|
packages = forAllSystems (system:
|
2022-05-03 20:22:43 +02:00
|
|
|
let
|
|
|
|
pkgs = nixpkgsFor.${system};
|
2022-05-20 19:52:31 +02:00
|
|
|
inherit (pkgs) lib overlays;# -> lib = pkgs.lib;overlays = pkgs.overlays;
|
2022-04-27 02:56:01 +02:00
|
|
|
in
|
|
|
|
rec {
|
2022-05-03 20:22:43 +02:00
|
|
|
go-xkcdreader = with pkgs; buildGoModule rec {
|
2022-03-12 10:29:25 +01:00
|
|
|
pname = "go-xkcdreader";
|
2022-05-03 20:22:43 +02:00
|
|
|
buildInputs = [
|
|
|
|
gcc
|
|
|
|
libglvnd # instead of libGL
|
|
|
|
wayland
|
|
|
|
libxkbcommon
|
|
|
|
xorg.libX11
|
|
|
|
xorg.libXcursor
|
|
|
|
xorg.libXfixes
|
|
|
|
xorg.libXrandr
|
|
|
|
xorg.libXrender
|
|
|
|
xorg.xrandr
|
|
|
|
xorg.libXinerama
|
|
|
|
xorg.xinput
|
|
|
|
xorg.libXi
|
|
|
|
xorg.libXxf86vm
|
|
|
|
# xorg.xorgserver
|
|
|
|
];
|
|
|
|
nativeBuildInputs = [ pkgconfig ];
|
|
|
|
|
2022-03-12 10:29:25 +01:00
|
|
|
inherit version;
|
2022-05-06 22:29:17 +02:00
|
|
|
doCheck = false;
|
2022-05-03 20:22:43 +02:00
|
|
|
# use go.mod for managing go deps, instead of vendor-only dir
|
|
|
|
proxyVendor = true;
|
|
|
|
tags = [ "wayland" ]; # go "-tags" to build with
|
|
|
|
ldflags = [
|
|
|
|
"-s"
|
|
|
|
"-w"
|
2022-05-12 15:54:16 +02:00
|
|
|
"-X cmd.version=${version}"
|
2022-05-03 20:22:43 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
modSha256 = lib.fakeSha256;
|
2022-05-20 19:52:31 +02:00
|
|
|
# dont't forget to update vendorSha256 whenever go.mod or go.sum change
|
2022-05-29 21:05:28 +02:00
|
|
|
vendorSha256 = "sha256-LvdcTbj8cFlaIBsq1VLfLF2Tu9HiZzGO8igD766nMLE=";
|
2022-05-03 20:22:43 +02:00
|
|
|
|
2022-03-12 10:29:25 +01:00
|
|
|
# In 'nix develop', we don't need a copy of the source tree
|
|
|
|
# in the Nix store.
|
2022-05-03 20:22:43 +02:00
|
|
|
src = lib.cleanSource ./.;
|
|
|
|
|
|
|
|
meta = {
|
|
|
|
description = "an offline-capable xkcd webcomic reader written in Go";
|
|
|
|
homepage = "https://git.dotya.ml/wanderer/go-xkcdreader";
|
|
|
|
license = lib.licenses.gpl3;
|
|
|
|
maintainers = [ "wanderer" ];
|
|
|
|
platforms = lib.platforms.linux ++ lib.platforms.darwin;
|
|
|
|
};
|
2022-03-12 10:29:25 +01:00
|
|
|
};
|
2022-05-03 20:22:43 +02:00
|
|
|
default = go-xkcdreader;
|
2022-03-12 10:29:25 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2022-04-26 13:51:11 +02:00
|
|
|
apps = forAllSystems (system: rec {
|
|
|
|
go-xkcdreader = {
|
|
|
|
type = "app";
|
2022-04-27 02:56:01 +02:00
|
|
|
program =
|
|
|
|
"${self.packages.${system}.go-xkcdreader}/bin/go-xkcdreader";
|
2022-04-26 13:51:11 +02:00
|
|
|
};
|
|
|
|
default = go-xkcdreader;
|
2022-03-12 10:29:25 +01:00
|
|
|
});
|
|
|
|
|
2022-04-27 02:56:01 +02:00
|
|
|
devShells = forAllSystems (system:
|
2022-05-03 20:22:43 +02:00
|
|
|
let
|
|
|
|
pkgs = import nixpkgs {
|
|
|
|
inherit system;
|
|
|
|
overlays = [ nixgl.overlay ];
|
|
|
|
};
|
2022-05-20 19:52:31 +02:00
|
|
|
goPkgs = import nixpkgs {
|
|
|
|
useFetched = true;
|
|
|
|
inherit system;
|
|
|
|
overlays = self.overlays or [ ] ++ [
|
|
|
|
(import ./overlay.nix)
|
|
|
|
];
|
|
|
|
};
|
2022-05-20 22:16:11 +02:00
|
|
|
gob = pkgs.writeShellScriptBin "gob" ''
|
|
|
|
cd $(git rev-parse --show-toplevel)
|
|
|
|
go build -v ./...
|
|
|
|
'';
|
|
|
|
gota = pkgs.writeShellScriptBin "gota" ''
|
|
|
|
cd $(git rev-parse --show-toplevel)
|
|
|
|
go test ./...
|
|
|
|
'';
|
2022-05-21 19:41:43 +02:00
|
|
|
upcache = pkgs.writeShellScriptBin "upcache" ''
|
|
|
|
## refs:
|
|
|
|
## https://fzakaria.com/2020/08/11/caching-your-nix-shell.html
|
|
|
|
## https://nixos.wiki/wiki/Caching_nix_shell_build_inputs
|
|
|
|
nix-store --query --references $(nix-instantiate shell.nix) | \
|
|
|
|
xargs nix-store --realise | \
|
|
|
|
xargs nix-store --query --requisites | \
|
|
|
|
cachix push go-xkcdreader
|
|
|
|
'';
|
2022-05-21 22:05:36 +02:00
|
|
|
add-license = pkgs.writeShellScriptBin "add-license" ''
|
|
|
|
go run github.com/google/addlicense@v1.0.0 -v \
|
|
|
|
-c "wanderer <a_mirre at utb dot cz>" \
|
|
|
|
-l "GPL-3.0-or-later" -s .
|
|
|
|
'';
|
2022-04-27 02:56:01 +02:00
|
|
|
in
|
2022-05-03 20:22:43 +02:00
|
|
|
{
|
|
|
|
default = with pkgs; mkShell
|
|
|
|
{
|
|
|
|
name = "go-xkcdreader-" + version;
|
|
|
|
|
|
|
|
GOFLAGS = "-buildmode=pie -trimpath -mod=readonly -modcacherw";
|
2022-05-12 15:54:16 +02:00
|
|
|
GOLDFLAGS = "-s -w -X cmd.version=${version}";
|
2022-05-03 20:22:43 +02:00
|
|
|
CGO_CFLAGS = "-g2 -Og -mtune=generic";
|
|
|
|
CGO_LDFLAGS = "-Wl,-O1,-sort-common,-as-needed,-z,relro,-z,now,-flto -pthread";
|
|
|
|
|
|
|
|
shellHook = ''
|
|
|
|
echo " -- in go-xkcdreader shell..."
|
|
|
|
'';
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
|
|
|
## uncomment the line below if using an Intel GPU when
|
|
|
|
## developing
|
|
|
|
# pkgs.nixgl.nixGLIntel
|
|
|
|
|
|
|
|
## this won't work without passing --impure, doesn't care what
|
|
|
|
## GPU vendor you use, it figures it out automatically
|
|
|
|
# pkgs.nixgl.auto.nixGLDefault # requires --impure
|
|
|
|
];
|
|
|
|
packages = [
|
2022-05-20 19:52:31 +02:00
|
|
|
## use patched Go, since it's supposed to be faster
|
|
|
|
goPkgs.go
|
|
|
|
## if you wish to use this, uncomment the related block in
|
|
|
|
## overlay.nix and the next line
|
|
|
|
# goPkgs.dominikh.go-tools
|
2022-05-29 21:19:40 +02:00
|
|
|
# goPkgs.patchelf-x86_64
|
|
|
|
# goPkgs.patchelf-aarch64
|
2022-05-20 19:52:31 +02:00
|
|
|
|
2022-05-20 22:16:11 +02:00
|
|
|
## ad-hoc cmds
|
|
|
|
gob
|
|
|
|
gota
|
2022-05-21 19:41:43 +02:00
|
|
|
upcache
|
2022-05-21 22:05:36 +02:00
|
|
|
add-license
|
2022-05-20 22:16:11 +02:00
|
|
|
|
2022-05-03 20:22:43 +02:00
|
|
|
gopls
|
|
|
|
gofumpt
|
|
|
|
go-tools
|
|
|
|
golangci-lint
|
|
|
|
nixpkgs-fmt
|
|
|
|
] ++ (if stdenv.isLinux then [
|
|
|
|
|
|
|
|
pkgconfig
|
|
|
|
|
|
|
|
# fyne deps
|
|
|
|
libglvnd # instead of libGL
|
|
|
|
wayland
|
|
|
|
libxkbcommon
|
|
|
|
xorg.libX11
|
|
|
|
xorg.libXcursor
|
|
|
|
xorg.libXfixes
|
|
|
|
xorg.libXrandr
|
|
|
|
xorg.libXrender
|
|
|
|
xorg.xrandr
|
|
|
|
xorg.libXinerama
|
|
|
|
xorg.xinput
|
|
|
|
xorg.libXi
|
|
|
|
xorg.libXxf86vm
|
2022-05-07 00:31:44 +02:00
|
|
|
xorg.xorgserver
|
2022-05-03 20:22:43 +02:00
|
|
|
|
|
|
|
] else [ ]);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
2022-03-12 10:29:25 +01:00
|
|
|
};
|
|
|
|
}
|