Add an example nixos config using this site

This commit is contained in:
Luka Korošec 2025-06-20 23:11:18 +02:00
parent 09a424d956
commit f2f8efdc1d
Signed by: Pizmovc
GPG key ID: 4E1338930C2F3572
4 changed files with 173 additions and 0 deletions

101
nixos-configuration/flake.lock generated Normal file
View file

@ -0,0 +1,101 @@
{
"nodes": {
"eleventy-src": {
"flake": false,
"locked": {
"lastModified": 1750429373,
"narHash": "sha256-8ht2rUBMnHHxavXUiDXvOZ+kAtoA3rkrkaaFyC04bUI=",
"owner": "11ty",
"repo": "eleventy",
"rev": "afa9d9b8b5398da35aa3fc375c08889bf29a5182",
"type": "github"
},
"original": {
"owner": "11ty",
"repo": "eleventy",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1750215678,
"narHash": "sha256-Rc/ytpamXRf6z8UA2SGa4aaWxUXRbX2MAWIu2C8M+ok=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "5395fb3ab3f97b9b7abca147249fa2e8ed27b192",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"our-site": {
"inputs": {
"eleventy-src": "eleventy-src",
"flake-utils": "flake-utils",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1750450809,
"narHash": "sha256-rGXq/J2nDfHqAIGCcfo7PkT1jWmJQ+oGjWiL5Z42Y4k=",
"ref": "main",
"rev": "ecb042ddbeb84b49910a324b671c924b47ec3509",
"shallow": true,
"type": "git",
"url": "ssh://gitea@gitea.kalu.blue/tech-blog/create-a-static-blog-with-nix.git"
},
"original": {
"ref": "main",
"shallow": true,
"type": "git",
"url": "ssh://gitea@gitea.kalu.blue/tech-blog/create-a-static-blog-with-nix.git"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs",
"our-site": "our-site"
}
},
"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",
"version": 7
}

View file

@ -0,0 +1,49 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
our-site = {
url = "git+ssh://gitea@gitea.kalu.blue/tech-blog/create-a-static-blog-with-nix.git?ref=main&shallow=1";
inputs.nixpkgs.follows = "nixpkgs"; # Will use the same Nixpkgs as the NixOS system
};
};
outputs =
{ self, nixpkgs, ... }@inputs:
{
nixosConfigurations.my-server-name = nixpkgs.lib.nixosSystem {
specialArgs = {
# These will be passed as arguments to the modules
inherit inputs;
};
modules = [
# Essential for test VM
{
virtualisation.vmVariant = {
virtualisation = {
memorySize = 2048;
cores = 2;
# Disable graphics to avoid gtk error
graphics = false;
};
};
# Create a user, so we can login and test
users.users.test = {
isNormalUser = true;
# Never use this, use `hashedPassword` instead
initialPassword = nixpkgs.lib.mkForce "123123";
# So we can use `sudo` mainly for `sudo shutdown now` and to be able to debug `caddy`
group = "wheel";
};
}
# Some configuration
{
nixpkgs.hostPlatform = "x86_64-linux";
system.stateVersion = "25.11";
}
./my-static-site.nix
];
};
};
}

View file

@ -0,0 +1,3 @@
# Run a the example config in a VM
vm:
nix run ".#nixosConfigurations.my-server-name.config.system.build.vm"

View file

@ -0,0 +1,20 @@
{ inputs, pkgs, ... }:
let
site-url = "example.com";
in
{
services.caddy = {
enable = true;
# Needs `http://` prefix so that it does not try to request TLS certificates and redirect to 443
virtualHosts."http://${site-url}".extraConfig = ''
file_server
root * ${inputs.our-site.packages."${pkgs.system}".default}
encode gzip
'';
};
environment.shellAliases = {
# Test our site
curl-site = "curl -H \"Host: ${site-url}\" localhost";
};
}