From cd187e3092dce488d7f9817109e54b239e311952 Mon Sep 17 00:00:00 2001 From: Kristian Krsnik Date: Sat, 2 Mar 2024 19:36:04 +0100 Subject: [PATCH] updated blog flake --- .gitignore | 18 ++++++++---------- flake.lock | 42 ++++------------------------------------- flake.nix | 55 ++++++++++++++++++++++++++++++------------------------ 3 files changed, 43 insertions(+), 72 deletions(-) diff --git a/.gitignore b/.gitignore index bcba48a..ccb4028 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,11 @@ +# Nix build output +/result + +# development +/.direnv/ +/themes + # Generated files by hugo /public/ -/resources/_gen/ -/assets/jsconfig.json -hugo_stats.json - -# Temporary lock file while building +/resources/ /.hugo_build.lock - -# Nix -.direnv/ -/result -/themes/ \ No newline at end of file diff --git a/flake.lock b/flake.lock index a0e2871..d6d32ec 100644 --- a/flake.lock +++ b/flake.lock @@ -1,35 +1,17 @@ { "nodes": { - "flake-utils": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1689068808, - "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, "nixpkgs": { "locked": { - "lastModified": 1692207601, - "narHash": "sha256-tfPGNKQcJT1cvT6ufqO/7ydYNL6mcJClvzbrzhKjB80=", + "lastModified": 1709237383, + "narHash": "sha256-cy6ArO4k5qTx+l5o+0mL9f5fa86tYUX3ozE1S+Txlds=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "b30c68669df77d981ce4aefd6b9d378563f6fc4e", + "rev": "1536926ef5621b09bba54035ae2bb6d806d72ac8", "type": "github" }, "original": { "owner": "NixOS", - "ref": "nixos-23.05", + "ref": "nixos-unstable", "repo": "nixpkgs", "type": "github" } @@ -52,25 +34,9 @@ }, "root": { "inputs": { - "flake-utils": "flake-utils", "nixpkgs": "nixpkgs", "nostyleplease": "nostyleplease" } - }, - "systems": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 2c3d758..628762c 100644 --- a/flake.nix +++ b/flake.nix @@ -3,7 +3,6 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - flake-utils.url = "github:numtide/flake-utils"; nostyleplease = { url = "github:Masellum/hugo-theme-nostyleplease"; flake = false; @@ -13,49 +12,57 @@ outputs = { self, nixpkgs, - flake-utils, nostyleplease, - }: - flake-utils.lib.eachDefaultSystem (system: let - pkgs = nixpkgs.legacyPackages.${system}; - in { - formatter = pkgs.alejandra; + }: let + supportedSystems = ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"]; + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + pkgs = forAllSystems (system: nixpkgs.legacyPackages.${system}); + in { + formatter = forAllSystems (system: pkgs.${system}.alejandra); - packages.default = pkgs.stdenv.mkDerivation { + packages = forAllSystems (system: { + default = pkgs.${system}.stdenv.mkDerivation { name = "blog"; - meta = with pkgs.lib; { - description = "Kristian's personal blog"; - platforms = platforms.all; - }; - # Exclude themes and public folder from build sources - src = builtins.filterSource (path: type: - !(type - == "directory" - && (baseNameOf path == "themes" || baseNameOf path == "public"))) - ./.; + src = builtins.filterSource (path: type: !(type == "directory" && (baseNameOf path == "themes" || baseNameOf path == "public"))) ./.; + + nativeBuildInputs = with pkgs.${system}; [ + hugo + ]; # Link theme to themes folder and build buildPhase = '' mkdir -p themes ln -s ${nostyleplease} themes/nostyleplease - ${pkgs.hugo}/bin/hugo --gc --minify + hugo --gc --minify ''; installPhase = '' cp -r public/. $out ''; }; + }); + + devShells = forAllSystems (system: { + default = pkgs.${system}.mkShellNoCC { + packages = with pkgs.${system}; [ + hugo + ]; - devShells.default = pkgs.mkShellNoCC { - packages = with pkgs; [hugo]; # Link theme to themes folder shellHook = '' - mkdir -p themes - unlink themes/nostyleplease - ln -s ${nostyleplease} themes/nostyleplease + if [ ! -d ./themes ]; then + mkdir ./themes + fi + + if [ ! -d ./themes/nostyleplease ]; then + ln -s ${nostyleplease} ./themes/nostyleplease + fi + + hugo server --buildDrafts ''; }; }); + }; }