-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add mkcert and hostctl instrumentation
- Loading branch information
David Arnold
committed
Oct 9, 2020
1 parent
4859a38
commit 5a24b56
Showing
9 changed files
with
229 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# mimick use case where users are expected to boostrap their dev ca | ||
# this is also better for testing devhsell ca bootstrapping | ||
dev-ca |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ buildGoModule, fetchFromGitHub, lib, installShellFiles }: | ||
|
||
buildGoModule rec { | ||
pname = "hostctl"; | ||
version = "1.0.14"; | ||
|
||
src = fetchFromGitHub { | ||
owner = "guumaster"; | ||
repo = pname; | ||
rev = "v${version}"; | ||
sha256 = "02bjii97l4fy43v2rb93m9b0ad8y6mjvbvp4sz6a5n0w9dm1z1q9"; | ||
}; | ||
|
||
vendorSha256 = "1lqk3cda0frqp2vwkqa4b3xkdw814wgkbr7g9r2mwxn85fpdcq5c"; | ||
|
||
doCheck = false; | ||
buildFlagsArray = [ "-ldflags=-s -w -X github.com/guumaster/hostctl/cmd/hostctl/actions.version=${version}" ]; | ||
|
||
nativeBuildInputs = [ installShellFiles ]; | ||
postInstall = '' | ||
$out/bin/hostctl completion bash > hostctl.bash | ||
$out/bin/hostctl completion zsh > hostctl.zsh | ||
installShellCompletion hostctl.{bash,zsh} | ||
# replace above by following once merged https://github.com/NixOS/nixpkgs/pull/83630 | ||
# installShellCompletion --cmd hostctl \ | ||
# --bash <($out/bin/hostctl completion bash) \ | ||
# --zsh <($out/bin/hostctl completion zsh) | ||
''; | ||
|
||
meta = with lib; { | ||
description = "Your dev tool to manage /etc/hosts like a pro!"; | ||
longDescription = '' | ||
This tool gives you more control over the use of your hosts file. | ||
You can have multiple profiles and switch them on/off as you need. | ||
''; | ||
homepage = "https://guumaster.github.io/hostctl/"; | ||
license = licenses.mit; | ||
maintainers = with maintainers; [ blaggacao ]; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{ lib, pkgs, config }: | ||
let | ||
inherit (config) | ||
name | ||
dev-ca-path | ||
static-dns | ||
; | ||
installProjectCA = { | ||
name = "ca-install"; | ||
help = "install dev CA"; | ||
category = "host state"; | ||
package = pkgs.mkcert; | ||
command = '' | ||
echo "$(tput bold)Installing the ${name}'s dev CA into local trust stores via mkcert command ...$(tput sgr0)" | ||
export CAROOT=${dev-ca-path} | ||
${pkgs.mkcert}/bin/mkcert -install | ||
''; | ||
}; | ||
uninstallProjectCA = { | ||
name = "ca-uninstall"; | ||
help = "uninstall dev CA"; | ||
category = "host state"; | ||
package = pkgs.mkcert; | ||
command = '' | ||
echo "$(tput bold)Purging the ${name}'s dev CA from local trust stores via mkcert command ...$(tput sgr0)" | ||
export CAROOT=${dev-ca-path} | ||
${pkgs.mkcert}/bin/mkcert -uninstall | ||
''; | ||
}; | ||
|
||
etcHosts = pkgs.writeText "${name}-etchosts" | ||
(lib.concatStringsSep "\n" | ||
(lib.mapAttrsToList (name: value: value + " " + name) static-dns) | ||
); | ||
# since this temporarily modifies /etc/hosts, use of sudo can't be avoided | ||
fqdnsActivate = { | ||
name = "dns-activate"; | ||
category = "host state"; | ||
help = "activate pre-configured static dns"; | ||
package = pkgs.hostctl; | ||
command = '' | ||
echo "$(tput bold)Installing ${name}'s static local DNS resolution via hostctl command ...$(tput sgr0)" | ||
sudo ${pkgs.hostctl}/bin/hostctl add ${name} --from ${etcHosts} | ||
''; | ||
}; | ||
fqdnsDeactivate = { | ||
name = "dns-deactivate"; | ||
category = "host state"; | ||
help = "deactivate pre-configured static dns"; | ||
package = pkgs.hostctl; | ||
command = '' | ||
echo "$(tput bold)Purging ${name}'s static local DNS resolution via hostctl command ...$(tput sgr0)" | ||
sudo ${pkgs.hostctl}/bin/hostctl remove ${name} | ||
''; | ||
}; | ||
in | ||
( | ||
if static-dns == null || static-dns == "" then [ ] | ||
else [ fqdnsActivate fqdnsDeactivate ] | ||
) ++ | ||
( | ||
if dev-ca-path == null || dev-ca-path == "" then [ ] | ||
else [ installProjectCA uninstallProjectCA ] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters