Skip to content

Commit 9c12b4e

Browse files
kylecarbscmoogmafredri
authored
chore: Add nix shell for simple development setup (coder#3399)
* chore: Add nix shell for simple development setup This enables contributors using Nix to set up their environment with ease. * improve nix style, flake output schema * fix error message * Update scripts/build_go_slim.sh Co-authored-by: Mathias Fredriksson <[email protected]> * Update scripts/build_go_slim.sh Co-authored-by: Mathias Fredriksson <[email protected]> * Add UTC default for timezone and remove unnecessary goreleaser dependency * Skip TZ test if localtime does not exist Co-authored-by: Charlie Moog <[email protected]> Co-authored-by: Mathias Fredriksson <[email protected]>
1 parent 3279504 commit 9c12b4e

File tree

9 files changed

+175
-9
lines changed

9 files changed

+175
-9
lines changed

cli/util.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ var errInvalidTimeFormat = xerrors.New("Start time must be in the format hh:mm[a
1616
var errUnsupportedTimezone = xerrors.New("The location you provided looks like a timezone. Check https://ipinfo.io for your location.")
1717

1818
// durationDisplay formats a duration for easier display:
19-
// * Durations of 24 hours or greater are displays as Xd
20-
// * Durations less than 1 minute are displayed as <1m
21-
// * Duration is truncated to the nearest minute
22-
// * Empty minutes and seconds are truncated
23-
// * The returned string is the absolute value. Use sign()
19+
// - Durations of 24 hours or greater are displays as Xd
20+
// - Durations less than 1 minute are displayed as <1m
21+
// - Duration is truncated to the nearest minute
22+
// - Empty minutes and seconds are truncated
23+
// - The returned string is the absolute value. Use sign()
2424
// if you need to indicate if the duration is positive or
2525
// negative.
2626
func durationDisplay(d time.Duration) string {
@@ -114,7 +114,7 @@ func parseCLISchedule(parts ...string) (*schedule.Schedule, error) {
114114
if loc == nil {
115115
loc, err = tz.TimezoneIANA()
116116
if err != nil {
117-
return nil, xerrors.Errorf("Could not automatically determine your timezone")
117+
loc = time.UTC
118118
}
119119
}
120120

coderd/util/tz/tz_linux.go

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ func TimezoneIANA() (*time.Location, error) {
3333
if err != nil {
3434
return nil, xerrors.Errorf("read location of %s: %w", etcLocaltime, err)
3535
}
36-
3736
stripped := strings.Replace(lp, zoneInfoPath, "", -1)
3837
stripped = strings.TrimPrefix(stripped, string(filepath.Separator))
3938
loc, err = time.LoadLocation(stripped)

coderd/util/tz/tz_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package tz_test
22

33
import (
44
"os"
5+
"runtime"
56
"testing"
67

78
"github.com/stretchr/testify/assert"
@@ -25,6 +26,11 @@ func Test_TimezoneIANA(t *testing.T) {
2526

2627
//nolint:paralleltest // UnsetEnv
2728
t.Run("NoEnv", func(t *testing.T) {
29+
_, err := os.Stat("/etc/localtime")
30+
if runtime.GOOS == "linux" && err != nil {
31+
// Not all Linux operating systems are guaranteed to have localtime!
32+
t.Skip("localtime doesn't exist!")
33+
}
2834
oldEnv, found := os.LookupEnv("TZ")
2935
if found {
3036
require.NoError(t, os.Unsetenv("TZ"))

docs/CONTRIBUTING.md

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
Coder requires Go 1.18+, Node 14+, and GNU Make.
66

7+
> **Note**:
8+
> Use [Nix](https://nix.dev/) for a one-command setup: `nix-shell`
9+
710
### Development workflow
811

912
Use the following `make` commands and scripts in development:

flake.lock

+94
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
description = "Development environments on your infrastructure";
3+
4+
inputs = {
5+
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
6+
flake-utils.url = "github:numtide/flake-utils";
7+
drpc.url = "github:storj/drpc/v0.0.32";
8+
};
9+
10+
outputs = { self, nixpkgs, flake-utils, drpc }:
11+
flake-utils.lib.eachDefaultSystem (system:
12+
let
13+
pkgs = nixpkgs.legacyPackages.${system};
14+
in
15+
{
16+
formatter = pkgs.nixpkgs-fmt;
17+
devShells.default = pkgs.mkShell {
18+
buildInputs = with pkgs; [
19+
bat
20+
drpc.defaultPackage.${system}
21+
exa
22+
git
23+
go-migrate
24+
go_1_19
25+
golangci-lint
26+
gopls
27+
gotestsum
28+
helm
29+
jq
30+
nfpm
31+
nodePackages.typescript
32+
nodePackages.typescript-language-server
33+
nodejs
34+
openssh
35+
openssl
36+
postgresql
37+
protoc-gen-go
38+
ripgrep
39+
shellcheck
40+
shfmt
41+
sqlc
42+
terraform
43+
typos
44+
yarn
45+
zip
46+
zstd
47+
];
48+
};
49+
}
50+
);
51+
}

provisionersdk/agent_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ func TestAgentScript(t *testing.T) {
4646
}
4747
script = strings.ReplaceAll(script, "${ACCESS_URL}", srvURL.String()+"/")
4848
script = strings.ReplaceAll(script, "${AUTH_TYPE}", "token")
49+
// In certain distributions "echo" is a part of coreutils, and determines
50+
// it's functionality based on the exec path name.
51+
script = strings.ReplaceAll(script, "BINARY_NAME=coder", "BINARY_NAME=echo")
4952
// This is intentionally ran in single quotes to mimic how a customer may
5053
// embed our script. Our scripts should not include any single quotes.
5154
// nolint:gosec

scripts/build_go_slim.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ done
5858
# Check dependencies
5959
dependencies go
6060
if [[ $compress != 0 ]]; then
61-
dependencies shasum tar zstd
61+
dependencies openssl tar zstd
6262

6363
if [[ $compress != [0-9]* ]] || [[ $compress -gt 22 ]] || [[ $compress -lt 1 ]]; then
6464
error "Invalid value for compress, must in in the range of [1, 22]"
@@ -114,7 +114,7 @@ if [[ $compress != 0 ]]; then
114114
sha_file=coder.sha1
115115
sha_dest="$dest_dir/$sha_file"
116116
log "--- Generating SHA1 for coder-slim binaries ($sha_dest)"
117-
shasum -b -a 1 coder-* | tee $sha_file
117+
openssl dgst -r -sha1 coder-* | tee $sha_file
118118
echo "$sha_dest"
119119
log
120120
log

shell.nix

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(import
2+
(
3+
fetchTarball {
4+
url = "https://github.com/edolstra/flake-compat/archive/b4a34015c698c7793d592d66adbab377907a2be8.tar.gz";
5+
sha256 = "1qc703yg0babixi6wshn5wm2kgl5y1drcswgszh4xxzbrwkk9sv7";
6+
}
7+
)
8+
{
9+
src = ./.;
10+
}).shellNix

0 commit comments

Comments
 (0)