Skip to content

Commit 693f23e

Browse files
committed
chore: Add nix shell for simple development setup
This enables contributors using Nix to set up their environment with ease.
1 parent 1fb274c commit 693f23e

File tree

8 files changed

+147
-10
lines changed

8 files changed

+147
-10
lines changed

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use nix

coderd/util/tz/tz_linux.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ func TimezoneIANA() (*time.Location, error) {
2929
return nil, xerrors.Errorf("lookup timezone from env: %w", err)
3030
}
3131

32-
lp, err := filepath.EvalSymlinks(etcLocaltime)
33-
if err != nil {
34-
return nil, xerrors.Errorf("read location of %s: %w", etcLocaltime, err)
32+
location, err := filepath.EvalSymlinks(etcLocaltime)
33+
if err == nil {
34+
location = strings.Replace(location, zoneInfoPath, "", -1)
35+
location = strings.TrimPrefix(location, string(filepath.Separator))
36+
} else {
37+
location, _ = time.Now().Zone()
3538
}
36-
37-
stripped := strings.Replace(lp, zoneInfoPath, "", -1)
38-
stripped = strings.TrimPrefix(stripped, string(filepath.Separator))
39-
loc, err = time.LoadLocation(stripped)
39+
loc, err = time.LoadLocation(location)
4040
if err != nil {
41-
return nil, xerrors.Errorf("invalid location %q guessed from %s: %w", stripped, lp, err)
41+
return nil, xerrors.Errorf("invalid location %q guessed from %s: %w", location, location, err)
4242
}
4343
return loc, nil
4444
}

docs/CONTRIBUTING.md

Lines changed: 3 additions & 0 deletions
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

Lines changed: 66 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

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

provisionersdk/agent_test.go

Lines changed: 3 additions & 0 deletions
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

Lines changed: 2 additions & 2 deletions
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 zip
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-* | cut -c1-40 | tee $sha_file
118118
echo "$sha_dest"
119119
log
120120
log

shell.nix

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
(import (
2+
fetchTarball {
3+
url = "https://github.com/edolstra/flake-compat/archive/12c64ca55c1014cdc1b16ed5a804aa8576601ff2.tar.gz";
4+
sha256 = "0jm6nzb83wa6ai17ly9fzpqc40wg1viib8klq8lby54agpl213w5"; }
5+
) {
6+
src = ./.;
7+
}).shellNix

0 commit comments

Comments
 (0)