diff --git a/flake.nix b/flake.nix index 91bbb0e..47d9e3b 100644 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,5 @@ { - description = "A Nix-flake-based Node.js development environment"; + description = "Volpe Blog"; inputs.nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1.*.tar.gz"; @@ -19,9 +19,39 @@ pkgs = import nixpkgs {inherit overlays system;}; }); in { + packages = forEachSupportedSystem ({pkgs}: { + default = pkgs.callPackage ./nix/package.nix {}; + volpe = pkgs.callPackage ./nix/package.nix {}; + }); + devShells = forEachSupportedSystem ({pkgs}: { default = pkgs.mkShell { - packages = with pkgs; [node2nix nodejs pnpm sqlite]; + packages = with pkgs; [ + nodejs + nodePackages.pnpm + ]; + }; + }); + + nixosConfigurations.volpe = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + {nixpkgs.overlays = overlays;} + ./nix/configuration.nix + ]; + }; + + # Deployment helper - use with: nix run .#deploy + apps = forEachSupportedSystem ({pkgs}: { + deploy = { + type = "app"; + program = toString (pkgs.writeShellScript "deploy-volpe" '' + set -e + echo "Building and deploying to cyberian@69.61.19.180..." + nixos-rebuild switch --flake .#volpe \ + --target-host cyberian@69.61.19.180 \ + --sudo + ''); }; }); }; diff --git a/nix/configuration.nix b/nix/configuration.nix new file mode 100644 index 0000000..49131ac --- /dev/null +++ b/nix/configuration.nix @@ -0,0 +1,44 @@ +{ + config, + pkgs, + ... +}: { + imports = [ + ./hardware-configuration.nix + ./module.nix + ]; + + nix.settings.experimental-features = ["nix-command" "flakes"]; + nix.settings.trusted-users = ["root" "cyberian"]; + + swapDevices = [ + { + device = "/swapfile"; + size = 2 * 1024; # 2GB + } + ]; + + boot.loader.grub.enable = true; + boot.loader.grub.device = "/dev/vda"; + system.stateVersion = "24.11"; + + users.users.cyberian = { + isNormalUser = true; + extraGroups = ["wheel"]; + }; + security.sudo.wheelNeedsPassword = false; + + services.qemuGuest.enable = true; + services.acpid.enable = true; + + services.openssh = { + enable = true; + settings.PasswordAuthentication = false; + }; + + # Enable the volpe service + services.volpe = { + enable = true; + domain = "69.61.19.180"; + }; +} \ No newline at end of file diff --git a/nix/hardware-configuration.nix b/nix/hardware-configuration.nix new file mode 100644 index 0000000..b8efdbf --- /dev/null +++ b/nix/hardware-configuration.nix @@ -0,0 +1,30 @@ +# Do not modify this file! It was generated by 'nixos-generate-config' +# and may be overwritten by future invocations. Please make changes +# to /etc/nixos/configuration.nix instead. +{ + config, + lib, + pkgs, + modulesPath, + ... +}: { + imports = [ + (modulesPath + "/profiles/qemu-guest.nix") + ]; + + boot.initrd.availableKernelModules = ["ata_piix" "virtio_pci" "floppy" "sr_mod" "virtio_blk"]; + boot.initrd.kernelModules = []; + boot.kernelModules = ["kvm-amd"]; + boot.extraModulePackages = []; + + fileSystems."/" = { + device = "/dev/disk/by-uuid/1195bb4c-ddcb-4ad6-8109-d28170f169b1"; + fsType = "ext4"; + }; + + swapDevices = []; + + networking.useDHCP = lib.mkDefault true; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; +} diff --git a/nix/module.nix b/nix/module.nix new file mode 100644 index 0000000..06fe4d9 --- /dev/null +++ b/nix/module.nix @@ -0,0 +1,33 @@ +{ + config, + lib, + pkgs, + ... +}: let + cfg = config.services.volpe; + pkg = pkgs.callPackage ./package.nix {}; +in { + options.services.volpe = { + enable = lib.mkEnableOption "volpe blog"; + + domain = lib.mkOption { + type = lib.types.str; + default = "localhost"; + description = "Domain name for nginx virtual host."; + }; + }; + + config = lib.mkIf cfg.enable { + services.nginx = { + enable = true; + virtualHosts.${cfg.domain} = { + root = "${pkg}"; + locations."/" = { + tryFiles = "$uri $uri/ /index.html"; + }; + }; + }; + + networking.firewall.allowedTCPPorts = [80 443]; + }; +} \ No newline at end of file diff --git a/nix/package.nix b/nix/package.nix new file mode 100644 index 0000000..ace602e --- /dev/null +++ b/nix/package.nix @@ -0,0 +1,47 @@ +{ + lib, + stdenv, + nodejs_latest, + pnpm_10, + fetchPnpmDeps, + pnpmConfigHook, +}: let + nodejs = nodejs_latest; + pnpm = pnpm_10; +in + stdenv.mkDerivation (finalAttrs: { + pname = "volpe"; + version = "1.0.0"; + + src = lib.cleanSource ./..; + + nativeBuildInputs = [ + nodejs + pnpm + pnpmConfigHook + ]; + + # fetchPnpmDeps creates the offline store + pnpmDeps = fetchPnpmDeps { + inherit (finalAttrs) pname version src; + hash = "sha256-AiyDVGSxlfdqzuei0N0F3UOXlQVztxqyU7gBkZbUqOI="; + fetcherVersion = 3; # pnpm store version + }; + + buildPhase = '' + runHook preBuild + + pnpm build + + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + + mkdir -p $out + cp -r _site/* $out/ + + runHook postInstall + ''; + }) \ No newline at end of file