It's now possible to build eko and eko-server with flake.nix

This commit is contained in:
2025-07-21 16:22:11 +03:00
parent 7d5ce5721b
commit 15cc391221
6 changed files with 167 additions and 26 deletions

1
VERSION Normal file
View File

@@ -0,0 +1 @@
v0.1.0

View File

@@ -17,13 +17,22 @@
package main
import (
"fmt"
"log"
"os"
"github.com/kyren223/eko/embeds"
"github.com/kyren223/eko/internal/client"
)
func main() {
if len(os.Args) > 1 && os.Args[1] == "-v" {
fmt.Println("version:", embeds.Version)
fmt.Println("commit:", embeds.Commit)
fmt.Println("build date:", embeds.BuildDate)
return
}
logFile, err := os.OpenFile("client.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0600)
if err != nil {
log.Fatalln(err)

View File

@@ -48,6 +48,13 @@ const (
var prod = true
func main() {
if len(os.Args) > 1 && os.Args[1] == "-v" {
fmt.Println("version:", embeds.Version)
fmt.Println("commit:", embeds.Commit)
fmt.Println("build date:", embeds.BuildDate)
return
}
prodFlag := flag.Bool("prod", true, "true for production mode, false for dev mode")
flag.Parse()
prod = *prodFlag

View File

@@ -21,6 +21,12 @@ import (
"sync/atomic"
)
var (
Version string = "unknown"
Commit string = "unknown"
BuildDate string = "unknown"
)
//go:embed server.crt
var ServerCertificate []byte

93
flake.lock generated Normal file
View File

@@ -0,0 +1,93 @@
{
"nodes": {
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1747046372,
"narHash": "sha256-CIVLLkVgvHYbgI2UpXvIIBJ12HWgX+fjA8Xf8PUmqCY=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "9100a0f413b0c601e0533d1d94ffd501ce2e7885",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nix-filter": {
"locked": {
"lastModified": 1731533336,
"narHash": "sha256-oRam5PS1vcrr5UPgALW0eo1m/5/pls27Z/pabHNy2Ms=",
"owner": "numtide",
"repo": "nix-filter",
"rev": "f7653272fd234696ae94229839a99b73c9ab7de0",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "nix-filter",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1753100475,
"narHash": "sha256-FF53JgK0MHjCkaac+GMnikfnK9dJkwHaqXfgKrtDkhs=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "bb65d58d5f5a779df1d018b0e3418969ba530628",
"type": "github"
},
"original": {
"owner": "nixos",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-compat": "flake-compat",
"flake-utils": "flake-utils",
"nix-filter": "nix-filter",
"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
}

View File

@@ -11,49 +11,68 @@
nix-filter.url = "github:numtide/nix-filter";
};
outputs = { self, ... }@inputs:
inputs.flake-utils.lib.eachDefaultSystem (system:
outputs =
{ self, ... }@inputs:
inputs.flake-utils.lib.eachDefaultSystem (
system:
let
overlays = [ ];
pkgs = import inputs.nixpkgs {
inherit system overlays;
};
lib = pkgs.lib;
version = (builtins.readFile ./VERSION); # TODO: have version?
version = (builtins.readFile ./VERSION);
buildDate = builtins.readFile (
pkgs.runCommand "build-date" { } ''
date -u +'%Y-%m-%d' > $out
''
);
commit = if (builtins.hasAttr "rev" self) then (builtins.substring 0 7 self.rev) else "unknown";
# vendorHash = pkgs.lib.fakeHash;
vendorHash = "sha256-2yCQ40T5N90lKpPOc+i6vz+1mI/p4Ey6PdRCJbGD+TE=";
src =
let
# Set this to `true` in order to show all of the source files
# that will be included in the module build.
debug-tracing = false;
source-files = inputs.nix-filter.lib.filter {
root = ./.;
};
in
(if (debug-tracing) then pkgs.lib.sources.trace source-files else source-files);
ldflags = [
"-X github.com/kyren223/eko/embeds.Version=${version}"
"-X github.com/kyren223/eko/embeds.Commit=${commit}"
"-X github.com/kyren223/eko/embeds.BuildDate=${buildDate}"
];
in
rec {
packages = rec {
eko = pkgs.buildGoModule {
pname = "eko";
version = version;
# vendorHash = pkgs.lib.fakeHash;
vendorHash = "sha256-t8Crwi8dPWOTiCbyCfgOCYJboC7pC1G/wyUsFfcVVkQ="; # TODO: change?
src =
let
# Set this to `true` in order to show all of the source files
# that will be included in the module build.
debug-tracing = false;
source-files = inputs.nix-filter.lib.filter {
root = ./.;
};
in
(
if (debug-tracing) then
pkgs.lib.sources.trace source-files
else
source-files
);
# Any extra packages required to build the binaries should go here.
vendorHash = vendorHash;
src = src;
buildInputs = [ ];
ldflags = [
"-X github.com/kyren223/eko/cmd/client/shared.Version=${version}" # TODO: change the version thing
"-X github.com/kyren223/eko/cmd/client/shared.Commit=${commit}" # TODO: change the commit thing
buildFlags = [
"-o"
"eko"
];
ldflags = ldflags;
modRoot = "./.";
subPackages = [ "cmd/client" ];
doCheck = false;
};
eko-server = pkgs.buildGoModule {
pname = "eko-server";
version = version;
vendorHash = vendorHash;
src = src;
buildInputs = [ ];
ldflags = ldflags;
modRoot = "./.";
subPackages = [ "cmd/server" ];
doCheck = false;
};
default = eko;
};
@@ -62,6 +81,11 @@
type = "app";
program = "${packages.eko}/bin/eko";
};
eko-server = {
type = "service";
program = "${packages.eko}/bin/eko-server";
# TODO: add systemd service
};
default = eko;
};
@@ -118,5 +142,6 @@
# hardeningDisable = [ "fortify" ];
# };
# };
});
}
);
}