feat(nix): build UTRP (#714)
* feat(nix): build UTRP * feat(nix): set fixed rev and sha256 + update lock file * chore(nix): remove systems input * chore: format * chore(nix): add meta attribute * feat(nix): add doprz as a maintainer
This commit is contained in:
7
.gitignore
vendored
7
.gitignore
vendored
@@ -212,4 +212,9 @@ package-lock.json
|
|||||||
storybook-static/
|
storybook-static/
|
||||||
package/
|
package/
|
||||||
|
|
||||||
.direnv/
|
# Nix
|
||||||
|
result
|
||||||
|
result-*
|
||||||
|
|
||||||
|
# direnv
|
||||||
|
.direnv
|
||||||
|
|||||||
10
default.nix
Normal file
10
default.nix
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
(import (
|
||||||
|
let
|
||||||
|
rev = "v1.1.0";
|
||||||
|
sha256 = "sha256:19d2z6xsvpxm184m41qrpi1bplilwipgnzv9jy17fgw421785q1m";
|
||||||
|
in
|
||||||
|
fetchTarball {
|
||||||
|
inherit sha256;
|
||||||
|
url = "https://github.com/NixOS/flake-compat/archive/${rev}.tar.gz";
|
||||||
|
}
|
||||||
|
) { src = ./.; }).defaultNix
|
||||||
31
flake.lock
generated
31
flake.lock
generated
@@ -1,19 +1,5 @@
|
|||||||
{
|
{
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"flake-compat": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1733328505,
|
|
||||||
"narHash": "sha256-NeCCThCEP3eCl2l/+27kNNK7QrwZB1IJCrXfrbv5oqU=",
|
|
||||||
"rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec",
|
|
||||||
"revCount": 69,
|
|
||||||
"type": "tarball",
|
|
||||||
"url": "https://api.flakehub.com/f/pinned/edolstra/flake-compat/1.1.0/01948eb7-9cba-704f-bbf3-3fa956735b52/source.tar.gz"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"type": "tarball",
|
|
||||||
"url": "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"flake-parts": {
|
"flake-parts": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs-lib": "nixpkgs-lib"
|
"nixpkgs-lib": "nixpkgs-lib"
|
||||||
@@ -81,28 +67,11 @@
|
|||||||
},
|
},
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"flake-compat": "flake-compat",
|
|
||||||
"flake-parts": "flake-parts",
|
"flake-parts": "flake-parts",
|
||||||
"nixpkgs": "nixpkgs",
|
"nixpkgs": "nixpkgs",
|
||||||
"systems": "systems",
|
|
||||||
"treefmt-nix": "treefmt-nix"
|
"treefmt-nix": "treefmt-nix"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"systems": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1681028828,
|
|
||||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
|
||||||
"owner": "nix-systems",
|
|
||||||
"repo": "default",
|
|
||||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "nix-systems",
|
|
||||||
"repo": "default",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"treefmt-nix": {
|
"treefmt-nix": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs": "nixpkgs_2"
|
"nixpkgs": "nixpkgs_2"
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
{
|
{
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
systems.url = "github:nix-systems/default";
|
|
||||||
flake-parts.url = "github:hercules-ci/flake-parts";
|
flake-parts.url = "github:hercules-ci/flake-parts";
|
||||||
flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";
|
|
||||||
treefmt-nix.url = "github:numtide/treefmt-nix";
|
treefmt-nix.url = "github:numtide/treefmt-nix";
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs =
|
outputs =
|
||||||
inputs@{ flake-parts, systems, ... }:
|
inputs@{ flake-parts, ... }:
|
||||||
flake-parts.lib.mkFlake { inherit inputs; } {
|
flake-parts.lib.mkFlake { inherit inputs; } {
|
||||||
systems = import systems;
|
systems = inputs.nixpkgs.lib.systems.flakeExposed;
|
||||||
|
|
||||||
imports = [
|
imports = [
|
||||||
|
./nix/packages.nix
|
||||||
./nix/devShells.nix
|
./nix/devShells.nix
|
||||||
./nix/treefmt.nix
|
./nix/treefmt.nix
|
||||||
];
|
];
|
||||||
|
|||||||
51
nix/package.nix
Normal file
51
nix/package.nix
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
{
|
||||||
|
stdenv,
|
||||||
|
lib,
|
||||||
|
nodejs,
|
||||||
|
pnpm_10,
|
||||||
|
git,
|
||||||
|
version ? "dev",
|
||||||
|
gitRev ? "unknown",
|
||||||
|
gitBranch ? "unknown",
|
||||||
|
buildScript ? "build",
|
||||||
|
}:
|
||||||
|
|
||||||
|
stdenv.mkDerivation (finalAttrs: {
|
||||||
|
inherit version;
|
||||||
|
pname = "ut-registration-plus";
|
||||||
|
|
||||||
|
src = ../.;
|
||||||
|
|
||||||
|
nativeBuildInputs = [
|
||||||
|
nodejs
|
||||||
|
pnpm_10.configHook
|
||||||
|
git
|
||||||
|
];
|
||||||
|
|
||||||
|
pnpmDeps = pnpm_10.fetchDeps {
|
||||||
|
inherit (finalAttrs) pname version src;
|
||||||
|
fetcherVersion = 2;
|
||||||
|
hash = "sha256-UqHymJWvlTV4glra/6DkxuCxbG5dpPkFcnvq3vuxsJ8=";
|
||||||
|
};
|
||||||
|
|
||||||
|
# Pass git info to the build
|
||||||
|
VITE_GIT_COMMIT = gitRev;
|
||||||
|
VITE_GIT_BRANCH = gitBranch;
|
||||||
|
|
||||||
|
buildPhase = ''
|
||||||
|
pnpm run ${buildScript}
|
||||||
|
'';
|
||||||
|
|
||||||
|
installPhase = ''
|
||||||
|
mkdir -p $out
|
||||||
|
cp -r dist/* $out/
|
||||||
|
'';
|
||||||
|
|
||||||
|
meta = {
|
||||||
|
description = "UT Registration Plus";
|
||||||
|
homepage = "https://github.com/Longhorn-Developers/UT-Registration-Plus";
|
||||||
|
license = lib.licenses.mit;
|
||||||
|
maintainers = lib.maintainers.doprz;
|
||||||
|
platforms = lib.platforms.unix;
|
||||||
|
};
|
||||||
|
})
|
||||||
40
nix/packages.nix
Normal file
40
nix/packages.nix
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
{ inputs, ... }:
|
||||||
|
{
|
||||||
|
perSystem =
|
||||||
|
{ pkgs, ... }:
|
||||||
|
let
|
||||||
|
packageJson = builtins.fromJSON (builtins.readFile ../package.json);
|
||||||
|
gitRev = inputs.self.shortRev or inputs.self.dirtyShortRev or "dev";
|
||||||
|
gitBranch = if inputs.self ? ref then inputs.self.ref else "unknown";
|
||||||
|
baseVersion = packageJson.version;
|
||||||
|
|
||||||
|
commonArgs = {
|
||||||
|
inherit gitRev gitBranch;
|
||||||
|
};
|
||||||
|
|
||||||
|
# Prod variant
|
||||||
|
ut-registration-plus = pkgs.callPackage ./package.nix (
|
||||||
|
commonArgs
|
||||||
|
// {
|
||||||
|
version = "${baseVersion}+git.${gitRev}";
|
||||||
|
buildScript = "build";
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
# Dev variant
|
||||||
|
ut-registration-plus-dev = pkgs.callPackage ./package.nix (
|
||||||
|
commonArgs
|
||||||
|
// {
|
||||||
|
version = "${baseVersion}-dev+git.${gitRev}";
|
||||||
|
buildScript = "build:dev";
|
||||||
|
}
|
||||||
|
);
|
||||||
|
in
|
||||||
|
{
|
||||||
|
packages = {
|
||||||
|
inherit ut-registration-plus ut-registration-plus-dev;
|
||||||
|
default = ut-registration-plus;
|
||||||
|
dev = ut-registration-plus-dev;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
10
shell.nix
10
shell.nix
@@ -1,12 +1,10 @@
|
|||||||
(import (
|
(import (
|
||||||
let
|
let
|
||||||
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
|
rev = "v1.1.0";
|
||||||
nodeName = lock.nodes.root.inputs.flake-compat;
|
sha256 = "sha256:19d2z6xsvpxm184m41qrpi1bplilwipgnzv9jy17fgw421785q1m";
|
||||||
in
|
in
|
||||||
fetchTarball {
|
fetchTarball {
|
||||||
url =
|
inherit sha256;
|
||||||
lock.nodes.${nodeName}.locked.url
|
url = "https://github.com/NixOS/flake-compat/archive/${rev}.tar.gz";
|
||||||
or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.${nodeName}.locked.rev}.tar.gz";
|
|
||||||
sha256 = lock.nodes.${nodeName}.locked.narHash;
|
|
||||||
}
|
}
|
||||||
) { src = ./.; }).shellNix
|
) { src = ./.; }).shellNix
|
||||||
|
|||||||
@@ -88,6 +88,31 @@ const fixManifestOptionsPage = (): Plugin => ({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function getGitInfo() {
|
||||||
|
// Try environment variables first (for Nix builds)
|
||||||
|
if (process.env.VITE_GIT_BRANCH && process.env.VITE_GIT_COMMIT) {
|
||||||
|
return {
|
||||||
|
gitBranch: process.env.VITE_GIT_BRANCH,
|
||||||
|
gitCommit: process.env.VITE_GIT_COMMIT,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fall back to git commands (for local development)
|
||||||
|
try {
|
||||||
|
return {
|
||||||
|
gitBranch: execSync('git rev-parse --abbrev-ref HEAD').toString().trim(),
|
||||||
|
gitCommit: execSync('git rev-parse --short HEAD').toString().trim(),
|
||||||
|
};
|
||||||
|
} catch {
|
||||||
|
return {
|
||||||
|
gitBranch: 'unknown',
|
||||||
|
gitCommit: 'unknown',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const gitInfo = getGitInfo();
|
||||||
|
|
||||||
let config: ResolvedConfig;
|
let config: ResolvedConfig;
|
||||||
let server: ViteDevServer;
|
let server: ViteDevServer;
|
||||||
|
|
||||||
@@ -180,12 +205,14 @@ export default defineConfig({
|
|||||||
'PROD',
|
'PROD',
|
||||||
'VITE_SENTRY_ENVIRONMENT',
|
'VITE_SENTRY_ENVIRONMENT',
|
||||||
'VITE_BETA_BUILD',
|
'VITE_BETA_BUILD',
|
||||||
|
'VITE_GIT_BRANCH',
|
||||||
|
'VITE_GIT_COMMIT',
|
||||||
],
|
],
|
||||||
includeTimestamp: true,
|
includeTimestamp: true,
|
||||||
includeBuildTime: true,
|
includeBuildTime: true,
|
||||||
customMetadata: {
|
customMetadata: {
|
||||||
gitBranch: () => execSync('git rev-parse --abbrev-ref HEAD').toString().trim(),
|
gitBranch: () => gitInfo.gitBranch,
|
||||||
gitCommit: () => execSync('git rev-parse --short HEAD').toString().trim(),
|
gitCommit: () => gitInfo.gitCommit,
|
||||||
nodeVersion: () => process.version,
|
nodeVersion: () => process.version,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in New Issue
Block a user