-
Notifications
You must be signed in to change notification settings - Fork 1
/
github.nix
87 lines (75 loc) · 2.18 KB
/
github.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
{ pkgs, config, lib, ... }:
# Automatically set git remotes URL for Github repositories.
# To easily use this module, use a reusable workspace like:
#
# gh = {
# github.origin = "my username";
# };
#
# It's also a good place to set 'github.ssh_prefix'.
# Then import in every workspaces that use Github:
#
# imports = [ gh ];
#
with lib;
let
conf = config.github;
mkUrl = prefix: org: "${prefix}${org}/${config.name}";
mkHttpUrl = mkUrl "https://github.com/";
mkSshUrl = mkUrl conf.ssh_prefix;
mkFetchUrl = if conf.private then
assert assertMsg (conf.ssh_prefix != null)
"'github.ssh_prefix' must be set when 'github.private' is set to 'true'.";
mkSshUrl
else
mkHttpUrl;
mkPushUrl = if conf.ssh_prefix != null then mkSshUrl else mkHttpUrl;
mkPushPullUrl = org: {
fetch = mkFetchUrl org;
push = mkPushUrl org;
};
in {
options = with lib; {
github.origin = mkOption {
type = types.nullOr types.string;
default = null;
description = ''
Set 'git.remotes.origin' to point to the Github repository
'<this value>/<workspace name>'.
'';
};
github.up = mkOption {
type = types.nullOr types.string;
default = null;
description = ''
Same as the 'origin' option but for a remote named 'up'.
'';
};
github.extra_remotes = mkOption {
type = types.listOf types.string;
default = [ ];
description = ''
Extra remotes, named after the user hosting the repository. Useful for forks, for example.
'';
};
github.ssh_prefix = mkOption {
type = types.nullOr types.string;
default = null;
description = ''
Prefix to use for SSH urls, which are used for 'push' url. If this is
unset, only HTTPS urls are used.
'';
};
github.private = mkOption {
type = types.bool;
default = false;
description = "Use the SSH url for both push and fetch.";
};
};
config = {
git.remotes = {
up = lib.mkIf (conf.up != null) (mkFetchUrl conf.up);
origin = lib.mkIf (conf.origin != null) (mkPushPullUrl conf.origin);
} // lib.genAttrs conf.extra_remotes mkPushPullUrl;
};
}