From 0fa79307c14befcf54e6ced07aacae8410542219 Mon Sep 17 00:00:00 2001 From: matt1432 Date: Tue, 6 Aug 2024 20:35:11 -0400 Subject: [PATCH] feat(ags): install node_modules in nix --- .gitignore | 2 +- apps/update/default.nix | 6 +---- lib.nix | 17 ++++++++++++++ nixosModules/ags/config/.envrc | 1 - nixosModules/ags/config/package-lock.json | Bin 82521 -> 78855 bytes nixosModules/ags/config/package.json | 12 +++++----- nixosModules/ags/default.nix | 13 +++++++---- nixosModules/desktop/manager/ags/default.nix | 9 ++++++++ outputs.nix | 22 ++++++++++++------- 9 files changed, 57 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 75f521b8..bd86ed37 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ *.egg-info # NPM -*node_modules/ +*node_modules *build/ # Direnv diff --git a/apps/update/default.nix b/apps/update/default.nix index 395a42e3..8930d900 100644 --- a/apps/update/default.nix +++ b/apps/update/default.nix @@ -1,10 +1,8 @@ { lib, - system, buildNpmPackage, callPackage, makeWrapper, - mozilla-addons-to-nix, nodejs_latest, ... }: let @@ -12,10 +10,9 @@ inherit (builtins) readFile fromJSON; packageJSON = fromJSON (readFile ./package.json); - pname = packageJSON.name; in buildNpmPackage rec { - name = pname; + pname = packageJSON.name; inherit (packageJSON) version; src = ./.; @@ -23,7 +20,6 @@ in runtimeInputs = [ (callPackage ../../nixosModules/docker/updateImage.nix {}) - mozilla-addons-to-nix.packages.${system}.default ]; nativeBuildInputs = [makeWrapper]; diff --git a/lib.nix b/lib.nix index 1aa1caff..a0c19331 100644 --- a/lib.nix +++ b/lib.nix @@ -7,6 +7,23 @@ 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 mkPkgs = system: input: import input { diff --git a/nixosModules/ags/config/.envrc b/nixosModules/ags/config/.envrc index 1b7f76a7..674cafba 100644 --- a/nixosModules/ags/config/.envrc +++ b/nixosModules/ags/config/.envrc @@ -1,2 +1 @@ use flake "$FLAKE#node" -npm ci diff --git a/nixosModules/ags/config/package-lock.json b/nixosModules/ags/config/package-lock.json index 95d5669909f6afeaf4d46db3bd6218abc09a9a99..f18a47731e9b73a284de61c74004b7c867fbb06a 100644 GIT binary patch delta 3572 zcmZ`+dvKK16`vdOFoBSeL`q^HA<`gj!tS^4jX|>S_xrto$-cAi-Ryg{qPAEc$iq9j zQdHK*XhDmVOI>Ys8m*&Dbu?|Y4z&Z=vEo#Vb)4F9K&SWnzFmZ=P5#Ke_dM?J`<-*o zIXU%{wx52|D!9386#tARy@}x1)aaNuoSjUj0>Q~dDv*x{vttvqybxT-Mp8*qg|!*~ z?!S6&=>OY5v2qZw;D^k9Xfkcsf9_!@MSb`0?|^gdt*{1!fPm(K)%&a6@HN;EYa^}I zZWic*-vBl|QDY--%XI*z;}Z1Ivh^)^F$0gW+Tq*GK2&ITx4^l<<&e2n3>Vv{QM&U9 z0Ba>FN-ZyfhGYmXE*pcUy;mVaw}7%or+W^O(m$hkUmxju2EE^Z%QDLK>7EiCUcDM_ z{?|C1TXPO!Ey^PtePA&she#$}9 zoDggL`w+htvr?HZcfm>~^$a;v#Ll$Y#J=pcBqM*$#95UYeuT=q%IF`0$BA zRAc|*JLO}lepnGs!kv>W_}(-J_Hx&t-TaX&+`|nML(n8`gFBf&gxCO8gk4P!o#^AK zU9|Qhdlhv{)h%-E{c+MrXDhLKImGQeG(P+pP5Qf|wm&KE@M&{*tk!wC@PHNq{ zL`>mLmBLw#s`>>3^iyFFhzH>9uW>Psc6i3p4VO#0;UV#Q`0C9<45J;+8OgIT$o*!M zofqb~1xlGBs}U#NT=#q-Cd_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axLxr1rygyv9kDL07XE$D-0_{Z_Gj%(8@0yZIp$nCee5KI53NY&B>@=! zem8h#ml}TXV!9#6JwG05z}`7NkAcnQfs1DS2u{FLCyz8>2jRg6Ecyxu;YPp@D=#B{ z12Z3WV{70WKhYr0H(mrfUV9J;sulKrFbI-)QLVT+BTM1w*IN)r0=Arfjggq%DPR5! z-BEL`CHwPcBti9B0AGJogWyy<_@#i6cy7DF)4xKSWtA<&-`diUDISet(>38hiR>VNSzyJCSg4MELdtb-EX-P`IWi}5Q`~B}cs2`a6;2N^0;ITi* z8E$kRV}1Bm119{qtzIz5y}-Py&;n9-F!2ZFvJbn4yjHbZ zD(}w2Bn`5`gt#UnM_`J%Si&HA+o@Gh5eUm*^RGX8Ss9Lv_q9nH@4+ zF6+R#rdTqj@cXqyRKhldg?aZ>$|#>oS=BOwnV--2c+zmfAK_TzUbER@a(b;Lj>eeN z%X8{Tfy>JAJ!W2v;B##LkOCdEr8+Nt!LQv~>AQ88vSsGPdaQPJ{oiH#+uPtH;QXF} z88!<$3I^A1nrR!sR#87294T*@jA<20Cy$H>I7JQ-wFHalQZYlul>(>7tl%f&f=OOD z?h;v~N&T3W&?OUrQbCk+@T8@HK_3Z8i%zYNOz;$>Lv2?VO8Iz@t2Ux^>E-%-1Y@2N o)Oc`eBettSTIv|Cyw1ihA%@yAwm&PXtma|pP*^k04Q!(S0=buIpa1{> diff --git a/nixosModules/ags/config/package.json b/nixosModules/ags/config/package.json index 27b9b510..611319a8 100644 --- a/nixosModules/ags/config/package.json +++ b/nixosModules/ags/config/package.json @@ -1,17 +1,17 @@ { + "name": "ags-node-modules", + "version": "0.0.0", "main": "config.js", "type": "module", "dependencies": { - "fzf": "0.5.2" - }, - "devDependencies": { + "fzf": "0.5.2", "@eslint/js": "9.8.0", "@stylistic/eslint-plugin": "2.6.1", "@types/eslint__js": "8.42.3", - "@types/node": "22.0.2", + "@types/node": "22.1.0", "eslint": "9.8.0", - "eslint-plugin-jsdoc": "48.10.2", + "eslint-plugin-jsdoc": "48.11.0", "typescript": "5.5.4", - "typescript-eslint": "8.0.0" + "typescript-eslint": "8.0.1" } } diff --git a/nixosModules/ags/default.nix b/nixosModules/ags/default.nix index 010f89f6..3a4859a9 100644 --- a/nixosModules/ags/default.nix +++ b/nixosModules/ags/default.nix @@ -10,7 +10,7 @@ in { inherit (lib) boolToString mkIf toLower; # Configs - inherit (config.vars) mainUser hostName; + inherit (config.vars) hostName; cfgDesktop = config.roles.desktop; flakeDir = config.environment.variables.FLAKE; @@ -24,7 +24,7 @@ in { services.upower.enable = true; - home-manager.users.${mainUser}.imports = [ + home-manager.users.${cfgDesktop.user}.imports = [ ags.homeManagerModules.default ({ @@ -46,11 +46,11 @@ in { ''; agsPkg = config.programs.ags.finalPackage; - agsConfigDir = "${removePrefix "/home/${mainUser}/" flakeDir}/nixosModules/ags"; + agsConfigDir = "${removePrefix "/home/${cfgDesktop.user}/" flakeDir}/nixosModules/ags"; in { assertions = [ { - assertion = hasPrefix "/home/${mainUser}/" flakeDir; + assertion = hasPrefix "/home/${cfgDesktop.user}/" flakeDir; message = '' Your $FLAKE environment variable needs to point to a directory in the main users' home to use the AGS module. @@ -68,6 +68,8 @@ in { home = { file = let + inherit (import "${self}/lib.nix" {inherit pkgs;}) buildNodeModules; + mkType = package: girName: { "${agsConfigDir}/config/types/@girs/${toLower girName}".source = pkgs.callPackage @@ -100,6 +102,9 @@ in { hasFprintd: ${boolToString (hostName == "wim")}, }; ''; + + "${agsConfigDir}/config/node_modules".source = + buildNodeModules ./config "sha256-Jt7HRrQ8xrpkku51zFbJ44IgPaKKXerZBJUyjo5VudQ="; } // (import ./icons.nix {inherit pkgs agsConfigDir;}) ); diff --git a/nixosModules/desktop/manager/ags/default.nix b/nixosModules/desktop/manager/ags/default.nix index f1d18a27..6d0ab0d7 100644 --- a/nixosModules/desktop/manager/ags/default.nix +++ b/nixosModules/desktop/manager/ags/default.nix @@ -25,6 +25,15 @@ in { 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 = { imports = [ags.homeManagerModules.default]; diff --git a/outputs.nix b/outputs.nix index ae32c52d..96de0b64 100644 --- a/outputs.nix +++ b/outputs.nix @@ -135,14 +135,20 @@ }; node = pkgs.mkShell { - packages = with pkgs; - [ - nodejs_latest - typescript - ] - ++ (with nodePackages; [ - ts-node - ]); + packages = with pkgs; [ + nodejs_latest + typescript + + (writeShellApplication { + name = "updateNpmDeps"; + 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 {