-
Notifications
You must be signed in to change notification settings - Fork 4
/
flake.nix
246 lines (185 loc) · 7.94 KB
/
flake.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# ============================================================================ #
#
#
#
# ---------------------------------------------------------------------------- #
{
# ---------------------------------------------------------------------------- #
description = "Yet another Nix+Node.js framework";
# ---------------------------------------------------------------------------- #
outputs = { nixpkgs, ... } @ inputs: let
# ---------------------------------------------------------------------------- #
inherit (( import ./lib { inherit (nixpkgs) lib; } ).libfloco)
eachSupportedSystemMap
;
# ---------------------------------------------------------------------------- #
overlays.deps = final: prev: {};
overlays.floco = import ./overlay.nix;
overlays.default = nixpkgs.lib.composeExtensions overlays.deps
overlays.floco;
# ---------------------------------------------------------------------------- #
nixosModules.default = nixosModules.floco;
nixosModules.floco = import ./modules/top;
nixosModules.plockToPdefs = { lib, lockDir, basedir, ... }: {
imports = [./modules/top];
config._module.args.basedir = lib.mkDefault lockDir;
config._module.args.lockDir = lib.mkDefault basedir;
options.floco = lib.mkOption {
type = lib.types.submoduleWith {
shorthandOnlyDefinesConfig = false;
modules = [
./modules/plockToPdefs
{
config._module.args.basedir = basedir;
config.lockDir = lib.mkDefault lockDir;
}
];
};
};
};
# Use `nixpkgs#fetchzip' instead of `builtins.fetchTree' for tarballs.
#
# This changes the caching behavior of tarballs, particularly when used in
# combination with a remote binary cache.
#
# This module is a recommended addition to `nixosModules.floco' for driving
# builds in a CI/CD context with a remote cache, because it skips fetching
# tarballs that are inputs to existing cached artifacts.
# Without this module, `builtins.fetchTree' will fetch any tarballs which
# are an input to any requested artifact, regardless of whether or not that
# artifact is already in the remote store.
#
# This module may not be desireable for local development on builds which
# may fail, because `nix' will not save inputs to failed results in its
# store, causing them to be refetched repeatedly until the build succeeds.
nixosModules.useFetchZip = import ./modules/configs/use-fetchzip.nix;
# ---------------------------------------------------------------------------- #
in { # Begin `outputs'
# ---------------------------------------------------------------------------- #
lib = import ./lib { inherit (nixpkgs) lib; };
# ---------------------------------------------------------------------------- #
inherit overlays nixosModules;
# ---------------------------------------------------------------------------- #
packages = eachSupportedSystemMap ( system: let
pkgsFor = nixpkgs.legacyPackages.${system}.extend overlays.default;
in {
inherit (pkgsFor)
floco
floco-nix
floco-utils
floco-hooks
floco-updaters
treeFor
semver
pacote
arborist
db
;
default = pkgsFor.floco;
} );
# ---------------------------------------------------------------------------- #
apps = eachSupportedSystemMap ( system: let
pkgsFor = nixpkgs.legacyPackages.${system}.extend overlays.default;
stripNL = s: let
m = builtins.match "\n*\([^\n]*.*[^\n]\)\n*" s;
in if m == null then m else builtins.head m;
in {
fromPlock = {
type = "app";
program = let
msg = stripNL ''
floco#fromPlock: The \`fromPlock' routine is deprecated.
Use \`floco -- translate ARGS...' or
`nix run github:aakropotkin/floco -- translate ARGS...` instead.
'';
in builtins.trace msg "${pkgsFor.floco-updaters}/bin/npm-plock.sh";
};
fromRegistry = {
type = "app";
program = let
msg = stripNL ''
floco#fromPlock: The \`fromRegistry' routine is deprecated.
Use \`floco -- translate ARGS...' or
`nix run github:aakropotkin/floco -- translate ARGS...` instead.
'';
in builtins.trace msg "${pkgsFor.floco-updaters}/bin/from-registry.sh";
};
} );
# ---------------------------------------------------------------------------- #
templates = let
basic = {
description = "a legacy style `default.nix' for a local project.";
path = ./templates/basic;
welcomeText = ''
Initialize/update your project by running:
nix run github:aakropotkin/floco -- translate -pt;
Build with:
nix build -f ./. -L global;
Be sure to read `foverrides.nix' to customize your build.
If you do not require this file feel free to delete it.
'';
};
in {
inherit basic;
default = basic;
registry = {
description = "a legacy style `default.nix' for a registry package.";
path = ./templates/registry;
welcomeText = ''
Initialize/update your package by running:
nix run github:aakropotkin/floco -- translate -pt <IDENT>@<VERSION>;
echo '{ ident = "<IDENT>"; version = "<VERSION>"; }' > info.nix;
Build with:
nix build -f ./. -L;
If you don't require `foverrides.nix', feel free to remove it.
'';
};
};
# ---------------------------------------------------------------------------- #
# A shorthand for accessing `nixpkgs' with `overlays.floco' applied.
# This is equivalent to `nixpkgs.legacyPackages', but intentionally uses a
# different name to indicate that it is an EXTENDED `nixpkgs' rather
# than the subset of packages defined in `overlays.floco'.
pkgsFor = let
bySystem = eachSupportedSystemMap ( system:
nixpkgs.legacyPackages.${system}.extend overlays.default
);
in bySystem // {
__functor = pf: system:
pf.${system} or (
throw "floco#pkgsFor: Unsupported system: ${system}"
);
};
# ---------------------------------------------------------------------------- #
# Convenience function that evaluates the `floco' module system on a
# singleton or list of modules/directories.
#
# This has a flexible call style that allows you to indicate `system'.
# To be explicit use either:
# runFloco.<system> <module(s)>
# runFloco "<system>" <module(s)>
# To omit system intentionally:
# runFloco.unknown <module(s)>
# runFloco "unknown" <module(s)>
# Or to use the current system as the default, simply:
# runFloco <module(s)>
#
# In `pure' evaluation mode, attempts to reference `builtins.currentSystem'
# will fall back to "unknown", meaning you will only be able to use `lib'
# routines and parts of the module system that do not reference `pkgs'.
#
# This is recommended as a convenience routine for interactive use on the
# CLI, and is explicitly NOT recommended for use scripts or CI automation.
# For non-interactive use, please use `lib.evalModules' directly, and be
# explicit about `system', module paths, and handling of JSON files
# ( use `lib.modules.importJSON' or `lib.libfloco.processImports[Floco]' ).
inherit (( import ./lib { inherit (nixpkgs) lib; } ).libfloco) runFloco;
# ---------------------------------------------------------------------------- #
}; # End `outputs'
# ---------------------------------------------------------------------------- #
}
# ---------------------------------------------------------------------------- #
#
#
#
# ============================================================================ #