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 95d56699..f18a4773 100644 Binary files a/nixosModules/ags/config/package-lock.json and b/nixosModules/ags/config/package-lock.json differ 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 {