Skip to content

Commit 09f745d

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

File tree

3 files changed

+184
-0
lines changed

3 files changed

+184
-0
lines changed

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,61 @@ 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+
78+
### Using Nix flakes
79+
80+
#### Run without installing
81+
```sh
82+
nix run nixpkgs#local-content-share
83+
```
84+
85+
#### Install
86+
```sh
87+
nix profile install nixpkgs#local-content-share
88+
```
89+
90+
### Using the NixOS Module
91+
92+
> [!NOTE]
93+
> The NixOS module has not yet been [merged](https://github.com/NixOS/nixpkgs/pull/426887) in nixpkgs. Until then, you'll need to add the flake to your inputs as shown above.
94+
95+
Add the flake to your inputs:
96+
```nix
97+
# flake.nix
98+
{
99+
inputs = {
100+
local-content-share = {
101+
url = "github:Tanq16/local-content-share";
102+
inputs.nixpkgs.follows = "nixpkgs";
103+
};
104+
};
105+
}
106+
```
107+
108+
Enable the service:
109+
```nix
110+
# configuration.nix
111+
{ inputs, ... }:
112+
{
113+
imports = [
114+
inputs.local-content-share.nixosModules.local-content-share
115+
];
116+
117+
services.local-content-share.enable = true;
118+
}
119+
```
120+
121+
The NixOS module provides the following options:
122+
123+
| Option | Default | Description |
124+
| --- | --- | --- |
125+
| `enable` | false | Whether the service should be enabled or not |
126+
| `port` | 8080 | The port that local-content-share will be available at |
127+
| `openFirewall` | false | Whether nixos should open the port in the firewall |
128+
| `package` | this flake's package | The package used by nixos for the service |
129+
130+
131+
77132
### Local development
78133

79134
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: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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+
{
10+
self,
11+
nixpkgs,
12+
...
13+
}:
14+
let
15+
systems = [
16+
"x86_64-linux"
17+
"aarch64-linux"
18+
"x86_64-darwin"
19+
"aarch64-darwin"
20+
];
21+
forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f system);
22+
in
23+
{
24+
packages = forAllSystems (
25+
system:
26+
let
27+
pkgs = import nixpkgs { inherit system; };
28+
in
29+
{
30+
local-content-share = pkgs.buildGoModule {
31+
pname = "local-content-share";
32+
version = ""; # nix needs version to be set, though setting it to the right one would mean it needs to be updated at each release
33+
src = ./.;
34+
vendorHash = null;
35+
36+
meta = {
37+
mainProgram = "local-content-share";
38+
description = "Self-hosted app for storing/sharing text/files in your local network with no setup on client devices";
39+
homepage = "https://github.com/Tanq16/local-content-share";
40+
};
41+
};
42+
default = self.packages.${system}.local-content-share;
43+
}
44+
);
45+
46+
nixosModules.local-content-share =
47+
{
48+
pkgs,
49+
lib,
50+
config,
51+
...
52+
}:
53+
let
54+
cfg = config.services.local-content-share;
55+
in
56+
{
57+
options.services.local-content-share = {
58+
enable = lib.mkEnableOption "Local-Content-Share";
59+
60+
package = lib.mkOption {
61+
type = lib.types.package;
62+
default = self.packages.${pkgs.system}.local-content-share;
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 = "Open chosen port";
75+
};
76+
};
77+
78+
config = lib.mkIf cfg.enable {
79+
systemd.services.local-content-share = {
80+
description = "Local-Content-Share";
81+
after = [ "network.target" ];
82+
wantedBy = [ "multi-user.target" ];
83+
84+
serviceConfig = {
85+
Type = "simple";
86+
DynamicUser = true;
87+
StateDirectory = "local-content-share";
88+
WorkingDirectory = "/var/lib/local-content-share";
89+
ExecStart = "${lib.getExe' cfg.package "local-content-share"} -listen=:${toString cfg.port}";
90+
Restart = "on-failure";
91+
};
92+
};
93+
94+
networking.firewall = lib.mkIf cfg.openFirewall {
95+
allowedTCPPorts = [ cfg.port ];
96+
};
97+
};
98+
};
99+
100+
nixosModules.default = self.nixosModules.local-content-share;
101+
};
102+
}

0 commit comments

Comments
 (0)