-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: implement development shell in flake.nix
- Loading branch information
Showing
5 changed files
with
172 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
use flake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,6 @@ dist/ | |
coverage/ | ||
.vscode | ||
Session.vim | ||
|
||
.direnv/ | ||
/.pre-commit-config.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,88 @@ | ||
# ============================================================================ # | ||
# | ||
# Educational computer simulator on a mission to "superscalate" the study of | ||
# computer architecture fundamentals. | ||
# | ||
# ---------------------------------------------------------------------------- # | ||
{ | ||
description = "simde"; | ||
description = "Educational computer architecture simulator"; | ||
|
||
inputs = { | ||
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; | ||
flake-utils.url = "github:numtide/flake-utils"; | ||
nixpkgs.url = "github:NixOS/nixpkgs"; | ||
pre-commit-hooks = { | ||
url = "github:cachix/pre-commit-hooks.nix"; | ||
inputs.nixpkgs.follows = "nixpkgs"; | ||
}; | ||
pnpm2nix = { | ||
url = "github:nzbr/pnpm2nix-nzbr"; | ||
inputs.nixpkgs.follows = "nixpkgs"; | ||
}; | ||
inputs.nixpkgs.follows = "nixpkgs"; | ||
}; | ||
}; | ||
|
||
outputs = { self, nixpkgs, flake-utils, pnpm2nix, ... } @ inputs: | ||
flake-utils.lib.eachDefaultSystem (system: | ||
let pkgs = import nixpkgs { inherit system; }; | ||
in with pkgs; rec { | ||
# Development environment | ||
devShell = mkShell { | ||
name = "simde"; | ||
nativeBuildInputs = [ nodejs nodePackages.pnpm ]; | ||
outputs = | ||
{ self | ||
, nixpkgs | ||
, pre-commit-hooks | ||
, pnpm2nix | ||
, ... | ||
}: | ||
let | ||
systems = [ | ||
"x86_64-linux" | ||
"aarch64-linux" | ||
"x86_64-darwin" | ||
"aarch64-darwin" | ||
]; | ||
|
||
# Helper to provide system-specific attributes | ||
forAllSystems = f: | ||
nixpkgs.lib.genAttrs systems (system: | ||
f rec { | ||
pkgs = nixpkgs.legacyPackages.${system}; | ||
commonPackages = builtins.attrValues { | ||
inherit (pkgs) nodejs; | ||
inherit (pkgs.nodePackages) pnpm; | ||
}; | ||
}); | ||
in | ||
{ | ||
pre-commit-check = pre-commit-hooks.run { | ||
src = builtins.path { path = ./.; }; | ||
default_stages = [ "manual" "push" ]; | ||
hooks = { | ||
nixpkgs-fmt.enable = true; | ||
commitizen.enable = true; | ||
biome = { | ||
enable = true; | ||
name = "Biome.js"; | ||
entry = "biome check --apply"; | ||
stages = [ "pre-push" ]; | ||
}; | ||
}; | ||
settings = { | ||
alejandra.verbosity = "quiet"; | ||
}; | ||
}; | ||
|
||
# Build package into dist/ dir with pnpm | ||
dist = pnpm2nix.packages.${system}.mkPnpmPackage { | ||
src = ./.; | ||
# Development environment | ||
devShells = forAllSystems ({ pkgs, commonPackages }: { | ||
inherit (self.pre-commit-check) shellHook; | ||
default = pkgs.mkShell { | ||
packages = with pkgs; [ nixpkgs-fmt biome ] ++ commonPackages; | ||
}; | ||
}); | ||
|
||
# Create SIMDE dist/ + SWS bundle | ||
packages.app = pkgs.writeShellScriptBin "app" '' | ||
${pkgs.static-web-server}/bin/static-web-server --root ${dist}.distDir | ||
''; | ||
# Build package into `dist/` dir from `pnpm-lock.yaml` | ||
buildDist = pnpm2nix.mkPnpmPackage { | ||
src = ./.; | ||
noDevDependencies = true; | ||
}; | ||
|
||
# The default package when a specific package name isn't specified | ||
defaultPackage = packages.app; | ||
} | ||
); | ||
# Create SIMDE `dist/` + `Static-Web-Server` bundle | ||
packages = forAllSystems ({ pkgs, ... }: { | ||
default = pkgs.writeShellScriptBin "default" '' | ||
${pkgs.static-web-server}/bin/static-web-server --root . | ||
''; | ||
}); | ||
}; | ||
} |