From 6efcf92100cd4dc1af72efc0b284c15609277b30 Mon Sep 17 00:00:00 2001 From: Mans Ziesel Date: Tue, 23 Jan 2024 20:13:51 +0100 Subject: [PATCH] first commit --- .gitignore | 3 ++ Makefile | 3 ++ cmd/server/main.go | 8 +++++ default.nix | 22 ++++++++++++ flake.lock | 85 ++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 48 ++++++++++++++++++++++++++ go.mod | 3 ++ gomod2nix.toml | 3 ++ schema/schema.go | 37 ++++++++++++++++++++ shell.nix | 24 +++++++++++++ 10 files changed, 236 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 cmd/server/main.go create mode 100644 default.nix create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 go.mod create mode 100644 gomod2nix.toml create mode 100644 schema/schema.go create mode 100644 shell.nix diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..66d4174 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/mzsite +/result +node_modules diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..80bb517 --- /dev/null +++ b/Makefile @@ -0,0 +1,3 @@ +proccess-css: + npx tailwindcss -i ./embedded/static/css/input.css -o ./embedded/static/css/style.css --watch + diff --git a/cmd/server/main.go b/cmd/server/main.go new file mode 100644 index 0000000..c76edc7 --- /dev/null +++ b/cmd/server/main.go @@ -0,0 +1,8 @@ +package main + +import "fmt" + +func main() { + fmt.Println("Hello, World!") + fmt.Println("Hello, World!") +} diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..50a23ee --- /dev/null +++ b/default.nix @@ -0,0 +1,22 @@ +{ pkgs ? ( + let + inherit (builtins) fetchTree fromJSON readFile; + inherit ((fromJSON (readFile ./flake.lock)).nodes) nixpkgs gomod2nix; + in + import (fetchTree nixpkgs.locked) { + overlays = [ + (import "${fetchTree gomod2nix.locked}/overlay.nix") + ]; + } + ) +, buildGoApplication ? pkgs.buildGoApplication +}: + +buildGoApplication { + pname = "server"; + version = "0.1"; + pwd = ./.; + src = ./.; + modules = ./gomod2nix.toml; + subPackages = [ "cmd/server" ]; +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..4f1a905 --- /dev/null +++ b/flake.lock @@ -0,0 +1,85 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gomod2nix": { + "inputs": { + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1705314449, + "narHash": "sha256-yfQQ67dLejP0FLK76LKHbkzcQqNIrux6MFe32MMFGNQ=", + "owner": "nix-community", + "repo": "gomod2nix", + "rev": "30e3c3a9ec4ac8453282ca7f67fca9e1da12c3e6", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "gomod2nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1705856552, + "narHash": "sha256-JXfnuEf5Yd6bhMs/uvM67/joxYKoysyE3M2k6T3eWbg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "612f97239e2cc474c13c9dafa0df378058c5ad8d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "gomod2nix": "gomod2nix", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..8504ece --- /dev/null +++ b/flake.nix @@ -0,0 +1,48 @@ +{ + description = "A basic gomod2nix flake"; + + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + inputs.flake-utils.url = "github:numtide/flake-utils"; + inputs.gomod2nix.url = "github:nix-community/gomod2nix"; + inputs.gomod2nix.inputs.nixpkgs.follows = "nixpkgs"; + inputs.gomod2nix.inputs.flake-utils.follows = "flake-utils"; + + outputs = { self, nixpkgs, flake-utils, gomod2nix }: + (flake-utils.lib.eachDefaultSystem + (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + + # The current default sdk for macOS fails to compile go projects, so we use a newer one for now. + # This has no effect on other platforms. + callPackage = pkgs.darwin.apple_sdk_11_0.callPackage or pkgs.callPackage; + in + { + packages.default = callPackage ./. { + inherit (gomod2nix.legacyPackages.${system}) buildGoApplication; + }; + packages.docker = let + bin = self.packages.${system}.default; + in pkgs.dockerTools.buildImage { + name = "git.mzsl.nl/mans/goshare"; + tag = "latest"; + fromImageName = "alpine"; + + created = "now"; + + # contents = [ bin ]; + + copyToRoot = pkgs.buildEnv { + name = "image-root"; + paths = [ bin ]; + pathsToLink = [ "/bin" ]; + }; + + config.Cmd = [ "/bin/server" ]; + }; + devShells.default = callPackage ./shell.nix { + inherit (gomod2nix.legacyPackages.${system}) mkGoEnv gomod2nix; + }; + }) + ); +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..0be975e --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.mzsl.nl/mans/goshare + +go 1.21 diff --git a/gomod2nix.toml b/gomod2nix.toml new file mode 100644 index 0000000..43cd4cf --- /dev/null +++ b/gomod2nix.toml @@ -0,0 +1,3 @@ +schema = 3 + +[mod] diff --git a/schema/schema.go b/schema/schema.go new file mode 100644 index 0000000..18ce4cf --- /dev/null +++ b/schema/schema.go @@ -0,0 +1,37 @@ +package schema + +import "time" + +type ShareType = int + +const ( + ShareDrop = iota + ShareSendSingle + ShareSendMultiple +) + +type MimeType = int + +const ( + MimeTypeText = iota +) + +type Share struct { + ShareId int + ShareType ShareType + CreatedAt time.Time + ValidUntil time.Time + PasswordHash string + ManagementToken string + Enabled bool +} + +type ShareFile struct { + ShareId int + Filename string + Mimetype MimeType + FileHash string + UploadedAt time.Time + Deleted bool + DownloadCount int +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..d4f21a8 --- /dev/null +++ b/shell.nix @@ -0,0 +1,24 @@ +{ pkgs ? ( + let + inherit (builtins) fetchTree fromJSON readFile; + inherit ((fromJSON (readFile ./flake.lock)).nodes) nixpkgs gomod2nix; + in + import (fetchTree nixpkgs.locked) { + overlays = [ + (import "${fetchTree gomod2nix.locked}/overlay.nix") + ]; + } + ) +, mkGoEnv ? pkgs.mkGoEnv +, gomod2nix ? pkgs.gomod2nix +}: + +let + goEnv = mkGoEnv { pwd = ./.; }; +in +pkgs.mkShell { + packages = [ + goEnv + gomod2nix + ]; +}