2022-06-14 16:46:11 +02:00
|
|
|
{
|
|
|
|
description = "mathematical informatics course semestral project solving a few mathematical optimisation tasks using well-known algorithms";
|
|
|
|
|
|
|
|
inputs = {
|
|
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
|
|
|
flake-compat = {
|
|
|
|
url = "github:edolstra/flake-compat";
|
|
|
|
flake = false;
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
|
|
|
nix-filter = {
|
|
|
|
url = "github:numtide/nix-filter";
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
outputs = {
|
|
|
|
self,
|
|
|
|
nixpkgs,
|
|
|
|
nix-filter,
|
|
|
|
...
|
|
|
|
}: let
|
|
|
|
projname = "math-optim";
|
|
|
|
|
|
|
|
# to work with older version of flakes
|
|
|
|
lastModifiedDate =
|
|
|
|
self.lastModifiedDate or self.lastModified or "19700101";
|
|
|
|
|
|
|
|
# Generate a user-friendly version number.
|
|
|
|
version = "v0.0.0";
|
|
|
|
|
|
|
|
# System types to support.
|
2022-06-20 15:58:44 +02:00
|
|
|
supportedSystems = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"];
|
2022-06-14 16:46:11 +02: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.
|
|
|
|
nixpkgsFor = forAllSystems (system:
|
|
|
|
import nixpkgs {
|
|
|
|
inherit system;
|
|
|
|
overlays = [
|
|
|
|
# no overlay imports atm
|
|
|
|
(import ./overlay.nix)
|
|
|
|
];
|
|
|
|
});
|
|
|
|
in rec {
|
|
|
|
formatter = forAllSystems (
|
|
|
|
system:
|
|
|
|
nixpkgsFor.${system}.alejandra
|
|
|
|
);
|
|
|
|
|
|
|
|
packages = forAllSystems (system: let
|
|
|
|
pkgs = nixpkgsFor.${system};
|
|
|
|
inherit (pkgs) lib overlays; # -> lib = pkgs.lib;overlays = pkgs.overlays;
|
|
|
|
in rec {
|
|
|
|
math-optim = with pkgs;
|
|
|
|
buildGoModule rec {
|
|
|
|
pname = "${projname}";
|
|
|
|
buildInputs = [
|
|
|
|
go
|
|
|
|
];
|
|
|
|
nativeBuildInputs = [pkgconfig];
|
|
|
|
|
|
|
|
overrideModAttrs = _: {
|
2022-06-25 00:28:34 +02:00
|
|
|
# GOPROXY = "direct";
|
2022-08-12 21:45:26 +02:00
|
|
|
GOFLAGS = "-buildmode=pie -trimpath -mod=readonly -modcacherw";
|
2022-06-14 16:46:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
inherit version;
|
|
|
|
doCheck = false;
|
|
|
|
# use go.mod for managing go deps, instead of vendor-only dir
|
|
|
|
proxyVendor = true;
|
|
|
|
tags = []; # go "-tags" to build with
|
|
|
|
ldflags = [
|
|
|
|
"-s"
|
|
|
|
"-w"
|
|
|
|
"-X main.version=${version}"
|
|
|
|
];
|
|
|
|
|
|
|
|
modSha256 = lib.fakeSha256;
|
|
|
|
# dont't forget to update vendorSha256 whenever go.mod or go.sum change
|
2022-06-20 03:32:48 +02:00
|
|
|
vendorSha256 = "sha256-JNvU72sb0m5bvKz/D6VAGsQiPh2lKt7N2DuhaOp6XA4=";
|
2022-06-14 16:46:11 +02:00
|
|
|
|
|
|
|
# In 'nix develop', we don't need a copy of the source tree
|
|
|
|
# in the Nix store.
|
|
|
|
src = nix-filter.lib.filter {
|
|
|
|
root = lib.cleanSource ./.;
|
|
|
|
exclude = [
|
|
|
|
./flake.nix
|
|
|
|
./flake.lock
|
|
|
|
./default.nix
|
|
|
|
./shell.nix
|
2022-08-12 20:48:02 +02:00
|
|
|
|
|
|
|
./.envrc
|
|
|
|
./.drone.star
|
|
|
|
./.gitattributes
|
|
|
|
./.gitignore
|
|
|
|
./.golangci.yml
|
|
|
|
./.editorconfig
|
|
|
|
./.pre-commit-config.yaml
|
|
|
|
|
|
|
|
./.badges
|
2022-06-14 16:46:11 +02:00
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
meta = {
|
|
|
|
description = "mathematical informatics course semestral project solving a few mathematical optimisation tasks using well-known algorithms";
|
|
|
|
homepage = "https://git.dotya.ml/wanderer/math-optim";
|
|
|
|
license = lib.licenses.gpl3;
|
|
|
|
maintainers = ["wanderer"];
|
|
|
|
platforms = lib.platforms.linux ++ lib.platforms.darwin;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
default = math-optim;
|
|
|
|
});
|
|
|
|
|
|
|
|
apps = forAllSystems (system: rec {
|
|
|
|
math-optim = {
|
|
|
|
type = "app";
|
|
|
|
program = "${self.packages.${system}.${projname}}/bin/${projname}";
|
|
|
|
};
|
|
|
|
default = math-optim;
|
|
|
|
});
|
|
|
|
|
|
|
|
devShells = forAllSystems (
|
|
|
|
system: let
|
|
|
|
pkgs = import nixpkgs {
|
|
|
|
inherit system;
|
|
|
|
overlays = [
|
|
|
|
(import ./overlay.nix)
|
|
|
|
];
|
|
|
|
};
|
|
|
|
goPkgs = import nixpkgs {
|
|
|
|
useFetched = true;
|
|
|
|
inherit system;
|
|
|
|
overlays =
|
|
|
|
self.overlays
|
|
|
|
or []
|
|
|
|
++ [
|
|
|
|
(import ./overlay.nix)
|
|
|
|
];
|
|
|
|
};
|
|
|
|
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-06-20 17:34:48 +02:00
|
|
|
gogen = pkgs.writeShellScriptBin "gogen" ''
|
|
|
|
cd $(git rev-parse --show-toplevel)
|
|
|
|
go generate -v ./report
|
|
|
|
'';
|
2022-06-14 16:46:11 +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 ${projname}
|
2022-08-12 21:42:00 +02:00
|
|
|
nix build --json \
|
|
|
|
| jq -r '.[].outputs | to_entries[].value' \
|
|
|
|
| cachix push ${projname}
|
2022-06-14 16:46:11 +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 .
|
|
|
|
'';
|
|
|
|
in {
|
|
|
|
default = with pkgs;
|
|
|
|
mkShell
|
|
|
|
{
|
|
|
|
name = "${projname}-" + version;
|
|
|
|
|
|
|
|
GOFLAGS = "-buildmode=pie -trimpath -mod=readonly -modcacherw";
|
|
|
|
GOLDFLAGS = "-s -w -X main.version=${version}";
|
|
|
|
CGO_CFLAGS = "-g0 -mtune=native";
|
|
|
|
CGO_LDFLAGS = "-Wl,-O1,-sort-common,-as-needed,-z,relro,-z,now,-flto -pthread";
|
|
|
|
GOPROXY = "direct";
|
|
|
|
|
|
|
|
shellHook = ''
|
|
|
|
echo " -- in math-optim dev shell..."
|
|
|
|
'';
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
|
|
|
];
|
|
|
|
packages =
|
|
|
|
[
|
|
|
|
# use pathed go, as it's (supposed to be) faster with cgo,
|
|
|
|
# which will inevitably encountered anyway.
|
|
|
|
goPkgs.go
|
|
|
|
go-tools
|
|
|
|
gopls
|
|
|
|
gofumpt
|
|
|
|
statix
|
|
|
|
alejandra
|
|
|
|
|
|
|
|
## ad-hoc cmds
|
|
|
|
gob
|
|
|
|
gota
|
2022-06-20 17:34:48 +02:00
|
|
|
gogen
|
2022-06-14 16:46:11 +02:00
|
|
|
upcache
|
|
|
|
add-license
|
|
|
|
]
|
|
|
|
++ (
|
|
|
|
if stdenv.isLinux
|
|
|
|
then [
|
|
|
|
]
|
|
|
|
else []
|
|
|
|
);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
}
|