Skip to content

Commit e291af9

Browse files
committed
add flake (output package and nixosModule)
1 parent 7b116a9 commit e291af9

File tree

3 files changed

+161
-0
lines changed

3 files changed

+161
-0
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,37 @@ Download the appropriate binary for your system from the [latest release](https:
7474
7575
Make the binary executable (for Linux/macOS) with `chmod +x local-content-share-*` and then run the binary with `./local-content-share-*`. The application will be available at `http://localhost:8080`.
7676

77+
### Using Nix flakes
78+
79+
#### Run without installing
80+
```sh
81+
nix run nixpkgs#local-content-share
82+
```
83+
84+
#### Install
85+
```sh
86+
nix profile install nixpkgs#local-content-share
87+
```
88+
89+
### Using the NixOS Module
90+
91+
There is a Nixos module for the app, you need to be on the unstable branch.
92+
93+
```nix
94+
services.local-content-share.enable = true;
95+
```
96+
97+
The NixOS module provides the following options:
98+
99+
| Option | Default | Description |
100+
| --- | --- | --- |
101+
| `enable` | false | Whether the service should be enabled or not |
102+
| `port` | 8080 | The port that local-content-share will be available at |
103+
| `listenAddress` | empty string | Which address to listen on, all if not set |
104+
| `openFirewall` | false | Whether to open the specified port in the firewall |
105+
| `package` | nixpkgs's | The package used by nixos for the service |
106+
107+
77108
### Local development
78109

79110
With `Go 1.23+` installed, run the following to download the binary to your GOBIN:

flake.lock

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
{
2+
description = "Share file/text in your local network";
3+
4+
inputs = {
5+
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
6+
};
7+
8+
outputs = {
9+
self,
10+
nixpkgs,
11+
...
12+
}: let
13+
systems = [
14+
"x86_64-linux"
15+
"aarch64-linux"
16+
"x86_64-darwin"
17+
"aarch64-darwin"
18+
];
19+
forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f system);
20+
in {
21+
packages = forAllSystems (
22+
system: let
23+
pkgs = import nixpkgs {inherit system;};
24+
in {
25+
local-content-share = pkgs.buildGoModule {
26+
pname = "local-content-share";
27+
version = ""; # nix needs version to be set, though setting it to the right one would mean it needs to be updated at each release
28+
src = ./.;
29+
vendorHash = null;
30+
31+
meta = {
32+
mainProgram = "local-content-share";
33+
description = "Self-hosted app for storing/sharing text/files in your local network with no setup on client devices";
34+
homepage = "https://github.com/Tanq16/local-content-share";
35+
};
36+
};
37+
default = self.packages.${system}.local-content-share;
38+
}
39+
);
40+
41+
nixosModules.local-content-share = {
42+
pkgs,
43+
lib,
44+
config,
45+
...
46+
}: let
47+
cfg = config.services.local-content-share;
48+
in {
49+
options.services.local-content-share = {
50+
enable = lib.mkEnableOption "Local-Content-Share";
51+
52+
package = lib.mkPackageOption pkgs "local-content-share" {};
53+
54+
listenAddress = lib.mkOption {
55+
type = lib.types.str;
56+
default = "";
57+
example = "127.0.0.1";
58+
description = ''
59+
Address on which the service will be available.
60+
61+
The service will listen on all interfaces if set to an empty string.
62+
'';
63+
};
64+
65+
port = lib.mkOption {
66+
type = lib.types.port;
67+
default = 8080;
68+
description = "Port on which the service will be available";
69+
};
70+
71+
openFirewall = lib.mkOption {
72+
type = lib.types.bool;
73+
default = false;
74+
description = "Whether to automatically open the specified port in the firewall";
75+
};
76+
};
77+
78+
config = lib.mkIf cfg.enable {
79+
systemd.services.local-content-share = {
80+
after = ["network.target"];
81+
wantedBy = ["multi-user.target"];
82+
83+
serviceConfig = {
84+
Type = "simple";
85+
DynamicUser = true;
86+
User = "local-content-share";
87+
StateDirectory = "local-content-share";
88+
StateDirectoryMode = "0700";
89+
WorkingDirectory = "/var/lib/local-content-share";
90+
ExecStart = "${lib.getExe' cfg.package "local-content-share"} -listen=${cfg.listenAddress}:${toString cfg.port}";
91+
Restart = "on-failure";
92+
};
93+
};
94+
95+
networking.firewall = lib.mkIf cfg.openFirewall {
96+
allowedTCPPorts = [cfg.port];
97+
};
98+
};
99+
};
100+
101+
nixosModules.default = self.nixosModules.local-content-share;
102+
};
103+
}

0 commit comments

Comments
 (0)