├── LICENSE ├── README.md ├── flake-module.nix └── flake.nix /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Sridhar Ratnakumar 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # proc-flake 2 | 3 | A [`flake-parts`](https://flake.parts/) Nix module for running multiple processes in a dev shell. 4 | 5 | [honcho](https://github.com/nickstenning/honcho) is used to launch the processes. 6 | 7 | ## Usage 8 | 9 | NOTE: this module requires the [flake-root](https://github.com/srid/flake-root) module. 10 | 11 | ```nix 12 | proc.groups.run.processes = { 13 | haskell.command = "${lib.getExe pkgs.haskellPackages.ghcid}"; 14 | tailwind.command = "${lib.getExe pkgs.haskellPackages.tailwind} -w -o ./static/tailwind.css './src/**/*.hs'"; 15 | }; 16 | 17 | ``` 18 | 19 | This gives a `config.proc.groups.run.package` derivation that you can put in the `nativeBuildInputs` of devShell for availability in the shell. 20 | 21 | For better discoverability, consider using this in conjunction with the [mission-control](https://github.com/Platonic-Systems/mission-control) module. 22 | 23 | ## Examples 24 | 25 | - https://github.com/EmaApps/ema-template 26 | 27 | ## Credits 28 | 29 | The idea for this module came largely from Domen Kožar's [devenv project](https://devenv.sh/processes/). 30 | 31 | ## Alternatives 32 | 33 | For a similar module that uses a more advanced tool called `process-compose`, see https://github.com/Platonic-Systems/process-compose-flake 34 | -------------------------------------------------------------------------------- /flake-module.nix: -------------------------------------------------------------------------------- 1 | # Largely inspired by: 2 | # https://github.com/cachix/devenv/blob/main/src/modules/processes.nix 3 | { self, config, lib, flake-parts-lib, ... }: 4 | 5 | let 6 | inherit (flake-parts-lib) 7 | mkPerSystemOption; 8 | inherit (lib) 9 | types; 10 | in 11 | { 12 | options = { 13 | perSystem = mkPerSystemOption 14 | ({ config, self', inputs', pkgs, system, ... }: 15 | let 16 | procSubmodule = types.submodule { 17 | options = { 18 | groups = lib.mkOption { 19 | type = types.attrsOf processGroupSubmodule; 20 | description = '' 21 | Process groups that can be invoked individually. 22 | ''; 23 | }; 24 | }; 25 | }; 26 | processGroupSubmodule = types.submodule (args@{ name, ... }: { 27 | options = { 28 | processes = lib.mkOption { 29 | type = types.attrsOf processSubmodule; 30 | description = '' 31 | Processes to run simultaneously when running this group. 32 | ''; 33 | }; 34 | package = lib.mkOption { 35 | type = types.package; 36 | description = '' 37 | The package to use to run the given process group. 38 | ''; 39 | }; 40 | }; 41 | config = 42 | let 43 | procfile = 44 | pkgs.writeText "Procfile" (lib.concatStringsSep "\n" 45 | (lib.mapAttrsToList (name: v: "${name}: ${v.command}") 46 | args.config.processes)); 47 | in 48 | { 49 | package = pkgs.writeShellApplication { 50 | inherit name; 51 | runtimeInputs = [ pkgs.honcho ]; 52 | text = '' 53 | tree_root=''$(${lib.getExe config.flake-root.package}) 54 | cd "$tree_root" 55 | 56 | # Pass user's arguments to honcho; if none was passed, pass 57 | # 'start' to launch all processes. 58 | ARG1="''${1:-start}" 59 | shift 1 || true 60 | 61 | set -x 62 | honcho --procfile ${procfile} "$ARG1" "$@" 63 | ''; 64 | }; 65 | }; 66 | }); 67 | processSubmodule = types.submodule { 68 | options = { 69 | command = lib.mkOption { 70 | type = types.str; 71 | description = '' 72 | The command to run the given process. 73 | ''; 74 | }; 75 | }; 76 | }; 77 | in 78 | { 79 | options.proc = lib.mkOption { 80 | type = procSubmodule; 81 | description = '' 82 | Configuration for processes to run in the development environment. 83 | ''; 84 | }; 85 | }); 86 | }; 87 | } 88 | -------------------------------------------------------------------------------- /flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "A `flake-parts` module for running Procfile-like processes"; 3 | outputs = { self, ... }: { 4 | flakeModule = ./flake-module.nix; 5 | }; 6 | } 7 | --------------------------------------------------------------------------------