From fd1e4e66f60e0bab3b1fda19c3e1846483090d74 Mon Sep 17 00:00:00 2001 From: Konstantin Nazarov Date: Sun, 11 Jun 2023 18:41:26 +0100 Subject: [PATCH] Implement nix-based build system --- Makefile | 10 +++++++++- bin/mdpage.sh | 2 +- bin/page.sh | 6 +++--- bin/rss.sh | 4 ++-- bin/toc.sh | 2 +- flake.lock | 26 ++++++++++++++++++++++++++ flake.nix | 33 +++++++++++++++++++++++++++++++++ knazarov.com.nix | 20 ++++++++++++++++++++ 8 files changed, 95 insertions(+), 8 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 knazarov.com.nix diff --git a/Makefile b/Makefile index af84264..776f982 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,8 @@ +ifeq ($(PREFIX),) + PREFIX := /usr/local +endif ODIR=output + PAGES_SRC := $(wildcard content/pages/*) PAGES_DST := $(patsubst content/pages/%,$(ODIR)/%/index.html,$(PAGES_SRC)) @@ -41,5 +45,9 @@ clean: deploy: rsync -avP --delete output/ root@knazarov.com:/var/www/knazarov.com/ +install: + install -d $(DESTDIR)$(PREFIX)/srv/knazarov.com + rsync -av --no-o --no-g output/ $(DESTDIR)$(PREFIX)/srv/knazarov.com + analytics: - ssh root@knazarov.com "cat /var/log/nginx/access.log" | ./bin/analytics.sh + ssh root@knazarov.com "cat /var/log/nginx/access.log" | ./bin/analytics.sh diff --git a/bin/mdpage.sh b/bin/mdpage.sh index 8cb25ad..77266aa 100755 --- a/bin/mdpage.sh +++ b/bin/mdpage.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh set -e diff --git a/bin/page.sh b/bin/page.sh index b85f589..0260e76 100755 --- a/bin/page.sh +++ b/bin/page.sh @@ -1,8 +1,8 @@ -#!/bin/bash +#!/bin/sh expand() { - TITLE="$1" - cat <<-"EOF" + TITLE="$1" + cat <<-"EOF" diff --git a/bin/rss.sh b/bin/rss.sh index e7c9dc1..b2760aa 100755 --- a/bin/rss.sh +++ b/bin/rss.sh @@ -1,7 +1,7 @@ -#!/bin/bash +#!/bin/sh remove_nbsp() { - sed 's#\ # #g' + sed 's#\ # #g' } date_rfc_822() { diff --git a/bin/toc.sh b/bin/toc.sh index 6aed27e..91f1994 100755 --- a/bin/toc.sh +++ b/bin/toc.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh set -e diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..214baa0 --- /dev/null +++ b/flake.lock @@ -0,0 +1,26 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1686503661, + "narHash": "sha256-s20xJMC8j8RRluqJixb7fLYkNiGNGebw82/R3ozcvzI=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "089f5788fbfefe3adcb930a908d4874e1ce5c0ce", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..582d923 --- /dev/null +++ b/flake.nix @@ -0,0 +1,33 @@ +{ + description = "Nix flake for knazarov.com"; + + # Flake inputs + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs"; # also valid: "nixpkgs"; + }; + + # Flake outputs + outputs = { self, nixpkgs }: + let + # Systems supported + allSystems = [ + "x86_64-linux" # 64-bit Intel/AMD Linux + "aarch64-linux" # 64-bit ARM Linux + "x86_64-darwin" # 64-bit Intel macOS + "aarch64-darwin" # 64-bit ARM macOS + ]; + + # Helper to provide system-specific attributes + forAllSystems = f: nixpkgs.lib.genAttrs allSystems (system: f { + pkgs = import nixpkgs { inherit system; }; + }); + in + { + packages = forAllSystems( {pkgs }: + { + "knazarov.com" = (pkgs.callPackage ./knazarov.com.nix {}); + default = (pkgs.callPackage ./knazarov.com.nix {}); + } + ); + }; +} diff --git a/knazarov.com.nix b/knazarov.com.nix new file mode 100644 index 0000000..d642bca --- /dev/null +++ b/knazarov.com.nix @@ -0,0 +1,20 @@ +{ + pkgs, + stdenv +}: +stdenv.mkDerivation rec { + pname = "knazarov.com"; + version = "0.1.0"; + + dontPatch = true; + + installFlags = "PREFIX=${placeholder "out"} VERSION=${version}"; + buildInputs = with pkgs; [ + gawk + gnused + rsync + ]; + + src = ./.; + +}