nix packaging

Still requires manual addition of modules and tweaking pagefind.
This commit is contained in:
outfoxxed 2024-09-28 02:26:13 -07:00
parent ffdbd0e614
commit a787497feb
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E
5 changed files with 147 additions and 9 deletions

16
.gitignore vendored
View file

@ -1,5 +1,7 @@
# build output
dist/
/result
# generated types
.astro/
@ -13,17 +15,13 @@ yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
# environment variables
.env
.env.production
# macOS-specific files
.DS_Store
# jetbrains setting folder
# IDE folders
.idea/
.vscode/
# direnv
/.envrc
/.direnv/
modules/
modules_old/

82
default.nix Normal file
View file

@ -0,0 +1,82 @@
{
lib,
stdenv,
nix-gitignore,
yarn-berry,
nodejs,
cacert,
}: stdenv.mkDerivation (final: let
nodeModules = stdenv.mkDerivation {
pname = "${final.pname}-node_modules";
version = final.version;
src = final.src;
nativeBuildInputs = [ nodejs yarn-berry cacert ];
configurePhase = ''
mkdir garbage-tooling
cat <<EOF > .yarnrc.yml
enableTelemetry: false
enableInlineBuilds: true
enableProgressBars: false
enableGlobalCache: false
nodeLinker: node-modules
EOF
'';
buildPhase = ''
# build will fail once due to missing nodejs executable
# linking before running this won't work, it will just delete it
HOME=$(pwd)/garbage-tooling yarn install || true
mkdir -p node_modules/node/bin
ln -s ${nodejs}/bin/node node_modules/node/bin/node
HOME=$(pwd)/garbage-tooling yarn install
'';
installPhase = ''
# none of the cache path configs in yarnrc actually do anything
# so we just copy node_modules manually
rm node_modules/node/bin/node # remove dep on nix package for output hash
mv node_modules $out
'';
fixupPhase = "true";
outputHashMode = "recursive";
outputHashAlgo = "sha256";
outputHash = "rKoDjvG5t+aQRrzAz0eTifPtL3zmWAu/emxXWd1ocxM=";
};
in {
pname = "quickshell-web";
version = "0.1.0";
src = nix-gitignore.gitignoreSource [] ./.;
nativeBuildInputs = [ yarn-berry ];
configurePhase = ''
mkdir garbage-tooling
cat <<EOF > .yarnrc.yml
enableInlineBuilds: true
enableProgressBars: false
enableGlobalCache: false
enableNetwork: false
nodeLinker: node-modules
EOF
cp -r ${nodeModules} node_modules
'';
buildPhase = ''
HOME=$(pwd)/garbage-tooling yarn build
'';
installPhase = "mv dist $out";
})

26
flake.lock Normal file
View file

@ -0,0 +1,26 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1727348695,
"narHash": "sha256-J+PeFKSDV+pHL7ukkfpVzCOO7mBSrrpJ3svwBFABbhI=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "1925c603f17fc89f4c8f6bf6f631a802ad85d784",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "nixos-unstable",
"type": "indirect"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

16
flake.nix Normal file
View file

@ -0,0 +1,16 @@
{
inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs }: let
forEachSystem = fn: nixpkgs.lib.genAttrs
[ "x86_64-linux" "aarch64-linux" ]
(system: fn system nixpkgs.legacyPackages.${system});
in {
packages = forEachSystem (system: pkgs: rec {
quickshell-web = pkgs.callPackage ./default.nix {};
default = quickshell-web;
});
};
}

16
shell.nix Normal file
View file

@ -0,0 +1,16 @@
{
pkgs ? import <nixpkgs> {},
quickshell-web ? pkgs.callPackage ./default.nix {},
}: pkgs.mkShell {
inputsFrom = [ quickshell-web ];
nativeBuildInputs = [ (pkgs.writeShellScriptBin "yarn-install-hack" ''
set -x
yarn install || true
mkdir -p node_modules/node/bin
ln -sf ${pkgs.nodejs}/bin/node node_modules/node/bin/node
yarn install
'') ];
YARN_NODE_LINKER = "node-modules";
}