git.iko.soy/typeable/nixpkgs
on master help sign in
services: Add Interplanetary File System service

Signed-off-by: Maximilian Güntner <code@klandest.in>

commit7fa157c5587d40ca757658e2c8017055c3c0419e authorMaximilian Güntner <code@klandest.in> dateSun 30 Oct 2016, 20:39 (10 years ago) parentdcb2179
3 files changed+114
nixos/modules/misc/ids.nix+2 nixos/modules/module-list.nix+1 nixos/modules/services/network-filesystems/ipfs.nix+111
nixos/modules/misc/ids.nix+2
@@ -278,6 +278,7 @@
278278 postgrey = 258;
279279 hound = 259;
280280 leaps = 260;
281+ ipfs = 261;
281282
282283 # When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399!
283284
@@ -526,6 +527,7 @@
526527 postgrey = 258;
527528 hound = 259;
528529 leaps = 260;
530+ ipfs = 261;
529531
530532 # When adding a gid, make sure it doesn't match an existing
531533 # uid. Users and groups with the same name should have equal
nixos/modules/module-list.nix+1
@@ -318,6 +318,7 @@
318318 ./services/monitoring/zabbix-server.nix
319319 ./services/network-filesystems/cachefilesd.nix
320320 ./services/network-filesystems/drbd.nix
321+ ./services/network-filesystems/ipfs.nix
321322 ./services/network-filesystems/netatalk.nix
322323 ./services/network-filesystems/nfsd.nix
323324 ./services/network-filesystems/openafs-client/default.nix
nixos/modules/services/network-filesystems/ipfs.nixnew file+111
@@ -0,0 +1,111 @@
1+{ config, lib, pkgs, ... }:
2+
3+with lib;
4+
5+let
6+ inherit (pkgs) ipfs;
7+
8+ cfg = config.services.ipfs;
9+
10+ ipfsFlags = ''${if cfg.autoMigrate then "--migrate" else ""} ${if cfg.enableGC then "--enable-gc" else ""} ${toString cfg.extraFlags}'';
11+
12+in
13+
14+{
15+
16+ ###### interface
17+
18+ options = {
19+
20+ services.ipfs = {
21+
22+ enable = mkEnableOption "Interplanetary File System";
23+
24+ user = mkOption {
25+ type = types.str;
26+ default = "ipfs";
27+ description = "User under which the IPFS daemon runs";
28+ };
29+
30+ group = mkOption {
31+ type = types.str;
32+ default = "ipfs";
33+ description = "Group under which the IPFS daemon runs";
34+ };
35+
36+ dataDir = mkOption {
37+ type = types.str;
38+ default = "/var/lib/ipfs";
39+ description = "The data dir for IPFS";
40+ };
41+
42+ autoMigrate = mkOption {
43+ type = types.bool;
44+ default = false;
45+ description = ''
46+ Whether IPFS should try to migrate the file system automatically.
47+ '';
48+ };
49+
50+ enableGC = mkOption {
51+ type = types.bool;
52+ default = false;
53+ description = ''
54+ Whether to enable automatic garbage collection.
55+ '';
56+ };
57+
58+ extraFlags = mkOption {
59+ type = types.listOf types.str;
60+ description = "Extra flags passed to the IPFS daemon";
61+ default = [];
62+ };
63+ };
64+ };
65+
66+ ###### implementation
67+
68+ config = mkIf cfg.enable {
69+ environment.systemPackages = [ pkgs.ipfs ];
70+
71+ users.extraUsers = mkIf (cfg.user == "ipfs") {
72+ ipfs = {
73+ group = cfg.group;
74+ home = cfg.dataDir;
75+ createHome = false;
76+ uid = config.ids.uids.ipfs;
77+ description = "IPFS daemon user";
78+ };
79+ };
80+
81+ users.extraGroups = mkIf (cfg.group == "ipfs") {
82+ ipfs = {
83+ gid = config.ids.gids.ipfs;
84+ };
85+ };
86+
87+ systemd.services.ipfs = {
88+ description = "IPFS Daemon";
89+
90+ wantedBy = [ "multi-user.target" ];
91+ after = [ "network.target" "local-fs.target" ];
92+ path = [ pkgs.ipfs pkgs.su pkgs.bash ];
93+
94+ preStart =
95+ ''
96+ install -m 0755 -o ${cfg.user} -g ${cfg.group} -d ${cfg.dataDir}
97+ if [[ ! -d ${cfg.dataDir}/.ipfs ]]; then
98+ cd ${cfg.dataDir}
99+ ${pkgs.su}/bin/su -s ${pkgs.bash}/bin/sh ${cfg.user} -c "${ipfs}/bin/ipfs init"
100+ fi
101+ '';
102+
103+ serviceConfig = {
104+ ExecStart = "${ipfs}/bin/ipfs daemon ${ipfsFlags}";
105+ User = cfg.user;
106+ Group = cfg.group;
107+ PermissionsStartOnly = true;
108+ };
109+ };
110+ };
111+}