Skip to content

Commit f14806c

Browse files
author
David Arnold
committed
Incorporate Nix Friday Feedback
1 parent 5a24b56 commit f14806c

File tree

7 files changed

+69
-54
lines changed

7 files changed

+69
-54
lines changed

default.nix

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
}:
44
import nixpkgs {
55
inherit system;
6-
overlays = [ (import ./overlay.nix) ];
6+
overlays = [
7+
(import ./overlay.nix)
8+
(import ./extensions/overlay.nix)
9+
];
710
}
File renamed without changes.

mkDevShell/instrumentation.nix renamed to extensions/hoststate-instrumentation.nix

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
{ lib, pkgs, config }:
1+
{ lib, pkgs, config, ... }:
2+
with lib;
23
let
34
inherit (config)
45
name
5-
dev-ca-path
66
static-dns
7+
dev-ca-path
78
;
9+
810
installProjectCA = {
911
name = "ca-install";
1012
help = "install dev CA";
@@ -54,11 +56,52 @@ let
5456
'';
5557
};
5658
in
57-
(
58-
if static-dns == null || static-dns == "" then [ ]
59-
else [ fqdnsActivate fqdnsDeactivate ]
60-
) ++
61-
(
62-
if dev-ca-path == null || dev-ca-path == "" then [ ]
63-
else [ installProjectCA uninstallProjectCA ]
64-
)
59+
{
60+
options = {
61+
dev-ca-path = mkOption {
62+
type = types.str;
63+
default = "";
64+
description = ''
65+
Path to a development CA.
66+
67+
Users can load/unload this dev CA easily and cleanly into their local
68+
trust stores via a wrapper around mkcert third party tool so that browsers
69+
and other tools would accept issued certificates under this CA as valid.
70+
71+
Use cases:
72+
- Ship static dev certificates under version control and make them trusted
73+
on user machines: add the rootCA under version control alongside the
74+
your dev certificates.
75+
- Provide users with easy and reliable CA bootstrapping through the mkcert
76+
command: exempt this path from version control via .gitignore and have
77+
users easily and reliably bootstrap a dev CA infrastructure on first use.
78+
'';
79+
};
80+
static-dns = mkOption {
81+
type = types.attrs;
82+
default = { };
83+
description = ''
84+
A list of static DNS entries, for which to enable instrumentation.
85+
86+
Users can enable/disable listed static DNS easily and cleanly
87+
via a wrapper around the hostctl third party tool.
88+
'';
89+
example = {
90+
"test.domain.local" = "172.0.0.1";
91+
"shared.domain.link-local" = "169.254.0.5";
92+
};
93+
};
94+
};
95+
config = {
96+
commands =
97+
(
98+
if static-dns == null || static-dns == "" then [ ]
99+
else [ fqdnsActivate fqdnsDeactivate ]
100+
) ++
101+
(
102+
if dev-ca-path == null || dev-ca-path == "" then [ ]
103+
else [ installProjectCA uninstallProjectCA ]
104+
);
105+
};
106+
}
107+

extensions/overlay.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
final: prev:
2+
{
3+
hostctl = prev.callPackage ./hostctl { };
4+
}
5+

mkDevShell/options.nix

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{ lib, pkgs, config, ... }:
22
with lib;
33
let
4-
instrumentedCommands = import ./instrumentation.nix { inherit lib pkgs config; };
5-
64
resolveKey = key:
75
let
86
attrs = builtins.filter builtins.isString (builtins.split "\\." key);
@@ -139,27 +137,6 @@ in
139137
'';
140138
};
141139

142-
# exclusively consumed by command instrumentation
143-
dev-ca-path = mkOption {
144-
type = types.str;
145-
default = "";
146-
description = ''
147-
Path to a development CA.
148-
149-
Users can load/unload this dev CA easily and cleanly into their local
150-
trust stores via a wrapper around mkcert third party tool so that browsers
151-
and other tools would accept issued certificates under this CA as valid.
152-
153-
Use cases:
154-
- Ship static dev certificates under version control and make them trusted
155-
on user machines: add the rootCA under version control alongside the
156-
your dev certificates.
157-
- Provide users with easy and reliable CA bootstrapping through the mkcert
158-
command: exempt this path from version control via .gitignore and have
159-
users easily and reliably bootstrap a dev CA infrastructure on first use.
160-
'';
161-
};
162-
163140
commands = mkOption {
164141
type = types.listOf (types.submodule { options = commandOptions; });
165142
default = [ ];
@@ -233,23 +210,6 @@ in
233210
'';
234211
};
235212

236-
# exclusively consumed by command instrumentation
237-
static-dns = mkOption {
238-
type = types.attrs;
239-
default = { };
240-
description = ''
241-
A list of static DNS entries, for which to enable instrumentation.
242-
243-
Users can enable/disable listed static DNS easily and cleanly
244-
via a wrapper around the hostctl third party tool.
245-
'';
246-
example = {
247-
"test.domain.local" = "172.0.0.1";
248-
"shared.domain.link-local" = "169.254.0.5";
249-
};
250-
};
251-
252-
253213
};
254214

255215
config = {
@@ -263,7 +223,7 @@ in
263223
DEVSHELL_MENU
264224
'';
265225
}
266-
] ++ instrumentedCommands;
226+
];
267227

268228
packages =
269229
lib.unique (

overlay.nix

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ final: prev:
22
{
33
devshell = prev.callPackage ./devshell { };
44
mkDevShell = prev.callPackage ./mkDevShell { };
5-
hostctl = prev.callPackage ./hostctl { };
65
}

shell.nix

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
#!/usr/bin/env nix-build
22
# Used to test the shell
33
{ pkgs ? import ./. { } }:
4-
pkgs.mkDevShell.fromTOML ./devshell.toml
4+
pkgs.mkDevShell {
5+
imports = [
6+
(pkgs.mkDevShell.importTOML ./devshell.toml)
7+
./extensions/hoststate-instrumentation.nix
8+
];
9+
}

0 commit comments

Comments
 (0)