mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-20 09:01:17 -08:00
this nix flake is heavily based off of prior work i have done in one of my repos. it comes with the following features: - building sable: `nix build .#sable` or just `nix build`. creates a `result/` dir with the built application. - devshell: nix users now no longer need to do download and install all the dependencies for sable by themselves. the devshell comes with all the dependencies needed to develop sable - checks: `nix flake check` is configured to perform all checks listed in `CONTRIBUTING.md` (fmt:check, lint, typecheck, knip, test:run) - formatting: `nix fmt` runs all the formatters pnpm would also call, but provides a more familiar interface for nix users. - pre-commit checks: nix users can benefit from having their changes checked for before the commit goes through. yay :3 `.vscode/settings.json` was updated to include hints for VS Code users using the "nix env selector" extension to auto-detect the nix dev environment, if you have nix installed. I had to change `oxfmt.config.ts` just a tiny bit to make it work with the nix stuff, because `node_modules` does not exist inside the nix build sandbox. `pnpm fmt` successfully runs, so nothing should have broken. `flake-lock-fix.yml` is a small workflow heavily based on <https://docs.determinate.systems/guides/fix-hashes/>, which triggers on pushes to `dev` which change `pnpm-lock.yaml`. The workflow uses `determinate-nixd` to fix hashes in the `flake.nix`, then pushes the changes to `dev` automatically.
182 lines
4.7 KiB
Nix
182 lines
4.7 KiB
Nix
# SPDX-License-Identifier: AGPL-3.0
|
|
{
|
|
inputs = {
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
|
flake-parts.url = "github:hercules-ci/flake-parts";
|
|
git-hooks.url = "github:cachix/git-hooks.nix";
|
|
git-hooks.inputs.nixpkgs.follows = "nixpkgs";
|
|
treefmt-nix.url = "github:numtide/treefmt-nix";
|
|
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
|
|
outputs =
|
|
inputs@{ flake-parts, ... }:
|
|
flake-parts.lib.mkFlake { inherit inputs; } {
|
|
imports = [
|
|
inputs.git-hooks.flakeModule
|
|
inputs.treefmt-nix.flakeModule
|
|
];
|
|
|
|
systems = [
|
|
"x86_64-linux"
|
|
"aarch64-linux"
|
|
"x86_64-darwin"
|
|
"aarch64-darwin"
|
|
];
|
|
|
|
perSystem =
|
|
{
|
|
config,
|
|
pkgs,
|
|
lib,
|
|
...
|
|
}:
|
|
let
|
|
self = inputs.self;
|
|
|
|
packageJson = builtins.fromJSON (builtins.readFile ./package.json);
|
|
|
|
nodejs = pkgs.nodejs_24;
|
|
pnpm = pkgs.pnpm_10;
|
|
pnpmConfigHook = pkgs.pnpmConfigHook.override { inherit pnpm; };
|
|
|
|
pnpmNativeBuildInputs = [
|
|
nodejs
|
|
pnpm
|
|
pnpmConfigHook
|
|
];
|
|
|
|
mkPnpmDeps =
|
|
{
|
|
src,
|
|
version,
|
|
pnpmInstallFlags,
|
|
}:
|
|
pkgs.fetchPnpmDeps {
|
|
inherit
|
|
pnpm
|
|
src
|
|
version
|
|
pnpmInstallFlags
|
|
;
|
|
pname = "sable";
|
|
fetcherVersion = 3;
|
|
hash = "sha256-9QIBOF1d7Z086IsOAHpOayKA3uNY0e5imYQixHKFXxw=";
|
|
};
|
|
|
|
mkPnpmCheck =
|
|
name: script:
|
|
pkgs.stdenv.mkDerivation (finalAttrs: {
|
|
pname = "sable-${name}";
|
|
inherit (packageJson) version;
|
|
src = lib.cleanSource ./.;
|
|
|
|
pnpmInstallFlags = [ "--ignore-scripts" ];
|
|
|
|
pnpmDeps = mkPnpmDeps {
|
|
inherit (finalAttrs) src version pnpmInstallFlags;
|
|
};
|
|
|
|
nativeBuildInputs = pnpmNativeBuildInputs;
|
|
|
|
buildPhase = ''
|
|
runHook preBuild
|
|
pnpm run ${script}
|
|
runHook postBuild
|
|
'';
|
|
|
|
installPhase = ''
|
|
runHook preInstall
|
|
touch $out
|
|
runHook postInstall
|
|
'';
|
|
|
|
doCheck = false;
|
|
});
|
|
in
|
|
{
|
|
treefmt = {
|
|
projectRootFile = "flake.nix";
|
|
programs = {
|
|
nixfmt.enable = true;
|
|
oxfmt.enable = true;
|
|
};
|
|
settings.global.excludes = [
|
|
"dist"
|
|
"node_modules"
|
|
"pnpm-lock.yaml"
|
|
"pnpm-workspace.yaml"
|
|
"package.json"
|
|
"LICENSE"
|
|
"CHANGELOG.md"
|
|
"./changeset"
|
|
];
|
|
};
|
|
pre-commit.settings.hooks = {
|
|
treefmt = {
|
|
enable = true;
|
|
package = config.treefmt.build.wrapper;
|
|
};
|
|
};
|
|
|
|
packages.sable = pkgs.stdenv.mkDerivation (finalAttrs: {
|
|
pname = "sable";
|
|
inherit (packageJson) version;
|
|
src = lib.cleanSource ./.;
|
|
|
|
# ignoring knope for building
|
|
pnpmInstallFlags = [ "--ignore-scripts" ];
|
|
|
|
pnpmDeps = mkPnpmDeps {
|
|
inherit (finalAttrs) src version pnpmInstallFlags;
|
|
};
|
|
|
|
nativeBuildInputs = pnpmNativeBuildInputs;
|
|
|
|
env.VITE_BUILD_HASH = self.shortRev or self.dirtyShortRev or "";
|
|
env.VITE_IS_RELEASE_TAG = "false";
|
|
|
|
buildPhase = ''
|
|
runHook preBuild
|
|
pnpm run build
|
|
runHook postBuild
|
|
'';
|
|
|
|
installPhase = ''
|
|
runHook preInstall
|
|
cp -r dist $out
|
|
runHook postInstall
|
|
'';
|
|
});
|
|
|
|
packages.default = config.packages.sable;
|
|
|
|
checks = {
|
|
build = config.packages.sable;
|
|
lint = mkPnpmCheck "lint" "lint";
|
|
fmt = mkPnpmCheck "fmt" "fmt:check";
|
|
test = mkPnpmCheck "test" "test:run";
|
|
typecheck = mkPnpmCheck "typecheck" "typecheck";
|
|
knip = mkPnpmCheck "knip" "knip";
|
|
};
|
|
|
|
devShells.default = pkgs.mkShell {
|
|
packages = [
|
|
nodejs
|
|
pnpm
|
|
pkgs.corepack
|
|
pkgs.vitejs
|
|
pkgs.oxlint
|
|
pkgs.oxfmt
|
|
pkgs.knope
|
|
pkgs.typescript
|
|
pkgs.typescript-language-server
|
|
pkgs.nil
|
|
pkgs.nixd
|
|
];
|
|
shellHook = config.pre-commit.installationScript;
|
|
};
|
|
};
|
|
};
|
|
}
|