summaryrefslogtreecommitdiff
path: root/flake.nix
diff options
context:
space:
mode:
authorseth <[email protected]>2024-02-12 20:29:15 -0500
committerseth <[email protected]>2024-02-13 00:24:08 -0500
commit2cbc22348ef038181e1dc89635a3be005604a4ca (patch)
tree33a33ffe0203b730078d01c5d7d3951239619ca9 /flake.nix
parent05780c6b2d8b184122a32095c50363a6c8617d64 (diff)
back to astro
Diffstat (limited to 'flake.nix')
-rw-r--r--flake.nix210
1 files changed, 69 insertions, 141 deletions
diff --git a/flake.nix b/flake.nix
index d2925f5..dedf2f6 100644
--- a/flake.nix
+++ b/flake.nix
@@ -1,150 +1,78 @@
{
- description = "getchoo's website";
+ description = "seth's website";
inputs = {
- nixpkgs.url = "nixpkgs/nixpkgs-unstable";
- nix-deno = {
- url = "github:nekowinston/nix-deno";
- inputs.nixpkgs.follows = "nixpkgs";
- };
- };
-
- outputs = {
- nixpkgs,
- nix-deno,
- self,
- ...
- }: let
- systems = [
- "x86_64-linux"
- "aarch64-linux"
- "x86_64-darwin"
- "aarch64-darwin"
- ];
-
- forSystem = system: fn:
- fn rec {
- pkgs = import nixpkgs {
- inherit system;
- overlays = [nix-deno.overlays.default];
- };
-
- inherit (pkgs) lib;
- self' = lib.mapAttrs (_: v: v.${system} or {}) self;
- };
-
- forAllSystems = fn: nixpkgs.lib.genAttrs systems (system: forSystem system fn);
- in {
- checks = forAllSystems ({
- lib,
- pkgs,
- self',
- ...
- }: {
- check-nil =
- pkgs.runCommand "check-nil" {
- nativeBuildInputs = with pkgs; [fd nil];
- } ''
- cd ${./.}
- fd . -e "nix" | while read -r file; do
- nil diagnostics "$file" || exit 1
- done
-
- touch $out
- '';
-
- "check-${self'.formatter.pname}" = pkgs.runCommand "check-${self'.formatter.pname}" {} ''
- ${lib.getExe self'.formatter} --check ${./.}
-
- touch $out
- '';
-
- check-statix =
- pkgs.runCommand "check-statix" {
- nativeBuildInputs = [pkgs.statix];
- } ''
- statix check ${./.}
-
- touch $out
- '';
-
- check-actionlint =
- pkgs.runCommand "check-actionlint" {
- nativeBuildInputs = [pkgs.actionlint];
- } ''
- actionlint ${./.github/workflows}/**
-
- touch $out
- '';
-
- check-denofmt =
- pkgs.runCommand "check-denofmt" {
- nativeBuildInputs = [pkgs.deno];
- } ''
- cd ${./.}
- export DENO_DIR="$(mktemp -d)"
- deno fmt --check
-
- touch $out
- '';
+ nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
- check-denolint =
- pkgs.runCommand "check-denolint" {
- nativeBuildInputs = [pkgs.deno];
- } ''
- cd ${./.}
- export DENO_DIR="$(mktemp -d)"
- deno lint
-
- touch $out
- '';
- });
-
- devShells = forAllSystems ({
- pkgs,
- self',
- ...
- }: {
- default = pkgs.mkShellNoCC {
- packages = with pkgs; [
- deno
- actionlint
-
- self'.formatter
- nil
- statix
- ];
- };
- });
-
- formatter = forAllSystems ({pkgs, ...}: pkgs.alejandra);
-
- packages = forAllSystems ({
- lib,
- pkgs,
- self',
- ...
- }: {
- website = pkgs.denoPlatform.mkDenoDerivation {
- name = "website";
- stdenv = pkgs.stdenvNoCC;
-
- src = lib.cleanSource ./.;
-
- buildPhase = ''
- runHook preBuild
-
- deno task build
+ flake-parts = {
+ url = "github:hercules-ci/flake-parts";
+ inputs.nixpkgs-lib.follows = "nixpkgs";
+ };
- runHook postBuild
- '';
+ treefmt-nix = {
+ url = "github:numtide/treefmt-nix";
+ inputs.nixpkgs.follows = "nixpkgs";
+ };
- installPhase = ''
- cp -r _site $out
- '';
+ pre-commit = {
+ url = "github:cachix/pre-commit-hooks.nix";
+ inputs = {
+ nixpkgs.follows = "nixpkgs";
+ nixpkgs-stable.follows = "nixpkgs";
+ flake-compat.follows = "";
};
-
- default = self'.packages.website;
- });
+ };
};
+
+ outputs = inputs:
+ inputs.flake-parts.lib.mkFlake { inherit inputs; } {
+ imports = with inputs; [ treefmt-nix.flakeModule pre-commit.flakeModule ];
+
+ systems =
+ [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
+
+ perSystem = { lib, pkgs, config, self', ... }:
+ let
+ nodejs-slim = pkgs.nodejs-slim_20; # this should be the current lts
+
+ enableAll = lib.flip lib.genAttrs (lib.const { enable = true; });
+ in {
+ treefmt = {
+ projectRootFile = ".git/config";
+
+ programs = enableAll [ "deadnix" "nixfmt" "prettier" ];
+
+ settings.global = {
+ excludes = [ "./node_modules/*" "flake.lock" "pnpm-lock.yaml" ];
+ };
+ };
+
+ pre-commit = {
+ settings.hooks = enableAll [
+ "actionlint"
+ "eclint"
+ "eslint"
+ "markdownlint"
+ "nil"
+ "statix"
+ "treefmt"
+ ];
+ };
+
+ devShells.default = pkgs.mkShellNoCC {
+ shellHook = config.pre-commit.installationScript;
+ packages = [
+ self'.formatter
+ nodejs-slim
+ # use pnpm from package.json
+ (pkgs.runCommand "corepack-enable" {
+ nativeBuildInputs = [ nodejs-slim ];
+ } ''
+ mkdir -p $out/bin
+ corepack enable --install-directory $out/bin
+ '')
+ ];
+ };
+ };
+ };
}