summaryrefslogtreecommitdiff
path: root/README.md
blob: 8569095b38c16104bab4c94e3318d66bd45e257f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# procfile-nix

A library + [flake-parts](https://flake.parts/) module that helps you manage procfiles and background jobs with [overmind](https://github.com/DarthSim/overmind) (or any other Procfile runner)!

## Usage

Regardless of if you use the library or flakeModule, you will be putting a package into your development shells.
Following this, the name you gave the Procfile will be avalible as a command while will setup all of your processes.

Example:

```shell
$ nix develop
$ myprocfile
```

You can also send the command to run in the background like so: `myprocfile &`

## Usage (library)

First, put this in your `flake.nix`:

```nix
{
  inputs = {
    nixpkgs.url = "nixpkgs/nixpkgs-unstable";
    procfile-nix = {
      url = "github:getchoo/procfile-nix";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = { nixpkgs, procfile-nix, ... }: let
    systems = [ "x86_64-linux" "aarch64-linux" ];

    forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f nixpkgs.legacyPackages.${system});
  in {
    devShells = forAllSystems ({
      lib,
      pkgs,
      system,
      ...
    }: let
      procfile = procfile-nix.lib.${system}.mkProcfileRunner {
        name = "daemons";

        procGroup = {
          redis = lib.getExe' pkgs.redis "redis-server";
        };

        # OPTIONAL: switch the Procfile runner if desired.
        procRunner = pkgs.honcho;
      };
    in {
      default = pkgs.mkShell {
        packages = [ procfile ];
      };
    });
  };
}
```

Then run `nix develop`, `daemons &`, and you're good to go!

## Usage (flakeModule)

```nix
{

  inputs = {
    nixpkgs.url = "nixpkgs/nixpkgs-unstable";
    flake-parts = {
      url = "github:hercules-ci/flake-parts";
      inputs.nixpkgs-lib.follows = "nixpkgs";
    };
    procfile-nix = {
      url = "github:getchoo/procfile-nix";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = inputs:
    inputs.flake-parts.lib.mkFlake { inherit inputs; } {
      systems = [ "x86_64-linux" "aarch64-linux" ];

      imports = [ inputs.procfile-nix.flakeModule ];

      perSystem = {
        config,
        lib,
        pkgs,
        ...
      }: {
        procfiles.daemons = {
          processes = {
            redis = lib.getExe' pkgs.redis "redis-server";
          };
          
          # OPTIONAL: switch the Procfile runner if desired.
          procRunner = pkgs.honcho;
        };

        devShells.default = pkgs.mkShell {
          packages = [ config.procfiles.daemons.package ];
        };
      };
    };
}
```

Similar to the last example, `nix develop` and `daemons &` may be run to start your Procfile