dev.fron.io rc / 39d4fd8
overlays(gitfs): fix gitfs Tony Olagbaiye 8 months ago
4 changed file(s) with 172 addition(s) and 126 deletion(s). Raw diff Collapse all Expand all
00 [
11 ./programs/nix-index.nix
22 ./services/nix-index.nix
3 ./services/git/nixos.nix
3 ./services/gitfs.nix
44 ./services/hydroxide/default.nix
55 ./services/ipfs-cluster/default.nix
66 ./security/mitigations.nix
+0
-125
modules/services/git/nixos.nix less more
0 { config, lib, pkgs, ... }:
1 with lib;
2 let
3 cfg = config.services.nixos-git;
4 workdir = "/var/lib/gitfs";
5 githubRemote = with cfg.github; "http://github.com/${owner}/${repo}";
6 in {
7 options.services.nixos-git = {
8 enable = mkEnableOption "NixOS.git";
9
10 directory = mkOption {
11 type = types.path;
12 default = "/run/git/nixos";
13 description = ''
14 The directory where nixos.git will be mounted.
15 '';
16 };
17
18 github = {
19 owner = mkOption {
20 type = with types; nullOr str;
21 default = null;
22 example = "bqv";
23 description = ''
24 Owner of the repository hosted on GitHub.
25 '';
26 };
27
28 repo = mkOption {
29 type = with types; nullOr str;
30 default = null;
31 example = "nixos";
32 description = ''
33 Name of the repository hosted on GitHub.
34 '';
35 };
36 };
37
38 remote = mkOption {
39 type = with types; nullOr str;
40 default = null;
41 example = "http://github.com/bqv/nixos";
42 description = ''
43 Url of the repository.
44 '';
45 };
46
47 branch = mkOption {
48 type = types.str;
49 default = "master";
50 example = "live";
51 description = ''
52 Name of the branch of the repository to be mounted.
53 '';
54 };
55
56 extraParams = mkOption {
57 type = types.attrs;
58 default = {};
59 example = { idle_fetch_timeout = "10"; };
60 description = ''
61 Extra params to pass to the mounter.
62 '';
63 };
64
65 package = mkOption {
66 type = types.package;
67 default = pkgs.gitfs;
68 defaultText = "pkgs.gitfs";
69 description = ''
70 Which gitfs package to use.
71 '';
72 };
73 };
74
75 config = mkIf cfg.enable {
76 assertions = [
77 {
78 assertion = !(builtins.all (v: v == null)
79 [ cfg.github.owner cfg.github.repo cfg.remote ]);
80 message = ''
81 You must set either remote or github in services.nixos-git.
82 '';
83 }
84 {
85 assertion = ((cfg.github.owner == null) == (cfg.github.repo == null));
86 message = ''
87 You must set both owner and repo in services.nixos-git.github.
88 '';
89 }
90 ];
91
92 programs.fuse.userAllowOther = true;
93
94 systemd.services.nixos-git = let
95 in {
96 enable = true;
97 path = [ cfg.package pkgs.coreutils ];
98 after = [ "network.target" ];
99 description = "NixOS.git Mount";
100 environment.HOME = workdir;
101 wantedBy = [ "multi-user.target" ];
102 serviceConfig = {
103 ExecStartPre = ''
104 ${pkgs.coreutils}/bin/mkdir -p ${workdir} ${cfg.directory}
105 '';
106 ExecStart = let
107 url = if ((cfg.github.owner == null) || (cfg.github.repo == null))
108 then cfg.remote else githubRemote;
109 params = cfg.extraParams // {
110 branch = cfg.branch;
111 foreground = "true";
112 allow_other = "true";
113 };
114 paramsString = concatStringsSep "," (
115 lib.mapAttrsToList (k: v: "${k}=${builtins.toString v}") params);
116 in ''
117 ${cfg.package}/bin/gitfs ${url} -o ${paramsString} ${cfg.directory}
118 '';
119 Restart = "always";
120 RestartSec = 15;
121 };
122 };
123 };
124 }
0 { config, lib, pkgs, ... }:
1
2 let
3 cfg = config.services.gitfs;
4 in {
5 options.services.gitfs = with lib; {
6 enable = mkEnableOption "gitfs";
7
8 workdir = mkOption {
9 type = types.str;
10 default = "/var/lib/gitfs";
11 description = ''
12 The internal gitfs working directory.
13 '';
14 };
15
16 mounts = mkOption {
17 type = types.attrsOf (types.submodule ({ name, config, ... }: {
18 options = {
19 directory = mkOption {
20 type = types.path;
21 default = name;
22 description = ''
23 The directory where nixos.git will be mounted.
24 '';
25 };
26
27 github = {
28 owner = mkOption {
29 type = with types; nullOr str;
30 default = null;
31 example = "bqv";
32 description = ''
33 Owner of the repository hosted on GitHub.
34 '';
35 };
36
37 repo = mkOption {
38 type = with types; nullOr str;
39 default = null;
40 example = "nixrc";
41 description = ''
42 Name of the repository hosted on GitHub.
43 '';
44 };
45
46 remote = mkOption {
47 type = types.str;
48 internal = true;
49 default = with config.github; "http://github.com/${owner}/${repo}";
50 };
51 };
52
53 remote = mkOption {
54 type = with types; nullOr str;
55 default = null;
56 example = "http://github.com/bqv/nixrc";
57 description = ''
58 Url of the repository.
59 '';
60 };
61
62 branch = mkOption {
63 type = types.str;
64 default = "master";
65 example = "live";
66 description = ''
67 Name of the branch of the repository to be mounted.
68 '';
69 };
70
71 extraParams = mkOption {
72 type = types.attrs;
73 default = {};
74 example = { idle_fetch_timeout = "10"; };
75 description = ''
76 Extra params to pass to the mounter.
77 '';
78 };
79
80 invocation = mkOption {
81 type = types.submodule {
82 options = {
83 url = mkOption { type = types.str; };
84 params = mkOption { type = types.str; };
85 };
86 };
87 internal = true;
88 default = {
89 url = if ((config.github.owner == null) || (config.github.repo == null))
90 then config.remote else config.github.remote;
91 params = let
92 paramAttrs = config.extraParams // {
93 inherit (config) branch;
94 foreground = "true";
95 allow_other = "true";
96 };
97 toKVList = lib.mapAttrsToList (k: v: "${k}=${builtins.toString v}");
98 in concatStringsSep "," (toKVList paramAttrs);
99 };
100 };
101 };
102 }));
103 default = {
104 };
105 };
106
107 package = mkOption {
108 type = types.package;
109 default = pkgs.gitfs;
110 defaultText = "pkgs.gitfs";
111 description = ''
112 Which gitfs package to use.
113 '';
114 };
115 };
116
117 config = lib.mkIf cfg.enable {
118 assertions = [
119 {
120 assertion = builtins.all (mnt: !(builtins.all (v: v == null)
121 [ mnt.github.owner mnt.github.repo mnt.remote ])) (builtins.attrValues cfg.mounts);
122 message = ''
123 You must set either remote or github in services.gitfs.mounts.
124 '';
125 }
126 {
127 assertion = builtins.all (mnt: ((mnt.github.owner == null) == (mnt.github.repo == null))) (builtins.attrValues cfg.mounts);
128 message = ''
129 You must set both owner and repo in services.gitfs.github.mounts.
130 '';
131 }
132 ];
133
134 environment.systemPackages = [ cfg.package ];
135
136 programs.fuse.userAllowOther = true;
137
138 systemd.services = lib.mapAttrs' (name: mnt: {
139 name = lib.strings.sanitizeDerivationName "gitfs-${name}";
140 value = {
141 enable = true;
142 path = [ cfg.package pkgs.coreutils ];
143 after = [ "network.target" ];
144 description = "${mnt.directory} gitfs mount of ${mnt.invocation.url}";
145 environment.HOME = cfg.workdir;
146 wantedBy = [ "multi-user.target" ];
147 serviceConfig = {
148 ExecStartPre = ''
149 ${pkgs.coreutils}/bin/mkdir -p ${cfg.workdir} ${mnt.directory}
150 '';
151 ExecStart = ''
152 ${cfg.package}/bin/gitfs ${mnt.invocation.url} -o ${mnt.invocation.params} ${mnt.directory}
153 '';
154 Restart = "always";
155 RestartSec = 15;
156 };
157 };
158 }) cfg.mounts;
159 };
160 }
0 inputs@{...}: final: prev: {
1 gitfs = prev.gitfs.overrideAttrs (drv: {
2 doInstallCheck = true;
3 installCheckPhase = "$out/bin/gitfs --help";
4 installCheckInputs = [ final.cacert ];
5 patchPhase = drv.patchPhase + ''
6 sed -i 's/from pygit2.remote import RemoteCallbacks/from pygit2.callbacks import RemoteCallbacks/' gitfs/mounter.py
7 '';
8 });
9 }