Skip to content

Commit

Permalink
chore: switched to devenv.sh for the development environment
Browse files Browse the repository at this point in the history
  • Loading branch information
iivvaannxx committed Aug 24, 2024
1 parent b82885b commit 3f65726
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 39 deletions.
12 changes: 12 additions & 0 deletions .devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"customizations": {
"vscode": {
"extensions": [
"mkhl.direnv"
]
}
},
"image": "ghcr.io/cachix/devenv:latest",
"overrideCommand": false,
"updateContentCommand": "devenv test"
}
11 changes: 11 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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

nix_direnv_watch_file flake.nix
nix_direnv_watch_file flake.lock

if ! use flake . --impure --override-input devenv-root "file+file://"<(printf %s "$PWD")
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ pnpm-debug.log*

.wrangler/
.dev.vars

.devenv/
.direnv/
.pre-commit-config.yaml
33 changes: 33 additions & 0 deletions devenv.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
config,
pkgs,
devenv-root,
...
} @ args: {
shells.default = {
name = "portfolio";
packages = with pkgs; [
git
wrangler
];

# Generates a .devcontainer configuration file.
devcontainer.enable = true;
env = {};

# TypeScript for better DX
languages.typescript.enable = true;
languages.javascript = {
enable = true;
pnpm.enable = true;
bun.enable = true;
};

# + Linting and formatting hooks.
pre-commit.hooks.alejandra.enable = true;
devenv.root = let
devenvRootFileContent = builtins.readFile devenv-root.outPath;
in
pkgs.lib.mkIf (devenvRootFileContent != "") devenvRootFileContent;
};
}
81 changes: 42 additions & 39 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,49 +1,52 @@
{
inputs = {

flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};

outputs = { self, nixpkgs, flake-utils }: let

inherit (flake-utils.lib) eachDefaultSystem;
mkFlake = system: let

# The set of packages to be used.
pkgs = import nixpkgs {
inherit system;
config.allowUnfree = true;
outputs = inputs @ {
flake-parts,
devenv-root,
nixpkgs,
...
}:
flake-parts.lib.mkFlake {inherit inputs;} {
imports = [
inputs.devenv.flakeModule
];

systems = ["x86_64-linux" "i686-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"];
perSystem = {
config,
self',
inputs',
pkgs,
system,
...
} @ args: {
devenv = import ./devenv.nix (args // {inherit devenv-root;});
};

env-name = "portfolio";
fhsEnv = pkgs.buildFHSUserEnv {

name = "${env-name}";
targetPkgs = pkgs: [

pkgs.nodejs-slim
pkgs.nodePackages_latest.pnpm

pkgs.git
pkgs.openssh
pkgs.bun
pkgs.wrangler
];
flake = {
# See: https://nix.dev/manual/nix/2.22/command-ref/new-cli/nix3-fmt
formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.alejandra;
};
};

in {
inputs = {
devenv-root = {
url = "file+file:///dev/null";
flake = false;
};

devShells.default = pkgs.mkShell {
nixpkgs.url = "github:cachix/devenv-nixpkgs/rolling";
devenv.url = "github:cachix/devenv";

# The packages used within the project.
buildInputs = [ fhsEnv ];
shellHook = ''
nix2container.url = "github:nlewo/nix2container";
nix2container.inputs.nixpkgs.follows = "nixpkgs";
mk-shell-bin.url = "github:rrbutani/nix-mk-shell-bin";

exec ${fhsEnv}/bin/${env-name}
'';
};
};
fenix.url = "github:nix-community/fenix";
fenix.inputs = {nixpkgs.follows = "nixpkgs";};
};

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

0 comments on commit 3f65726

Please sign in to comment.