Skip to content

Commit 7a7c272

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 7a7c272

File tree

8 files changed

+153
-10
lines changed

8 files changed

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

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)