Created
          March 19, 2025 00:56 
        
      - 
      
- 
        Save lewalkingdad/a03ba038762dcb001861b4ad2566e64e to your computer and use it in GitHub Desktop. 
    Nix Flake Template For Elixir / Phoenix Dev Environment
  
        
  
    
      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
    
  
  
    
  | { | |
| description = "Elixir Phoenix Dev Environment"; | |
| inputs = { | |
| nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; | |
| flake-parts.url = "github:hercules-ci/flake-parts"; | |
| process-compose.url = "github:Platonic-Systems/process-compose-flake"; | |
| services-flake.url = "github:juspay/services-flake"; | |
| git-hooks.url = "github:cachix/git-hooks.nix"; | |
| }; | |
| outputs = inputs: | |
| inputs.flake-parts.lib.mkFlake { inherit inputs; } { | |
| imports = [ | |
| inputs.process-compose.flakeModule | |
| inputs.git-hooks.flakeModule | |
| ]; | |
| systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; | |
| perSystem = {self', pkgs, config, lib, ... }: { | |
| pre-commit.settings.hooks = { | |
| alejandra.enable = true; | |
| credo.enable = true; | |
| dialyzer.enable = true; | |
| mix-format.enable = true; | |
| mix-test.enable = true; | |
| }; | |
| process-compose."default" = { config, ...}: | |
| let | |
| dbName = "database"; | |
| in | |
| { | |
| imports = [ | |
| inputs.services-flake.processComposeModules.default | |
| ]; | |
| services.postgres."pg1" = { | |
| enable = true; | |
| initialDatabases = [ | |
| { | |
| name = dbName; | |
| } | |
| ]; | |
| }; | |
| settings.processes.phoenix = let | |
| pgcfg = config.services.postgres.pg1; | |
| in | |
| { | |
| environment.PGWEB_DATABASE_URL = pgcfg.connectionURI { inherit dbName; }; | |
| command = "${pkgs.elixir}/bin/mix phx.server --open"; | |
| depends_on."pg1".condition = "process_healthy"; | |
| }; | |
| settings.processes.pgweb = let | |
| pgcfg = config.services.postgres.pg1; | |
| in { | |
| environment.PGWEB_DATABASE_URL = pgcfg.connectionURI { inherit dbName; }; | |
| command = pkgs.pgweb; | |
| depends_on."pg1".condition = "process_healthy"; | |
| }; | |
| settings.processes.test = { | |
| command = pkgs.writeShellApplication { | |
| name = "pg1-test"; | |
| runtimeInputs = [ config.services.postgres.pg1.package ]; | |
| text = '' | |
| echo 'SELECT version();' | psql -h 127.0.0.1 ${dbName} | |
| ''; | |
| }; | |
| depends_on."pg1".condition = "process_healthy"; | |
| }; | |
| }; | |
| devShells.default = pkgs.mkShell { | |
| inputsFrom = [ | |
| config.process-compose."default".services.outputs.devShell | |
| ]; | |
| shellHook = let | |
| dir-locals = pkgs.writeTextFile { | |
| name = ".dir-locals.el"; | |
| text = '' | |
| ((elixir-ts-mode . ((eglot-server-programs . ((elixir-ts-mode . ("${pkgs.lib.getExe pkgs.elixir-ls}"))))))) | |
| ''; | |
| }; | |
| in | |
| '' | |
| cat ${dir-locals} > .dir-locals.el | |
| ''; | |
| buildInputs = with pkgs; [ | |
| elixir | |
| elixir-ls | |
| glibcLocales | |
| ] ++ lib.optional stdenv.isLinux inotify-tools | |
| ++ lib.optional stdenv.isDarwin terminal-notifier | |
| ++ lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ | |
| CoreFoundation | |
| CoreServices | |
| ]); | |
| nativeBuildInputs = [ pkgs.just ]; | |
| }; | |
| }; | |
| }; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment