From 53a7304138f96c45944f3ca00882c9359acc8cc8 Mon Sep 17 00:00:00 2001 From: Ivan Mincik Date: Thu, 6 Mar 2025 13:07:23 +0100 Subject: [PATCH] Update Nix packaging files --- .gitignore | 7 ++-- flake.nix | 96 ++++++++++++++++++++++++++++++++++++++--------------- package.nix | 57 +++++++++++++++++-------------- 3 files changed, 106 insertions(+), 54 deletions(-) diff --git a/.gitignore b/.gitignore index 7d779054..f4f3d85c 100644 --- a/.gitignore +++ b/.gitignore @@ -27,7 +27,7 @@ $RECYCLE.BIN/ # Ignore all the scraped data scraped-data -#pytest +# pytest /test/.jbsite /test/screenshots/ /test/.pytest_cache @@ -43,4 +43,7 @@ node_modules/ env core core -result \ No newline at end of file +result + +# Nix +result diff --git a/flake.nix b/flake.nix index 896834f5..aa7ba747 100644 --- a/flake.nix +++ b/flake.nix @@ -1,34 +1,90 @@ { - description = "Development environment and build process for a Hugo app with Python requirements"; + description = "QGIS Planet Website"; + + # nixConfig = { + # extra-substituters = [ "https://example.cachix.org" ]; + # extra-trusted-public-keys = [ "example.cachix.org-1:xxxx=" ]; + # }; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; }; - outputs = { self, nixpkgs }: + outputs = { self, nixpkgs }: let + # Flake system supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; forAllSystems = nixpkgs.lib.genAttrs supportedSystems; - - nixpkgsFor = forAllSystems (system: import nixpkgs { - inherit system; + nixpkgsFor = forAllSystems (system: import nixpkgs { + inherit system; config.allowUnfree = true; }); - mkDevShell = system: + in + { + # + ### PACKAGES + # + + packages = forAllSystems (system: + let + pkgs = nixpkgsFor.${system}; + + in + { + website = pkgs.callPackage ./package.nix { }; + }); + + + # + ### APPS + # + + apps = forAllSystems (system: + let + pkgs = nixpkgsFor.${system}; + inherit (nixpkgs) lib; + + wwwLauncher = pkgs.writeShellApplication { + name = "website"; + runtimeInputs = [ pkgs.python3 ]; + text = '' + exec ${lib.getExe pkgs.python3} \ + -m http.server 8000 \ + -d ${self.packages.${system}.website}/ + ''; + }; + + in + { + default = { + type = "app"; + program = "${wwwLauncher}/bin/website"; + }; + }); + + + # + ### SHELLS + # + + devShells = forAllSystems (system: let pkgs = nixpkgsFor.${system}; + in { + # Development environment default = pkgs.mkShell { + packages = with pkgs; [ - hugo # Hugo for building the website - vscode # VSCode for development - python312Packages.feedparser # Python package: feedparser - python312Packages.requests # Python package: requests - python312Packages.pillow # Python package: Pillow + hugo # Hugo for building the website + vscode # VSCode for development + python312Packages.feedparser # Python package: feedparser + python312Packages.requests # Python package: requests + python312Packages.pillow # Python package: Pillow python312Packages.python-dateutil # Python package: dateutil - gnumake # GNU Make for build automation + gnumake # GNU Make for build automation ]; shellHook = '' @@ -51,20 +107,6 @@ echo "-----------------------" ''; }; - }; - - in - { - devShells = builtins.listToAttrs (map (system: { - name = system; - value = mkDevShell system; - }) supportedSystems); - - packages = builtins.listToAttrs (map (system: { - name = system; - value = { - qgis-planet-website = nixpkgsFor.${system}.callPackage ./package.nix {}; - }; - }) supportedSystems); + }); }; } diff --git a/package.nix b/package.nix index 6cd9d2db..4ec44733 100644 --- a/package.nix +++ b/package.nix @@ -1,32 +1,39 @@ -{ lib, stdenv, hugo, gnumake }: +{ lib +, stdenv +, hugo +}: stdenv.mkDerivation { - name = "qgis-planet-website"; - src = lib.cleanSourceWith { - src = ./.; - filter = ( - path: type: (builtins.all (x: x != baseNameOf path) [ - ".git" - ".github" - "flake.nix" - "package.nix" - ]) - ); - }; - buildInputs = [ hugo gnumake ]; + name = "qgis-planet-website"; - buildPhase = '' - make deploy - ''; + src = lib.cleanSourceWith { + src = ./.; + filter = ( + path: type: (builtins.all (x: x != baseNameOf path) [ + ".git" + ".github" + "flake.nix" + "flake.lock" + "package.nix" + "result" + ]) + ); + }; - installPhase = '' - mkdir -p $out - cp -r public/* $out/ - ''; + buildInputs = [ hugo ]; - meta = with lib; { - description = "A built QGIS Planet website"; - license = licenses.mit; - }; + buildPhase = '' + hugo --config config.toml,config/config.prod.toml + ''; + + installPhase = '' + mkdir -p $out + cp -r public_prod/* $out/ + ''; + + meta = with lib; { + description = "A built QGIS Planet website"; + license = licenses.mit; + }; }