Skip to content

Commit

Permalink
chore: split devenv.nix into 2 files, one for backend and another for…
Browse files Browse the repository at this point in the history
… non-essential services
  • Loading branch information
Rekkice committed Jan 14, 2025
1 parent 64d0e45 commit 55ece07
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 57 deletions.
4 changes: 2 additions & 2 deletions devenv.lock
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@
},
"nixpkgs-unstable": {
"locked": {
"lastModified": 1736012469,
"lastModified": 1736798957,
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "8f3e1f807051e32d8c95cd12b9b421623850a34d",
"rev": "9abb87b552b7f55ac8916b6fc9e5cb486656a2f3",
"type": "github"
},
"original": {
Expand Down
77 changes: 22 additions & 55 deletions devenv.nix
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
{ pkgs, lib, inputs, ... }:

let
pkgs-unstable = import inputs.nixpkgs-unstable { system = pkgs.stdenv.system; };
in
# top-level devenv.nix. contains services not essential to running the backend, such as Prometheus and Kafka
{
devcontainer.enable = true;

languages.elixir = {
enable = true;
package = pkgs-unstable.beamMinimal26Packages.elixir;
};
enterShell = ''
export PATH="$HOME/.mix/escripts:$PATH"
if [ ! -d ".devenv/state/grafana" ]; then
cp -rL .devenv/profile/share/grafana .devenv/state/grafana
chmod 777 -R .devenv/state/grafana
Expand All @@ -23,74 +15,49 @@ in
fi
'';

# https://devenv.sh/common-patterns/#configure-the-shell-based-on-the-current-machine
packages = [
pkgs.gnumake
pkgs.antora
pkgs.python314
pkgs.grafana
pkgs.prometheus
];

# for Antora extensions
languages.javascript.enable = true;
languages.javascript.yarn = {
enable = true;
install.enable = true;
};

tasks = {
"mix:deps" = {
exec = ''
# overrides the imported task to cd
exec = lib.mkForce ''
cd tololo
mix deps.get
'';
# runs before entering shell and before testing
before = [ "devenv:enterShell" "devenv:enterTest" ];
};
"mix:format" = {
exec = ''
# overrides the imported task to cd
exec = lib.mkForce ''
cd tololo
mix format --check-formatted
'';
};
};

enterTest = ''
cd tololo
mix test
mix credo
'';

# https://devenv.sh/common-patterns/#configure-the-shell-based-on-the-current-machine
packages = [
pkgs.gnumake
pkgs.antora
pkgs.python314
pkgs.grafana
pkgs.prometheus
] ++
# Linux only
lib.optionals pkgs.stdenv.isLinux [
# for ExUnit notifier
pkgs.libnotify

# for package - file_system
pkgs.inotify-tools
] ++
# Darwin only
lib.optionals pkgs.stdenv.isDarwin [
# for ExUnit notifier
pkgs.terminal-notifier

# for package - file_system
pkgs.darwin.apple_sdk.frameworks.CoreFoundation
pkgs.darwin.apple_sdk.frameworks.CoreServices
];

# for Antora extensions
languages.javascript.enable = true;
languages.javascript.yarn = {
enable = true;
install.enable = true;
};

processes = {
grafana.exec = "grafana server --homepath .devenv/state/grafana";
prometheus.exec = "prometheus --storage.tsdb.path .devenv/state/prometheus/data";
};

services.postgres = {
enable = true;
initialScript = ''
CREATE ROLE postgres WITH SUPERUSER LOGIN PASSWORD 'postgres';
'';
};

services.kafka.enable = true;
}
2 changes: 2 additions & 0 deletions devenv.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
inputs:
nixpkgs-unstable:
url: github:NixOS/nixpkgs/nixos-unstable
imports:
- ./tololo
116 changes: 116 additions & 0 deletions tololo/devenv.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{
"nodes": {
"devenv": {
"locked": {
"dir": "src/modules",
"lastModified": 1736426010,
"owner": "cachix",
"repo": "devenv",
"rev": "1c384bc4be3ee571511fbbc6fdc94fe47d60f6cf",
"type": "github"
},
"original": {
"dir": "src/modules",
"owner": "cachix",
"repo": "devenv",
"type": "github"
}
},
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1733328505,
"owner": "edolstra",
"repo": "flake-compat",
"rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"gitignore": {
"inputs": {
"nixpkgs": [
"pre-commit-hooks",
"nixpkgs"
]
},
"locked": {
"lastModified": 1709087332,
"owner": "hercules-ci",
"repo": "gitignore.nix",
"rev": "637db329424fd7e46cf4185293b9cc8c88c95394",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "gitignore.nix",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1733477122,
"owner": "cachix",
"repo": "devenv-nixpkgs",
"rev": "7bd9e84d0452f6d2e63b6e6da29fe73fac951857",
"type": "github"
},
"original": {
"owner": "cachix",
"ref": "rolling",
"repo": "devenv-nixpkgs",
"type": "github"
}
},
"nixpkgs-unstable": {
"locked": {
"lastModified": 1736798957,
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "9abb87b552b7f55ac8916b6fc9e5cb486656a2f3",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"pre-commit-hooks": {
"inputs": {
"flake-compat": "flake-compat",
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1735882644,
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "a5a961387e75ae44cc20f0a57ae463da5e959656",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"type": "github"
}
},
"root": {
"inputs": {
"devenv": "devenv",
"nixpkgs": "nixpkgs",
"nixpkgs-unstable": "nixpkgs-unstable",
"pre-commit-hooks": "pre-commit-hooks"
}
}
},
"root": "root",
"version": 7
}
62 changes: 62 additions & 0 deletions tololo/devenv.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{ pkgs, lib, inputs, ... }:

# backend devenv.nix. contains only the essential dependencies to run the project
let
pkgs-unstable = import inputs.nixpkgs-unstable { system = pkgs.stdenv.system; };
in
{
languages.elixir = {
enable = true;
package = pkgs-unstable.beamMinimal26Packages.elixir;
};
enterShell = ''
export PATH="$HOME/.mix/escripts:$PATH"
'';

tasks = {
"mix:deps" = {
exec = ''
mix deps.get
'';
# runs before entering shell and before testing
before = [ "devenv:enterShell" "devenv:enterTest" ];
};
"mix:format" = {
exec = ''
mix format --check-formatted
'';
};
};

enterTest = ''
mix test
mix credo
'';

# https://devenv.sh/common-patterns/#configure-the-shell-based-on-the-current-machine
packages = # Linux only
lib.optionals pkgs.stdenv.isLinux [
# for ExUnit notifier
pkgs.libnotify

# for package - file_system
pkgs.inotify-tools
] ++
# Darwin only
lib.optionals pkgs.stdenv.isDarwin [
# for ExUnit notifier
pkgs.terminal-notifier

# for package - file_system
pkgs.darwin.apple_sdk.frameworks.CoreFoundation
pkgs.darwin.apple_sdk.frameworks.CoreServices
];

services.postgres = {
enable = true;
initialScript = ''
CREATE ROLE postgres WITH SUPERUSER LOGIN PASSWORD 'postgres';
'';
};
}

3 changes: 3 additions & 0 deletions tololo/devenv.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
inputs:
nixpkgs-unstable:
url: github:NixOS/nixpkgs/nixos-unstable

0 comments on commit 55ece07

Please sign in to comment.