Skip to content

Commit

Permalink
devTools etc
Browse files Browse the repository at this point in the history
  • Loading branch information
jkarni committed Dec 15, 2024
1 parent 3468f98 commit 8148c0c
Showing 1 changed file with 45 additions and 3 deletions.
48 changes: 45 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@
default = false;
};

devTools = lib.mkOption {
type = lib.types.listOf lib.types.str;
description = "A list of packages make available in the devshell for this project. This is useful for things like LSPs, formatters, etc.";
default = [];
};

buildDependencies = lib.mkOption {
type = lib.types.listOf lib.types.str;
description = "A list of dependencies required to build this package. They are made available in the devshell, and at build time";
default = [];
};

runtimeDependencies = lib.mkOption {
type = lib.types.listOf lib.types.str;
description = "A list of dependencies required at runtime. They are made available in the devshell, at build time, and are available on the server at runtime";
default = [];
};

testCommand = lib.mkOption {
type = lib.types.str;
description = "The command to run the test. Default: npm run test";
Expand All @@ -55,6 +73,8 @@

config =
let
mkPackage = pkgName : pkgs.${pkgName};
mkPackages = builtins.map mkPackage;
theModule = projectConfig:
{ lib
, config
Expand All @@ -67,7 +87,10 @@
dream2nix.modules.dream2nix.nodejs-granular-v3
];

mkDerivation = { src = projectConfig.src; };
mkDerivation = {
src = projectConfig.src;
buildInputs = mkPackages projectConfig.buildDependencies;
};

deps = { nixpkgs, ... }: {
inherit
Expand Down Expand Up @@ -107,7 +130,7 @@
"${name}-test"
{ buildInputs = [
pkgs.nodejs
]; }
] ++ (mkPackages projectConfig.buildDependencies); }
''
GLOBIGNORE=".:.."
cp -r ${packages."${name}"}/lib/node_modules/nodejs-app/* .
Expand All @@ -120,6 +143,8 @@
touch /build/.gitignore
echo build/ >> /build/.gitignore
ls
${projectConfig.testCommand}
mkdir $out
'';
Expand All @@ -137,8 +162,24 @@
''
;
}) {} config.nodejs;

devShells = builtins.mapAttrs (name: projectConfig:
pkgs.mkShell {
inputsFrom = [packages."${name}"];
packages =
(mkPackages projectConfig.devTools) ++
(mkPackages projectConfig.buildDependencies) ++
(mkPackages projectConfig.runtimeDependencies) ++
(if projectConfig.prettier then [pkgs.nodePackages.prettier] else [])
;
}
) config.nodejs;


nixosConfigurations = builtins.mapAttrs
(name: projectConfig: {
environment.systemPackages = projectConfig.runtimeDependencies;

systemd.services.${name} = {
description = "${name} nodejs garnix module";
wantedBy = [ "multi-user.target" ];
Expand All @@ -149,7 +190,8 @@
DynamicUser = true;
ExecStart = lib.getExe (pkgs.writeShellApplication {
name = "start-${name}";
runtimeInputs = [ config.packages.${name} ];
runtimeInputs = [ config.packages.${name}
] ++ projectConfig.runtimeDependencies;
text = projectConfig.serverCommand;
});
};
Expand Down

0 comments on commit 8148c0c

Please sign in to comment.