Skip to content

chore: Add nix shell for simple development setup #3399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
chore: Add nix shell for simple development setup
This enables contributors using Nix to set up their environment with ease.
  • Loading branch information
kylecarbs committed Aug 7, 2022
commit 693f23e08609fc57fef7bd263d9dc576aba02274
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use nix
16 changes: 8 additions & 8 deletions coderd/util/tz/tz_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ func TimezoneIANA() (*time.Location, error) {
return nil, xerrors.Errorf("lookup timezone from env: %w", err)
}

lp, err := filepath.EvalSymlinks(etcLocaltime)
if err != nil {
return nil, xerrors.Errorf("read location of %s: %w", etcLocaltime, err)
location, err := filepath.EvalSymlinks(etcLocaltime)
if err == nil {
location = strings.Replace(location, zoneInfoPath, "", -1)
location = strings.TrimPrefix(location, string(filepath.Separator))
} else {
location, _ = time.Now().Zone()
}

stripped := strings.Replace(lp, zoneInfoPath, "", -1)
stripped = strings.TrimPrefix(stripped, string(filepath.Separator))
loc, err = time.LoadLocation(stripped)
loc, err = time.LoadLocation(location)
if err != nil {
return nil, xerrors.Errorf("invalid location %q guessed from %s: %w", stripped, lp, err)
return nil, xerrors.Errorf("invalid location %q guessed from %s: %w", location, location, err)
}
return loc, nil
}
3 changes: 3 additions & 0 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

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

> **Note**:
> Use [Nix](https://nix.dev/) for a one-command setup: `nix-shell`

### Development workflow

Use the following `make` commands and scripts in development:
Expand Down
66 changes: 66 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 57 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
description = "Development environments on your infrastructure";

inputs = {
nixpkgs-unstable.url = "nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
drpc = {
url = "github:storj/drpc";
inputs = {
nixpkgs.follows = "nixpkgs-unstable";
flake-utils.follows = "flake-utils";
};
};
};

outputs = { self, nixpkgs-unstable, flake-utils, drpc }:
flake-utils.lib.eachDefaultSystem (system:
with nixpkgs-unstable.legacyPackages.${system}; rec {
devShell =
let devtools = {};
in mkShell {
buildInputs = [
drpc.defaultPackage.${system}
];
nativeBuildInputs = [
go_1_19
gopls
nodejs
ripgrep
exa
bat
typos
git
nfpm
openssl
protoc-gen-go
go-migrate
gotestsum
goreleaser
sqlc
shfmt
terraform
shellcheck
golangci-lint
yarn
postgresql
helm
jq
zstd
zip
openssh
nodePackages.typescript
nodePackages.typescript-language-server
];
};
});
}
3 changes: 3 additions & 0 deletions provisionersdk/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ func TestAgentScript(t *testing.T) {
}
script = strings.ReplaceAll(script, "${ACCESS_URL}", srvURL.String()+"/")
script = strings.ReplaceAll(script, "${AUTH_TYPE}", "token")
// In certain distributions "echo" is a part of coreutils, and determines
// it's functionality based on the exec path name.
script = strings.ReplaceAll(script, "BINARY_NAME=coder", "BINARY_NAME=echo")
// This is intentionally ran in single quotes to mimic how a customer may
// embed our script. Our scripts should not include any single quotes.
// nolint:gosec
Expand Down
4 changes: 2 additions & 2 deletions scripts/build_go_slim.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ done
# Check dependencies
dependencies go
if [[ $compress != 0 ]]; then
dependencies shasum tar zstd
dependencies openssl tar zstd zip

if [[ $compress != [0-9]* ]] || [[ $compress -gt 22 ]] || [[ $compress -lt 1 ]]; then
error "Invalid value for compress, must in in the range of [1, 22]"
Expand Down Expand Up @@ -114,7 +114,7 @@ if [[ $compress != 0 ]]; then
sha_file=coder.sha1
sha_dest="$dest_dir/$sha_file"
log "--- Generating SHA1 for coder-slim binaries ($sha_dest)"
shasum -b -a 1 coder-* | tee $sha_file
openssl dgst -r -sha1 coder-* | cut -c1-40 | tee $sha_file
echo "$sha_dest"
log
log
Expand Down
7 changes: 7 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(import (
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/12c64ca55c1014cdc1b16ed5a804aa8576601ff2.tar.gz";
sha256 = "0jm6nzb83wa6ai17ly9fzpqc40wg1viib8klq8lby54agpl213w5"; }
) {
src = ./.;
}).shellNix