Skip to content

Commit a347c9a

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

12 files changed

Lines changed: 157 additions & 164 deletions

File tree

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
}

devshell.toml

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,6 @@ packages = [
1616
#
1717
# motd = ""
1818

19-
# This setting helps to add a project's shared *development* root CA
20-
# to host's local trust stores by instrumenting the mkcert third party tool.
21-
# Defining this section also adds `mkcert` to the available packages.
22-
# Set to the path where mkcert-generated CAROOT files are expected to exist
23-
#
24-
# NOTES:
25-
# - be careful to only put *development* certificates under version control
26-
# - create those files with the devshell generated *-install-CA command
27-
# - optionally put this path under .gitignore, if you want users to
28-
# generate certificates themselves on first clone (using *-install-CA)
29-
dev-ca-path = "./dev-ca"
30-
3119
# Use this section to set environment variables to have in the environment.
3220
#
3321
# NOTE: all the values are escaped
@@ -67,10 +55,32 @@ name = "hub"
6755
package = "gitAndTools.hub"
6856
category = "utilites"
6957

58+
59+
# ============================================================================
60+
# Example of custom extensions NOT part of devshell, see also:
61+
# ============================================================================
62+
# ./default.nix
63+
# ./shell.nix
64+
# ./extensions/*
65+
# ============================================================================
66+
67+
[extensions]
68+
# This setting helps to add a project's shared *development* root CA
69+
# to host's local trust stores by instrumenting the mkcert third party tool.
70+
# Defining this section also adds `mkcert` to the available packages.
71+
# Set to the path where mkcert-generated CAROOT files are expected to exist
72+
#
73+
# NOTES:
74+
# - be careful to only put *development* certificates under version control
75+
# - create those files with the devshell generated *-install-CA command
76+
# - optionally put this path under .gitignore, if you want users to
77+
# generate certificates themselves on first clone (using *-install-CA)
78+
dev-ca-path = "./dev-ca"
79+
7080
# These settings help to manage local DNS overrides via
7181
# instrumentation of the hostcl third party tool.
7282
# Defining this section also adds `hostctl` to the available packages.
73-
[static-dns]
83+
[extensions.static-dns]
7484
"test.domain.local" = "172.0.0.1"
7585
"shared.domain.link-local" = "169.254.0.5"
7686

devshell/config.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@ type config struct {
2525
Name string `toml:"name"`
2626
Packages []string `toml:"packages"`
2727
Motd *string `toml:"motd"`
28-
DevCaPath *string `toml:"dev-ca-path,omitempty"`
2928
Env map[string]interface{} `toml:"env"`
3029
Bash configBash `toml:"bash,omitempty"`
3130
Commands []configCommand `toml:"commands"`
32-
StaticDNS map[string]interface{} `toml:"static-dns,omitempty"`
3331
}
3432

3533
func configLoad(path string) (*config, error) {

docs/devshell.toml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,6 @@ packages = [
1616
#
1717
# motd = ""
1818

19-
# This setting helps to add a project's shared *development* root CA
20-
# to host's local trust stores by instrumenting the mkcert third party tool.
21-
# Defining this section also adds `mkcert` to the available packages.
22-
# Set to the path where mkcert-generated CAROOT files are expected to exist
23-
#
24-
# NOTES:
25-
# - be careful to only put *development* certificates under version control
26-
# - create those files with the devshell generated *-install-CA command
27-
# - optionally put this path under .gitignore, if you want users to
28-
# generate certificates themselves on first clone (using *-install-CA)
29-
# dev-ca-path = "./dev-ca"
30-
3119
# Use this section to set environment variables to have in the environment.
3220
#
3321
# NOTE: all the values are escaped
@@ -67,9 +55,3 @@ name = "hub"
6755
package = "gitAndTools.hub"
6856
category = "utilites"
6957

70-
# These settings help to manage local DNS overrides via
71-
# instrumentation of the hostcl third party tool.
72-
# Defining this section also adds `hostctl` to the available packages.
73-
[static-dns]
74-
"test.domain.local" = "172.0.0.1"
75-
"shared.domain.link-local" = "169.254.0.5"

docs/devshell.toml.md

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,6 @@ packages = [
2424
#
2525
# motd = ""
2626

27-
# This setting helps to add a project's shared *development* root CA
28-
# to host's local trust stores by instrumenting the mkcert third party tool.
29-
# Defining this section also adds `mkcert` to the available packages.
30-
# Set to the path where mkcert-generated CAROOT files are expected to exist
31-
#
32-
# NOTES:
33-
# - be careful to only put *development* certificates under version control
34-
# - create those files with the devshell generated *-install-CA command
35-
# - optionally put this path under .gitignore, if you want users to
36-
# generate certificates themselves on first clone (using *-install-CA)
37-
# dev-ca-path = "./dev-ca"
38-
3927
# Use this section to set environment variables to have in the environment.
4028
#
4129
# NOTE: all the values are escaped
@@ -74,13 +62,6 @@ help = "github utility"
7462
name = "hub"
7563
package = "gitAndTools.hub"
7664
category = "utilities"
77-
78-
# These settings help to manage local DNS overrides via
79-
# instrumentation of the hostcl third party tool.
80-
# Defining this section also adds `hostctl` to the available packages.
81-
[static-dns]
82-
"test.domain.local" = "172.0.0.1"
83-
"shared.domain.link-local" = "169.254.0.5"
8465
```
8566

8667
## Schema
@@ -104,8 +85,6 @@ The name field is optional and defaults to `devshell`.
10485

10586
### The `motd` field
10687

107-
### The `dev-ca-path` field
108-
10988
### The `env` section
11089

11190
### The `bash.extra` field
@@ -119,5 +98,3 @@ The name field is optional and defaults to `devshell`.
11998
* `name`:
12099
* `package`:
121100

122-
### The `static-dns` section
123-

extensions/options.nix

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
{ lib, pkgs, config, ... }:
2+
with lib;
3+
let
4+
inherit (config)
5+
name
6+
;
7+
inherit (config.extensions)
8+
static-dns
9+
dev-ca-path
10+
;
11+
12+
installProjectCA = {
13+
name = "ca-install";
14+
help = "install dev CA";
15+
category = "host state";
16+
package = pkgs.mkcert;
17+
command = ''
18+
echo "$(tput bold)Installing the ${name}'s dev CA into local trust stores via mkcert command ...$(tput sgr0)"
19+
export CAROOT=${dev-ca-path}
20+
${pkgs.mkcert}/bin/mkcert -install
21+
'';
22+
};
23+
uninstallProjectCA = {
24+
name = "ca-uninstall";
25+
help = "uninstall dev CA";
26+
category = "host state";
27+
package = pkgs.mkcert;
28+
command = ''
29+
echo "$(tput bold)Purging the ${name}'s dev CA from local trust stores via mkcert command ...$(tput sgr0)"
30+
export CAROOT=${dev-ca-path}
31+
${pkgs.mkcert}/bin/mkcert -uninstall
32+
'';
33+
};
34+
35+
etcHosts = pkgs.writeText "${name}-etchosts"
36+
(lib.concatStringsSep "\n"
37+
(lib.mapAttrsToList (name: value: value + " " + name) static-dns)
38+
);
39+
# since this temporarily modifies /etc/hosts, use of sudo can't be avoided
40+
fqdnsActivate = {
41+
name = "dns-activate";
42+
category = "host state";
43+
help = "activate pre-configured static dns";
44+
package = pkgs.hostctl;
45+
command = ''
46+
echo "$(tput bold)Installing ${name}'s static local DNS resolution via hostctl command ...$(tput sgr0)"
47+
sudo ${pkgs.hostctl}/bin/hostctl add ${name} --from ${etcHosts}
48+
'';
49+
};
50+
fqdnsDeactivate = {
51+
name = "dns-deactivate";
52+
category = "host state";
53+
help = "deactivate pre-configured static dns";
54+
package = pkgs.hostctl;
55+
command = ''
56+
echo "$(tput bold)Purging ${name}'s static local DNS resolution via hostctl command ...$(tput sgr0)"
57+
sudo ${pkgs.hostctl}/bin/hostctl remove ${name}
58+
'';
59+
};
60+
extensionOptions = {
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+
in
96+
{
97+
options = {
98+
extensions = mkOption {
99+
type = types.submodule { options = extensionOptions; };
100+
default = [ ];
101+
description = ''
102+
Custom extensions to devshell.
103+
'';
104+
};
105+
};
106+
config = {
107+
commands =
108+
(
109+
if static-dns == null || static-dns == "" then [ ]
110+
else [ fqdnsActivate fqdnsDeactivate ]
111+
) ++
112+
(
113+
if dev-ca-path == null || dev-ca-path == "" then [ ]
114+
else [ installProjectCA uninstallProjectCA ]
115+
);
116+
};
117+
}
118+

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/instrumentation.nix

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)