Created
February 10, 2023 06:14
-
-
Save montchr/cde9119048e40d19d896e0ddd049b292 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# SPDX-FileCopyrightText: 2022-2023 Temple University | |
# SPDX-License-Identifier: GPL-3.0-or-later | |
{ | |
inputs, | |
cell, | |
}: let | |
inherit (inputs) devenv nixpkgs std; | |
inherit (inputs.cells) logan-center media wordpress; | |
l = inputs.nixpkgs.lib // builtins; | |
prj = logan-center.meta.project; | |
in | |
l.mapAttrs (_: std.lib.dev.mkShell) | |
{ | |
default = { | |
inherit (prj) name; | |
imports = [ | |
({config, ...}: let | |
inherit (procSettings) stateDir; | |
cfg = config.devenv; | |
procSettings = cfg.procv.settings; | |
supervisorPath = "${procSettings.stateDir}/${procSettings.name}"; | |
procfileScripts = { | |
honcho = '' | |
${nixpkgs.honcho}/bin/honcho start -f ${cfg.procfile} --env ${cfg.procfileEnv} & | |
''; | |
# overmind = '' | |
# OVERMIND_ENV=${config.procfileEnv} ${nixpkgs.overmind}/bin/overmind start --procfile ${config.procfile} & | |
# ''; | |
process-compose = '' | |
${nixpkgs.process-compose}/bin/process-compose --config ${cfg.procfile} \ | |
--port $PC_HTTP_PORT \ | |
--tui=$PC_TUI_ENABLED & | |
''; | |
# hivemind = '' | |
# ${nixpkgs.hivemind}/bin/hivemind --print-timestamps ${config.procfile} & | |
# ''; | |
}; | |
in { | |
options.devenv = l.mkOption { | |
type = l.types.nullOr (l.types.submoduleWith { | |
modules = [ | |
{ | |
_module.args = { | |
pkgs = nixpkgs; | |
inherit inputs; | |
inherit (inputs.devenv.inputs) pre-commit-hooks; | |
}; | |
} | |
(devenv + "/src/modules/top-level.nix") | |
{ | |
options.procv.settings = { | |
name = l.mkOption { | |
default = null; | |
type = l.types.nullOr l.types.string; | |
}; | |
stateDir = l.mkOption { | |
# TODO: is this reliable? | |
default = "\${PRJ_DATA_DIR:-\${DEVENV_STATE}}"; | |
type = l.types.nullOr l.types.string; | |
}; | |
}; | |
} | |
]; | |
}); | |
default = null; | |
}; | |
config = { | |
commands = l.mkIf (cfg.processes != {}) [{package = cfg.procfileScript;}]; | |
devenv = { | |
procv.settings.name = "procv"; | |
procfileScript = l.mkForce (nixpkgs.writeShellScriptBin "procv-up" '' | |
${cfg.process.before} | |
${procfileScripts.${cfg.process.implementation}} | |
# TODO: ensure state dirs exist for all requested services (if needed) | |
if [[ ! -d "${stateDir}" ]]; then | |
mkdir -p "${stateDir}" | |
fi | |
stop_up() { | |
echo "Stopping processes..." | |
kill -TERM $(cat "${supervisorPath}") | |
rm "${supervisorPath}" | |
wait | |
${cfg.process.after} | |
echo "Processes stopped." | |
} | |
trap stop_up SIGINT SIGTERM | |
echo $! > "${supervisorPath}" | |
wait | |
''); | |
}; | |
}; | |
}) | |
wordpress.devenvProfiles.serve | |
cell.devshellProfiles.formatters | |
media.devshellProfiles.image-optimisation | |
wordpress.devshellProfiles.default | |
std.std.devshellProfiles.default | |
]; | |
packages = [ | |
nixpkgs.cachix | |
nixpkgs.fd | |
nixpkgs.nodejs | |
nixpkgs.ripgrep | |
nixpkgs.gh # <https://cli.github.com/> | |
nixpkgs.gum # <https://github.com/charmbracelet/gum> | |
nixpkgs.reuse # <https://github.com/fsfe/reuse-tool> | |
]; | |
env = [ | |
{ | |
name = "CACHIX_CACHE_NAME"; | |
value = "kleintu"; | |
} | |
]; | |
commands = [ | |
{ | |
# NOTE: This yarn@v1 package is only used for initial bootstrapping. | |
# After the first run, yarn will manage its own versions. | |
# This setup assures both backward- and forward-compatibility, | |
# which is one of yarn's advertised features. That said, | |
# the newer versions of yarn come with some caveats, | |
# requiring the frequent use of the `yarn sdks` command | |
# unless using the `node-modules` linker. | |
package = nixpkgs.yarn; | |
category = "tools"; | |
} | |
{ | |
category = "tools"; | |
package = nixpkgs.just; | |
} | |
{ | |
category = "tools"; | |
package = nixpkgs.reuse; | |
} | |
{ | |
category = "tools"; | |
package = nixpkgs.pastel; | |
} | |
{ | |
category = "tools"; | |
package = nixpkgs.cocogitto; | |
} | |
]; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment