Skip to content

Update Nix packaging files #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ $RECYCLE.BIN/
# Ignore all the scraped data
scraped-data

#pytest
# pytest
/test/.jbsite
/test/screenshots/
/test/.pytest_cache
Expand All @@ -43,4 +43,7 @@ node_modules/
env
core
core
result
result

# Nix
result
96 changes: 69 additions & 27 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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 = ''
Expand All @@ -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);
});
};
}
57 changes: 32 additions & 25 deletions package.nix
Original file line number Diff line number Diff line change
@@ -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;
};
}