Skip to content

Commit

Permalink
chore: implement development shell in flake.nix
Browse files Browse the repository at this point in the history
  • Loading branch information
oxcabe committed Apr 7, 2024
1 parent 2a058bd commit 7bdc453
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 44 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ dist/
coverage/
.vscode
Session.vim

.direnv/
/.pre-commit-config.yaml
7 changes: 2 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
# syntax=docker/dockerfile:1.7

# Nix builder
FROM nixos/nix:latest AS builder
FROM nixos/nix-flakes:latest AS builder

# Copy our source and setup our working dir
COPY . /tmp/build
WORKDIR /tmp/build

# Build our Nix environment
RUN nix \
--extra-experimental-features "nix-command flakes" \
--option filter-syscalls false \
build
RUN nix build

# Copy the Nix store closure into a directory
RUN mkdir /tmp/nix-store-closure
Expand Down
106 changes: 91 additions & 15 deletions flake.lock

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

99 changes: 75 additions & 24 deletions flake.nix
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 .
'';
});
};
}

0 comments on commit 7bdc453

Please sign in to comment.