Skip to content
This repository was archived by the owner on May 21, 2025. It is now read-only.

Commit c112813

Browse files
committed
nix module
1 parent 65ff650 commit c112813

File tree

5 files changed

+105
-26
lines changed

5 files changed

+105
-26
lines changed

flake.nix

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,21 @@
1010
inputs.flakelight.follows = "flakelight";
1111
};
1212
};
13-
outputs = { mill-scale, ... }: mill-scale ./. { };
13+
outputs = {mill-scale, ...}:
14+
mill-scale ./. {
15+
nixosModules = {outputs, ...}: {
16+
default = {
17+
pkgs,
18+
config,
19+
lib,
20+
...
21+
}: {
22+
imports = [./nix/module.nix];
23+
config = lib.mkIf config.services.demostf.sync.enable {
24+
nixpkgs.overlays = [outputs.overlays.default];
25+
services.demostf.sync.package = lib.mkDefault pkgs.demostf-sync;
26+
};
27+
};
28+
};
29+
};
1430
}

nix/docker.nix

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
{ dockerTools
2-
, demostf-sync
3-
,
1+
{
2+
dockerTools,
3+
demostf-sync,
44
}:
55
dockerTools.buildLayeredImage {
66
name = "demostf/sync";
@@ -11,9 +11,9 @@ dockerTools.buildLayeredImage {
1111
dockerTools.caCertificates
1212
];
1313
config = {
14-
Cmd = [ "sync" ];
14+
Cmd = ["sync"];
1515
ExposedPorts = {
16-
"80/tcp" = { };
16+
"80/tcp" = {};
1717
};
1818
};
1919
}

nix/module.nix

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
lib,
3+
config,
4+
...
5+
}: let
6+
cfg = config.services.demostf.sync;
7+
in {
8+
options = {
9+
services.demostf.sync = with lib; {
10+
enable = mkEnableOption "demostf sync";
11+
package = mkOption {
12+
type = types.package;
13+
defaultText = literalExpression "pkgs.demostf-sync";
14+
description = "package to use";
15+
};
16+
socket = mkOption {
17+
type = types.str;
18+
default = "/var/run/demostf-sync/sync.socket";
19+
};
20+
};
21+
};
22+
23+
config = lib.mkIf cfg.enable {
24+
systemd.services.demostf-sync = {
25+
wantedBy = ["multi-user.target"];
26+
environment = {
27+
SOCKET = cfg.socket;
28+
};
29+
30+
serviceConfig = {
31+
DynamicUser = true;
32+
ExecStart = "${cfg.package}/bin/sync";
33+
Restart = "on-failure";
34+
35+
PrivateTmp = true;
36+
PrivateUsers = true;
37+
ProtectSystem = "strict";
38+
ProtectHome = true;
39+
NoNewPrivileges = true;
40+
PrivateDevices = true;
41+
ProtectClock = true;
42+
CapabilityBoundingSet = true;
43+
ProtectKernelLogs = true;
44+
ProtectControlGroups = true;
45+
SystemCallArchitectures = "native";
46+
ProtectKernelModules = true;
47+
RestrictNamespaces = true;
48+
MemoryDenyWriteExecute = true;
49+
ProtectHostname = true;
50+
LockPersonality = true;
51+
ProtectKernelTunables = true;
52+
DevicePolicy = "closed";
53+
RestrictAddressFamilies = ["AF_UNIX"];
54+
RestrictRealtime = true;
55+
ProcSubset = "pid";
56+
ProtectProc = "invisible";
57+
SystemCallFilter = ["@system-service" "~@resources" "~@privileged"];
58+
UMask = "0007";
59+
IPAddressDeny = "any";
60+
RuntimeDirectory = "demostf-sync";
61+
};
62+
};
63+
};
64+
}

nix/overlay.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
prev: final: {
2-
demostf-sync = final.callPackage ./package.nix { };
3-
demostf-sync-docker = final.callPackage ./docker.nix { };
2+
demostf-sync = final.callPackage ./package.nix {};
3+
demostf-sync-docker = final.callPackage ./docker.nix {};
44
}

nix/package.nix

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1-
{ stdenv
2-
, rustPlatform
3-
, lib
4-
, pkg-config
5-
, openssl
6-
,
7-
}:
8-
let
1+
{
2+
stdenv,
3+
rustPlatform,
4+
lib,
5+
pkg-config,
6+
openssl,
7+
}: let
98
inherit (lib.sources) sourceByRegex;
109
inherit (builtins) fromTOML readFile;
11-
src = sourceByRegex ../. [ "Cargo.*" "(src)(/.*)?" ];
10+
src = sourceByRegex ../. ["Cargo.*" "(src)(/.*)?"];
1211
version = (fromTOML (readFile ../Cargo.toml)).package.version;
1312
in
14-
rustPlatform.buildRustPackage rec {
15-
pname = "demostf-sync";
13+
rustPlatform.buildRustPackage rec {
14+
pname = "demostf-sync";
1615

17-
inherit src version;
16+
inherit src version;
1817

19-
buildInputs = [ openssl ];
18+
buildInputs = [openssl];
2019

21-
nativeBuildInputs = [ pkg-config ];
20+
nativeBuildInputs = [pkg-config];
2221

23-
cargoLock = {
24-
lockFile = ../Cargo.lock;
25-
};
26-
}
22+
cargoLock = {
23+
lockFile = ../Cargo.lock;
24+
};
25+
}

0 commit comments

Comments
 (0)