Skip to content

Commit facf6ca

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 facf6ca

File tree

8 files changed

+157
-10
lines changed

8 files changed

+157
-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: 79 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: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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.nixpkgs.follows = "nixpkgs-unstable";
10+
};
11+
};
12+
13+
outputs = { self, nixpkgs-unstable, flake-utils, drpc }:
14+
flake-utils.lib.eachDefaultSystem (system:
15+
with nixpkgs-unstable.legacyPackages.${system}; rec {
16+
devShell =
17+
let devtools = {};
18+
in mkShell {
19+
buildInputs = [
20+
drpc.defaultPackage.${system}
21+
];
22+
nativeBuildInputs = [
23+
go_1_19
24+
gopls
25+
nodejs
26+
ripgrep
27+
exa
28+
bat
29+
typos
30+
git
31+
nfpm
32+
openssl
33+
protoc-gen-go
34+
go-migrate
35+
gotestsum
36+
goreleaser
37+
sqlc
38+
shfmt
39+
terraform
40+
shellcheck
41+
golangci-lint
42+
yarn
43+
postgresql
44+
helm
45+
jq
46+
zstd
47+
zip
48+
openssh
49+
nodePackages.typescript
50+
nodePackages.typescript-language-server
51+
];
52+
};
53+
});
54+
}

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)