feat(ags): install node_modules in nix
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-08-06 20:35:11 -04:00
parent 9ea4b26421
commit 0fa79307c1
9 changed files with 57 additions and 25 deletions

2
.gitignore vendored
View file

@ -2,7 +2,7 @@
*.egg-info *.egg-info
# NPM # NPM
*node_modules/ *node_modules
*build/ *build/
# Direnv # Direnv

View file

@ -1,10 +1,8 @@
{ {
lib, lib,
system,
buildNpmPackage, buildNpmPackage,
callPackage, callPackage,
makeWrapper, makeWrapper,
mozilla-addons-to-nix,
nodejs_latest, nodejs_latest,
... ...
}: let }: let
@ -12,10 +10,9 @@
inherit (builtins) readFile fromJSON; inherit (builtins) readFile fromJSON;
packageJSON = fromJSON (readFile ./package.json); packageJSON = fromJSON (readFile ./package.json);
pname = packageJSON.name;
in in
buildNpmPackage rec { buildNpmPackage rec {
name = pname; pname = packageJSON.name;
inherit (packageJSON) version; inherit (packageJSON) version;
src = ./.; src = ./.;
@ -23,7 +20,6 @@ in
runtimeInputs = [ runtimeInputs = [
(callPackage ../../nixosModules/docker/updateImage.nix {}) (callPackage ../../nixosModules/docker/updateImage.nix {})
mozilla-addons-to-nix.packages.${system}.default
]; ];
nativeBuildInputs = [makeWrapper]; nativeBuildInputs = [makeWrapper];

17
lib.nix
View file

@ -7,6 +7,23 @@
version = mkVersion src; version = mkVersion src;
}; };
buildNodeModules = dir: npmDepsHash: let
pkg = inputs.pkgs.callPackage ({buildNpmPackage, ...}: let
inherit (builtins) readFile fromJSON;
packageJSON = fromJSON (readFile (dir + /package.json));
in
buildNpmPackage {
pname = packageJSON.name;
inherit (packageJSON) version;
src = dir;
inherit npmDepsHash;
dontNpmBuild = true;
}) {};
in "${pkg}/lib/node_modules/${pkg.pname}/node_modules";
# Import pkgs from a nixpkgs # Import pkgs from a nixpkgs
mkPkgs = system: input: mkPkgs = system: input:
import input { import input {

View file

@ -1,2 +1 @@
use flake "$FLAKE#node" use flake "$FLAKE#node"
npm ci

Binary file not shown.

View file

@ -1,17 +1,17 @@
{ {
"name": "ags-node-modules",
"version": "0.0.0",
"main": "config.js", "main": "config.js",
"type": "module", "type": "module",
"dependencies": { "dependencies": {
"fzf": "0.5.2" "fzf": "0.5.2",
},
"devDependencies": {
"@eslint/js": "9.8.0", "@eslint/js": "9.8.0",
"@stylistic/eslint-plugin": "2.6.1", "@stylistic/eslint-plugin": "2.6.1",
"@types/eslint__js": "8.42.3", "@types/eslint__js": "8.42.3",
"@types/node": "22.0.2", "@types/node": "22.1.0",
"eslint": "9.8.0", "eslint": "9.8.0",
"eslint-plugin-jsdoc": "48.10.2", "eslint-plugin-jsdoc": "48.11.0",
"typescript": "5.5.4", "typescript": "5.5.4",
"typescript-eslint": "8.0.0" "typescript-eslint": "8.0.1"
} }
} }

View file

@ -10,7 +10,7 @@ in {
inherit (lib) boolToString mkIf toLower; inherit (lib) boolToString mkIf toLower;
# Configs # Configs
inherit (config.vars) mainUser hostName; inherit (config.vars) hostName;
cfgDesktop = config.roles.desktop; cfgDesktop = config.roles.desktop;
flakeDir = config.environment.variables.FLAKE; flakeDir = config.environment.variables.FLAKE;
@ -24,7 +24,7 @@ in {
services.upower.enable = true; services.upower.enable = true;
home-manager.users.${mainUser}.imports = [ home-manager.users.${cfgDesktop.user}.imports = [
ags.homeManagerModules.default ags.homeManagerModules.default
({ ({
@ -46,11 +46,11 @@ in {
''; '';
agsPkg = config.programs.ags.finalPackage; agsPkg = config.programs.ags.finalPackage;
agsConfigDir = "${removePrefix "/home/${mainUser}/" flakeDir}/nixosModules/ags"; agsConfigDir = "${removePrefix "/home/${cfgDesktop.user}/" flakeDir}/nixosModules/ags";
in { in {
assertions = [ assertions = [
{ {
assertion = hasPrefix "/home/${mainUser}/" flakeDir; assertion = hasPrefix "/home/${cfgDesktop.user}/" flakeDir;
message = '' message = ''
Your $FLAKE environment variable needs to point to a directory in Your $FLAKE environment variable needs to point to a directory in
the main users' home to use the AGS module. the main users' home to use the AGS module.
@ -68,6 +68,8 @@ in {
home = { home = {
file = let file = let
inherit (import "${self}/lib.nix" {inherit pkgs;}) buildNodeModules;
mkType = package: girName: { mkType = package: girName: {
"${agsConfigDir}/config/types/@girs/${toLower girName}".source = "${agsConfigDir}/config/types/@girs/${toLower girName}".source =
pkgs.callPackage pkgs.callPackage
@ -100,6 +102,9 @@ in {
hasFprintd: ${boolToString (hostName == "wim")}, hasFprintd: ${boolToString (hostName == "wim")},
}; };
''; '';
"${agsConfigDir}/config/node_modules".source =
buildNodeModules ./config "sha256-Jt7HRrQ8xrpkku51zFbJ44IgPaKKXerZBJUyjo5VudQ=";
} }
// (import ./icons.nix {inherit pkgs agsConfigDir;}) // (import ./icons.nix {inherit pkgs agsConfigDir;})
); );

View file

@ -25,6 +25,15 @@ in {
createHome = true; createHome = true;
}; };
# Setup node modules for dev env
home-manager.users.${cfg.user}.home.file = let
flakeDir = config.environment.variables.FLAKE;
modulesDir = "${lib.removePrefix "/home/${cfg.user}/" flakeDir}/nixosModules";
nodeModules = config.home-manager.users.${cfg.user}.home.file."${modulesDir}/ags/config/node_modules".source;
in {
"${modulesDir}/desktop/manager/ags/node_modules".source = nodeModules;
};
home-manager.users.greeter = { home-manager.users.greeter = {
imports = [ags.homeManagerModules.default]; imports = [ags.homeManagerModules.default];

View file

@ -135,14 +135,20 @@
}; };
node = pkgs.mkShell { node = pkgs.mkShell {
packages = with pkgs; packages = with pkgs; [
[ nodejs_latest
nodejs_latest typescript
typescript
] (writeShellApplication {
++ (with nodePackages; [ name = "updateNpmDeps";
ts-node runtimeInputs = [prefetch-npm-deps nodejs_latest];
]);
text = ''
npm i --package-lock-only || true # this command will fail but still updates the main lockfile
prefetch-npm-deps ./package-lock.json
'';
})
];
}; };
subtitles-dev = pkgs.mkShell { subtitles-dev = pkgs.mkShell {