Compare commits

..

2 Commits

Author SHA1 Message Date
tux
adf7c84269 refactor(nix): migrate flake to flake-parts 2026-09-08 04:28:48 +05:30
tux
a86a290e88 chore(nix): update package reference 2026-09-08 03:51:15 +05:30
6 changed files with 110 additions and 63 deletions

57
flake.lock generated
View File

@@ -1,5 +1,23 @@
{ {
"nodes": { "nodes": {
"flake-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1788450739,
"narHash": "sha256-glZLQlzIn1fXH6PazR2iUmTo7kzzyYSshrWhLS9TqCU=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "31729ca8cbdb4fa927b34e5f4353e6a83f39e993",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1740547748, "lastModified": 1740547748,
@@ -16,9 +34,46 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs-lib": {
"locked": {
"lastModified": 1788057806,
"narHash": "sha256-DTQSMxzDWmT0zhguthvegnVkn7CFqGCv4IHCzk5ZUpM=",
"owner": "nix-community",
"repo": "nixpkgs.lib",
"rev": "596e2e3940e09b2abbeb03f75fa1828c57fcd72c",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixpkgs.lib",
"type": "github"
}
},
"root": { "root": {
"inputs": { "inputs": {
"nixpkgs": "nixpkgs" "flake-parts": "flake-parts",
"nixpkgs": "nixpkgs",
"treefmt-nix": "treefmt-nix"
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1786901030,
"narHash": "sha256-WSFCsDSE5ffgD2MqzkM2CYjeFiKhRF/dJUN8uedb6YE=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "27b3b12a8e6375f28ebe122f07d230ca5459bbfa",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
} }
} }
}, },

View File

@@ -1,33 +1,43 @@
{ {
description = "Simple tunneler in Go that exposes local ports to the internet"; description =
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; "Simple tunneler in Go that exposes local ports to the internet";
outputs = inputs = {
{ nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
self, flake-parts.url = "github:hercules-ci/flake-parts";
nixpkgs,
}:
let
systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
forAllSystems = treefmt-nix = {
function: nixpkgs.lib.genAttrs systems (system: function nixpkgs.legacyPackages.${system}); url = "github:numtide/treefmt-nix";
in inputs.nixpkgs.follows = "nixpkgs";
{
packages = forAllSystems (pkgs: rec {
default = trok;
trok = pkgs.callPackage ./package.nix { };
});
nixosModules.default = ./module.nix;
devShells = forAllSystems (pkgs: {
default = pkgs.callPackage ./shell.nix { };
});
}; };
};
outputs = inputs:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
imports = [ inputs.treefmt-nix.flakeModule ];
systems =
[ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
perSystem = { config, pkgs, ... }: {
treefmt = {
projectRootFile = "flake.nix";
programs = {
nixfmt.enable = true;
gofumpt.enable = true;
};
};
packages = rec {
default = tfolio;
tfolio = pkgs.callPackage ./nix/package.nix { };
};
devShells.default = pkgs.callPackage ./nix/shell.nix { };
};
flake.nixosModules.default = ./nix/module.nix;
};
} }

View File

@@ -1,11 +1,6 @@
{ { config, lib, pkgs, ... }:
config, with lib;
lib, let cfg = config.services.trok;
pkgs,
...
}:
with lib; let
cfg = config.services.trok;
in { in {
options.services.trok = { options.services.trok = {
enable = mkEnableOption "Enable trok"; enable = mkEnableOption "Enable trok";
@@ -38,19 +33,20 @@ in {
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [cfg.port]; networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.port ];
systemd.services = { systemd.services = {
trok = { trok = {
description = "trok server"; description = "trok server";
after = ["network.target"]; after = [ "network.target" ];
wantedBy = ["multi-user.target"]; wantedBy = [ "multi-user.target" ];
serviceConfig = { serviceConfig = {
Type = "simple"; Type = "simple";
User = "trok"; User = "trok";
Group = "trok"; Group = "trok";
ExecStart = "${getExe pkgs.trok} server -a ${cfg.host}:${toString cfg.port}"; ExecStart =
"${getExe pkgs.trok} server -a ${cfg.host}:${toString cfg.port}";
Restart = "always"; Restart = "always";
LockPersonality = true; LockPersonality = true;
@@ -73,7 +69,7 @@ in {
RestrictRealtime = true; RestrictRealtime = true;
RestrictSUIDSGID = true; RestrictSUIDSGID = true;
SystemCallArchitectures = "native"; SystemCallArchitectures = "native";
SystemCallFilter = ["@system-service"]; SystemCallFilter = [ "@system-service" ];
UMask = "0077"; UMask = "0077";
}; };
}; };
@@ -89,8 +85,6 @@ in {
}; };
}; };
users.groups = mkIf (cfg.group == "trok") { users.groups = mkIf (cfg.group == "trok") { ${cfg.group} = { }; };
${cfg.group} = {};
};
}; };
} }

View File

@@ -1,12 +1,9 @@
{ { lib, buildGoModule }:
lib,
buildGoModule,
}:
buildGoModule { buildGoModule {
pname = "trok"; pname = "trok";
version = "0.2.0"; version = "0.2.0";
src = ./.; src = ../.;
vendorHash = "sha256-KwcLxkW3pbzujjc6JOZRwATlAA/qndf4FWpkJANv2z8="; vendorHash = "sha256-KwcLxkW3pbzujjc6JOZRwATlAA/qndf4FWpkJANv2z8=";
meta = { meta = {

4
nix/shell.nix Normal file
View File

@@ -0,0 +1,4 @@
{ callPackage, go, }:
let mainPkg = callPackage ./package.nix { };
in mainPkg.overrideAttrs
(oa: { nativeBuildInputs = [ go ] ++ (oa.nativeBuildInputs or [ ]); })

View File

@@ -1,13 +0,0 @@
{
callPackage,
go,
}: let
mainPkg = callPackage ./default.nix {};
in
mainPkg.overrideAttrs (oa: {
nativeBuildInputs =
[
go
]
++ (oa.nativeBuildInputs or []);
})