init v0
This commit is contained in:
parent
561ea7543d
commit
43e6b6d318
25 changed files with 8063 additions and 374 deletions
142
flake.nix
142
flake.nix
|
|
@ -18,15 +18,122 @@
|
|||
...
|
||||
} @ inputs: let
|
||||
# Set the Erlang version
|
||||
erlangVersion = "erlang_27";
|
||||
erlangVersion = "erlang";
|
||||
# Set the Elixir version
|
||||
elixirVersion = "elixir_1_17";
|
||||
elixirVersion = "elixir";
|
||||
in
|
||||
flake-parts.lib.mkFlake {inherit inputs;} {
|
||||
systems = import systems;
|
||||
|
||||
imports = [inputs.process-compose-flake.flakeModule];
|
||||
|
||||
flake = {
|
||||
nixosModules.default = {
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
with lib; let
|
||||
cfg = config.sites.zoeycomputer;
|
||||
in {
|
||||
options.sites.zoeycomputer = {
|
||||
enable = mkEnableOption "Enables the zoey computer";
|
||||
|
||||
domain = mkOption rec {
|
||||
type = types.str;
|
||||
default = "zoeys.computer";
|
||||
example = default;
|
||||
description = "The domain name for the website";
|
||||
};
|
||||
|
||||
ssl = mkOption rec {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
example = default;
|
||||
description = "Whether to enable SSL on the domain or not";
|
||||
};
|
||||
|
||||
phx = {
|
||||
port = mkOption rec {
|
||||
type = types.int;
|
||||
default = 4000;
|
||||
example = default;
|
||||
description = "What port should phoenix run on";
|
||||
};
|
||||
|
||||
package = mkOption rec {
|
||||
type = types.derivation;
|
||||
default = self.packages.${pkgs.system}.default;
|
||||
example = default;
|
||||
description = "The phoenix package containing the application";
|
||||
};
|
||||
|
||||
enableServer = mkOption rec {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
example = default;
|
||||
description = "Enable Phoenix Server, why would you not enable this?";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
services.nginx.virtualHosts.${cfg.domain} = {
|
||||
forceSSL = cfg.ssl;
|
||||
enableACME = cfg.ssl;
|
||||
locations."/".proxyPass = "http://127.0.0.1:${cfg.phx.port}";
|
||||
};
|
||||
|
||||
systemd.services.${release_name} = let
|
||||
release_name = "zoeyscomputer";
|
||||
working_directory = "/var/lib/zoeycomputer";
|
||||
in {
|
||||
wantedBy = ["multi-user.target"];
|
||||
after = ["network.target" "postgresql.service"];
|
||||
# note that if you are connecting to a postgres instance on a different host
|
||||
# postgresql.service should not be included in the requires.
|
||||
requires = ["network-online.target" "postgresql.service"];
|
||||
description = "zoey computer";
|
||||
environment = {
|
||||
# RELEASE_TMP is used to write the state of the
|
||||
# VM configuration when the system is running
|
||||
# it needs to be a writable directory
|
||||
RELEASE_TMP = working_directory;
|
||||
# can be generated in an elixir console with
|
||||
# Base.encode32(:crypto.strong_rand_bytes(32))
|
||||
PORT = cfg.phx.port;
|
||||
PHX_HOST = cfg.domain;
|
||||
PHX_SERVER = cfg.phx.enableServer;
|
||||
};
|
||||
serviceConfig = {
|
||||
Type = "exec";
|
||||
DynamicUser = true;
|
||||
WorkingDirectory = working_directory;
|
||||
# Implied by DynamicUser, but just to emphasize due to RELEASE_TMP
|
||||
PrivateTmp = true;
|
||||
ExecStart = pkgs.writeShellScript "start-zoeycomputer" ''
|
||||
${cfg.phx.package}/bin/${release_name} eval "ZoeysComputer.Release.migrate"
|
||||
${cfg.phx.package}/bin/${release_name} start
|
||||
'';
|
||||
ExecStop = ''
|
||||
${cfg.phx.package}/bin/${release_name} stop
|
||||
'';
|
||||
ExecReload = ''
|
||||
${cfg.phx.package}/bin/${release_name} restart
|
||||
'';
|
||||
Restart = "on-failure";
|
||||
RestartSec = 5;
|
||||
StartLimitBurst = 3;
|
||||
StartLimitInterval = 10;
|
||||
};
|
||||
# disksup requires bash
|
||||
path = [pkgs.bash];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
perSystem = {
|
||||
# self',
|
||||
config,
|
||||
|
|
@ -34,7 +141,17 @@
|
|||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}: {
|
||||
}: let
|
||||
npmDeps = (pkgs.callPackage ./assets/default.nix {}).shell.nodeDependencies;
|
||||
|
||||
heroicons = pkgs.fetchFromGitHub {
|
||||
owner = "tailwindlabs";
|
||||
repo = "heroicons";
|
||||
rev = "v2.1.1";
|
||||
hash = "sha256-y/kY8HPJmzB2e7ErgkUdQijU7oUhfS3fI093Rsvyvqs=";
|
||||
sparseCheckout = ["optimized"];
|
||||
};
|
||||
in {
|
||||
# Define a consistent package set for development, testing, and
|
||||
# production.
|
||||
_module.args.pkgs = import nixpkgs {
|
||||
|
|
@ -54,10 +171,10 @@
|
|||
];
|
||||
};
|
||||
|
||||
# Add hydraJob for x86_64-linux
|
||||
hydraJobs = lib.optionalAttrs (system == "x86_64-linux") {
|
||||
default = self.packages.${system}.default;
|
||||
};
|
||||
# # Add hydraJob for x86_64-linux
|
||||
# hydraJobs = lib.optionalAttrs (system == "x86_64-linux") {
|
||||
# default = self.packages.${system}.default;
|
||||
# };
|
||||
|
||||
# You can build your Elixir application using mixRelease.
|
||||
packages.default = pkgs.beamPackages.mixRelease {
|
||||
|
|
@ -71,7 +188,15 @@
|
|||
};
|
||||
buildInputs = with pkgs; [nodejs];
|
||||
|
||||
MIX_ENV = "prod";
|
||||
postBuild = ''
|
||||
echo ${heroicons}
|
||||
ln -sf ${npmDeps}/lib/node_modules assets/node_modules
|
||||
ln -sf ${heroicons} deps/heroicons
|
||||
ls deps/
|
||||
npm run deploy --prefix ./assets
|
||||
|
||||
mix do deps.loadpaths --no-deps-check, phx.digest
|
||||
'';
|
||||
};
|
||||
|
||||
# Add dependencies to develop your application using Mix.
|
||||
|
|
@ -84,6 +209,7 @@
|
|||
# application.
|
||||
nodejs
|
||||
mix2nix
|
||||
node2nix
|
||||
# Add the language server of your choice.
|
||||
inputs.lexical.packages.${system}.default
|
||||
# I once added Hex via a Nix development shell, but now I install
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue