130 lines
3.9 KiB
Nix
130 lines
3.9 KiB
Nix
{
|
|
description = "srx.astro.nix";
|
|
inputs = {
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
flake-compat = {
|
|
url = "github:edolstra/flake-compat";
|
|
flake = false;
|
|
};
|
|
pre-commit-hooks = {
|
|
url = "github:cachix/pre-commit-hooks.nix";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
inputs.flake-utils.follows = "flake-utils";
|
|
};
|
|
npm-buildpackage.url = "github:serokell/nix-npm-buildpackage";
|
|
};
|
|
outputs = {
|
|
self,
|
|
nixpkgs,
|
|
flake-utils,
|
|
...
|
|
} @ inputs:
|
|
flake-utils.lib.eachSystem ["x86_64-linux" "aarch64-linux"] (
|
|
system: let
|
|
pkgs = import nixpkgs {inherit system;};
|
|
version = builtins.substring 0 8 self.lastModifiedDate;
|
|
astro-modules = pname: version: src:
|
|
pkgs.mkYarnModules {
|
|
pname = "${pname}-modules";
|
|
inherit version;
|
|
packageJSON = "${src}/package.json";
|
|
yarnLock = ./yarn.lock;
|
|
yarnNix = ./nix/yarn.nix;
|
|
# postBuild = ''
|
|
# cp -r $out/node_modules/ $out/node_modules/
|
|
# '';
|
|
};
|
|
in {
|
|
checks = import ./nix/checks.nix inputs system;
|
|
devShells.default = import ./nix/shell.nix inputs system;
|
|
|
|
packages = {
|
|
astro-package-nix = pkgs.stdenv.mkDerivation rec {
|
|
pname = "srx-portfolio";
|
|
inherit version;
|
|
src = ./.;
|
|
nativeBuildInputs = [
|
|
pkgs.nodejs
|
|
];
|
|
buildPhase = ''
|
|
ln -sf ${astro-modules pname version src}/node_modules node_modules
|
|
export NODE_OPTIONS='--unhandled-rejections=warn'
|
|
npm --update-notifier=false run build
|
|
'';
|
|
installPhase = ''
|
|
mv dist $out
|
|
'';
|
|
};
|
|
|
|
nginx-container-docker = pkgs.dockerTools.buildImage {
|
|
name = "nginx";
|
|
tag = version;
|
|
copyToRoot = pkgs.buildEnv {
|
|
name = "base-config";
|
|
pathsToLink = ["/bin"];
|
|
paths = [
|
|
pkgs.dockerTools.fakeNss
|
|
pkgs.nginx
|
|
];
|
|
};
|
|
runAsRoot = ''
|
|
#!${pkgs.runtimeShell}
|
|
${pkgs.dockerTools.shadowSetup}
|
|
groupadd --system nginx
|
|
useradd --system --gid nginx nginx
|
|
'';
|
|
extraCommands = ''
|
|
mkdir -p tmp/nginx_client_body
|
|
mkdir -p var/log/nginx
|
|
mkdir -p var/cache/nginx
|
|
'';
|
|
};
|
|
|
|
astro-container-docker = let
|
|
nginxPort = "8080";
|
|
nginxConf = pkgs.writeText "nginx.conf" ''
|
|
user nginx nginx;
|
|
daemon off;
|
|
error_log /dev/stdout info;
|
|
pid /dev/null;
|
|
events {}
|
|
http {
|
|
access_log /dev/stdout;
|
|
server {
|
|
listen ${nginxPort};
|
|
index index.html;
|
|
location / {
|
|
root ${self.packages.${system}.default};
|
|
}
|
|
}
|
|
}
|
|
'';
|
|
in
|
|
pkgs.dockerTools.buildImage {
|
|
name = "astro";
|
|
tag = version;
|
|
fromImage = self.packages.${system}.nginx-container-docker;
|
|
copyToRoot = pkgs.buildEnv {
|
|
name = "image-www";
|
|
paths = [self.packages.${system}.default];
|
|
};
|
|
config = {
|
|
Cmd = ["nginx" "-c" nginxConf];
|
|
ExposedPorts = {
|
|
"${nginxPort}/tcp" = {};
|
|
};
|
|
};
|
|
};
|
|
|
|
default = self.packages.${system}.astro-package-nix;
|
|
};
|
|
|
|
pkgs = import nixpkgs {
|
|
inherit system;
|
|
config.allowUnfree = true;
|
|
};
|
|
}
|
|
);
|
|
}
|