initial commit

This commit is contained in:
leo 2023-05-14 16:47:01 +02:00
commit 14ec6c27b7
Signed by: wanderer
SSH Key Fingerprint: SHA256:Dp8+iwKHSlrMEHzE3bJnPng70I7LEsa3IJXRH/U+idQ
13 changed files with 476 additions and 0 deletions

22
.editorconfig Normal file

@ -0,0 +1,22 @@
root = true
[*]
charset = utf-8
end_of_line = lf
# go files (excluding templates)
[*.{go,mod,sum}]
indent_style = tab
indent_size = 4
tab_width = 4
[*.nix]
indent_style = space
indent_size = 2
[*.md]
trim_trailing_whitespace = false
[*.{yaml,yml}]
indent_style = space
indent_size = 2

7
.envrc Normal file

@ -0,0 +1,7 @@
use flake
# ref: https://github.com/direnv/direnv/wiki/Vim
# comment out if not planning to use this
#add_extra_vimrc
# vim: ff=unix ft=sh

2
.gitattributes vendored Normal file

@ -0,0 +1,2 @@
*.md diff=markdown
*.go diff=golang

8
.gitignore vendored Normal file

@ -0,0 +1,8 @@
.direnv
# binaries/symlinks to binaries
result
result-*
# coverage or other binary files
*.out

103
.golangci.yml Normal file

@ -0,0 +1,103 @@
# Copyright 2023 wanderer <a_mirre at utb dot cz>
# SPDX-License-Identifier: GPL-3.0-or-later
---
run:
go: 1.20.3
tests: true
issues:
max-issues-per-linter: 0
max-same-issues: 0
linters:
enable:
- bidichk
# - dupl
# The linter 'deadcode' is deprecated (since v1.49.0) due to: The owner
# seems to have abandoned the linter. Replaced by unused.
# - deadcode
- decorder
- dogsled
- exportloopref
- forbidigo
- gas
- gocognit
- goconst
- gocritic
- godot
- govet
- gofmt
- gofumpt
- goimports
- goprintffuncname
- gosec
- ineffassign
# The linter 'ifshort' is deprecated (since v1.48.0) due to: The repository
# of the linter has been deprecated by the owner.
# - ifshort
- misspell
# - prealloc
- revive
- tparallel
- unconvert
- unparam
- unused
# The linter 'varcheck' is deprecated (since v1.49.0) due to: The owner
# seems to have abandoned the linter. Replaced by unused.
# - varcheck
- wastedassign
- whitespace
- wsl
linter-settings:
dupl:
threshold: 100
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- ifElseChain
- octalLiteral
- whyNoLint
- wrapperFunc
gocyclo:
min-complexity: 15
gofumpt:
extra-rules: true
lang-version: "1.18"
govet:
check-shadowing: true
revive:
severity: warning
confidence: 0.8
errorCode: 1
warningCode: 1
rules:
- name: blank-imports
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: error-return
- name: error-strings
- name: error-naming
- name: exported
- name: if-return
- name: increment-decrement
- name: var-naming
- name: var-declaration
- name: package-comments
- name: range
- name: receiver-naming
- name: time-naming
- name: unexported-return
- name: indent-error-flow
- name: errorf
- name: duplicated-imports
- name: modifies-value-receiver
...

56
.pre-commit-config.yaml Normal file

@ -0,0 +1,56 @@
---
fail_fast: false
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-merge-conflict
- repo: meta
hooks:
- id: check-hooks-apply
- repo: local
hooks:
- id: pre-commit-validate-config
name: pre-commit validate config
entry: pre-commit validate-config
pass_filenames: false
files: '^.pre-commit-config.yaml$'
language: system
- repo: https://github.com/TekWizely/pre-commit-golang
rev: v1.0.0-rc.1
hooks:
- id: go-mod-tidy
- id: go-test-mod
- id: golangci-lint-mod
- id: go-build-mod
- repo: local
hooks:
- id: statix
name: statix
entry: statix check .
always_run: false
pass_filenames: false
files: '\.*.nix$'
language: system
- id: nix-fmt
name: nix fmt
entry: nix fmt -- --check .
always_run: false
pass_filenames: false
files: '\.*.nix$'
language: system
- id: flake-check
name: nix flake check
entry: nix flake check --keep-going
always_run: false
pass_filenames: false
files: "flake.(nix|lock)$"
language: system
- id: nix-build-go-proj
name: nix build go proj
entry: nix build .#proj
pass_filenames: false
# trigger this hook on changes to any of nix (also flake.lock) files
# and go's mod or sum files
files: '\.*.(nix|lock|mod|sum)$'
language: system

3
README.md Normal file

@ -0,0 +1,3 @@
# [ak0da](https://git.dotya.ml/wanderer/ak0da)
this repo contains code of compulsory tasks for `AK0DA` course.

16
default.nix Normal file

@ -0,0 +1,16 @@
(
import
(
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
)
{
src = ./.;
}
)
.defaultNix

60
flake.lock Normal file

@ -0,0 +1,60 @@
{
"nodes": {
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1673956053,
"narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"nix-filter": {
"locked": {
"lastModified": 1681154353,
"narHash": "sha256-MCJ5FHOlbfQRFwN0brqPbCunLEVw05D/3sRVoNVt2tI=",
"owner": "numtide",
"repo": "nix-filter",
"rev": "f529f42792ade8e32c4be274af6b6d60857fbee7",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "nix-filter",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1683968890,
"narHash": "sha256-FuNtjMvT07cJydY5NRyRhIni/dEwkSkijmFEdsmqdkA=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "ea11a3977f4cba013d8680667616be827c967ac0",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-compat": "flake-compat",
"nix-filter": "nix-filter",
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

176
flake.nix Normal file

@ -0,0 +1,176 @@
{
description = "Data Analysis";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
nix-filter = {
url = "github:numtide/nix-filter";
};
};
outputs = {
self,
nixpkgs,
nix-filter,
...
}: let
projname = "ak0da";
# 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";
supportedSystems = ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
pkgs = forAllSystems (system: nixpkgs.legacyPackages.${system});
# Nixpkgs instantiated for supported system types.
nixpkgsFor = forAllSystems (system:
import nixpkgs {
inherit system;
overlays = [
# no overlay imports atm
# (import ./overlay.nix)
];
});
in {
formatter = forAllSystems (
system:
nixpkgsFor.${system}.alejandra
);
packages = forAllSystems (system: let
baseurl = "https://git.dotya.ml/wanderer/ak0da/";
pkgs = nixpkgsFor.${system};
inherit (pkgs) lib overlays;
in rec {
proj = with pkgs;
buildGo120Module rec {
pname = "proj";
buildInputs = [
go_1_20
];
nativeBuildInputs = [pkgconfig];
overrideModAttrs = _: {
# GOPROXY = "direct";
GOFLAGS = "-buildmode=pie -trimpath -mod=readonly -modcacherw";
};
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"
];
# dont't forget to update vendorSha256 whenever go.mod or go.sum change
vendorSha256 = null;
# In 'nix develop', we don't need a copy of the source tree
# in the Nix store.
src = nix-filter.lib.filter {
# when in doubt, check out
# https://github.com/numtide/nix-filter#design-notes
# tl;dr: it'd be best to include folders, however there are
# currently issues with that approach.
root = lib.cleanSource ./.;
exclude = [
./flake.nix
./flake.lock
./default.nix
./shell.nix
./overlay.nix
./README.md
./.envrc
./.gitattributes
./.gitignore
./.golangci.yml
./.editorconfig
./.pre-commit-config.yaml
# program output
./out
./res
# nix result symlink
./result
# the entire .git folder
./.git
];
};
meta = {
description = "implementation of the compulsory task for ak0da";
homepage = baseurl;
license = lib.licenses.gpl3;
maintainers = ["wanderer"];
platforms = lib.platforms.linux ++ lib.platforms.darwin;
};
};
default = proj;
});
apps = forAllSystems (system: rec {
proj = {
type = "app";
program = "${self.packages.${system}.${projname}}/bin/proj";
};
default = proj;
});
devShells = forAllSystems (system: let
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}
nix build --json \
| jq -r '.[].outputs | to_entries[].value' \
| cachix push ${projname}
'';
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 = pkgs.${system}.mkShellNoCC {
name = "${projname}-" + version;
GOFLAGS = "-buildmode=pie -trimpath -mod=readonly -modcacherw";
GOLDFLAGS = "-s -w";
CGO_CFLAGS = "-g0 -Ofast -mtune=native -flto";
CGO_LDFLAGS = "-Wl,-O1,-sort-common,-as-needed,-z,relro,-z,now,-flto -pthread";
shellHook = ''
echo " -- in ${projname} dev shell..."
'';
packages = with pkgs.${system}; [
pre-commit
statix
# deps
go_1_20
go-tools
gofumpt
];
};
});
};
}

3
go.mod Normal file

@ -0,0 +1,3 @@
module git.dotya.ml/wanderer/ak0da
go 1.20

4
main.go Normal file

@ -0,0 +1,4 @@
package main
func main() {
}

16
shell.nix Normal file

@ -0,0 +1,16 @@
(
import
(
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
)
{
src = ./.;
}
)
.shellNix