Skip to content

Commit

Permalink
feat: add nix flake and .devcontainer.json (#594)
Browse files Browse the repository at this point in the history
Co-authored-by: Kalle Ahlström <[email protected]>
Co-authored-by: Mikael Siidorow <[email protected]>
  • Loading branch information
3 people authored Jan 15, 2025
1 parent a364758 commit 06696a6
Show file tree
Hide file tree
Showing 7 changed files with 557 additions and 72 deletions.
48 changes: 48 additions & 0 deletions .devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"customizations": {
"vscode": {
"extensions": [
"mkhl.direnv",
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint",
"bradlc.vscode-tailwindcss",
"yoavbls.pretty-ts-errors",
"github.vscode-github-actions",
"ms-vscode.vscode-typescript-next"
],
"settings": {
"editor.tabSize": 2,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.fixAll.eslint": "explicit",
"source.fixAll.stylelint": "explicit"
},
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact"
],
"eslint.runtime": "node_modules/.bin/eslint",
"typescript.tsdk": "node_modules/typescript/lib",
"eslint.workingDirectories": [
{
"mode": "auto"
}
],
"tailwindCSS.experimental.classRegex": [
["cva\\(([^)]*)\\)", "[\"'`]([^\"'`]*).*?[\"'`]"]
]
}
}
},
"image": "ghcr.io/cachix/devenv:latest",
"overrideCommand": false,
"updateContentCommand": "direnv reload",
"remoteEnv": { "LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}" },
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
}
}
10 changes: 10 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
if ! has nix_direnv_version || ! nix_direnv_version 2.2.1; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.1/direnvrc" "sha256-zelF0vLbEl5uaqrfIzbgNzJWGmLzCmYAkInj/LNxvKs="
fi

watch_file flake.nix
watch_file flake.lock
if ! use flake . --no-pure-eval --accept-flake-config
then
echo "devenv could not be built. The devenv environment was not loaded. Make the necessary changes to devenv.nix and hit enter to try again." >&2
fi
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ public/dist
!.vscode/extensions.json
.idea
/payload.config.ts
.devenv
.direnv
.pnpm-store
265 changes: 265 additions & 0 deletions flake.lock

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

65 changes: 65 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
inputs = {
nixpkgs.url = "github:cachix/devenv-nixpkgs/rolling";
systems.url = "github:nix-systems/default";
devenv.url = "github:cachix/devenv";
devenv.inputs.nixpkgs.follows = "nixpkgs";
};

nixConfig = {
extra-trusted-public-keys = "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw=";
extra-substituters = "https://devenv.cachix.org";
};

outputs = {
self,
nixpkgs,
devenv,
systems,
...
} @ inputs: let
forEachSystem = nixpkgs.lib.genAttrs (import systems);
in {
packages = forEachSystem (system: {
devenv-up = self.devShells.${system}.default.config.procfileScript;
devenv-test = self.devShells.${system}.default.config.test;
});

devShells =
forEachSystem
(system: let
pkgs = nixpkgs.legacyPackages.${system};
bun = pkgs.bun.overrideAttrs (oldAttrs: {
buildInputs = oldAttrs.buildInputs or [] ++ [pkgs.makeWrapper];
postInstall =
oldAttrs.postInstall
or ""
+ ''
wrapProgram $out/bin/bun \
--set LD_LIBRARY_PATH "${pkgs.stdenv.cc.cc.lib}/lib/:$LD_LIBRARY_PATH"
'';
});
in {
default = devenv.lib.mkShell {
inherit inputs pkgs;
modules = [
{
packages = with pkgs; [bash mongodb-tools docker bun];

# FIXME: this is only required within the dev container
enterShell = ''
export PATH="$PATH:/usr/local/bin"
'';

languages.javascript = {
enable = true;
package = pkgs.nodejs-slim_22;
pnpm.enable = true;
pnpm.install.enable = true;
};
}
];
};
});
};
}
Loading

0 comments on commit 06696a6

Please sign in to comment.