commit for the blog

Signed-off-by: Xe <me@christine.website>
This commit is contained in:
Cadey Ratio 2022-02-27 18:37:44 +00:00
parent 704487ba63
commit 1e692d6117
4 changed files with 66 additions and 6 deletions

View File

@ -15,9 +15,26 @@
"type": "indirect"
}
},
"portable-svc": {
"locked": {
"lastModified": 1645960986,
"narHash": "sha256-XuapDz2dkUAgKaj3L2EUgzXApn6IXGtQVg/TEfhr0w8=",
"ref": "main",
"rev": "138c25c1c3ee4f7945059e05259d3fe03678e843",
"revCount": 5,
"type": "git",
"url": "https://tulpa.dev/cadey/portable-svc.git"
},
"original": {
"ref": "main",
"type": "git",
"url": "https://tulpa.dev/cadey/portable-svc.git"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs",
"portable-svc": "portable-svc",
"utils": "utils"
}
},

View File

@ -4,9 +4,10 @@
inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable";
utils.url = "github:numtide/flake-utils";
portable-svc.url = "git+https://tulpa.dev/cadey/portable-svc.git?ref=main";
};
outputs = { self, nixpkgs, utils }:
outputs = { self, nixpkgs, utils, portable-svc }:
utils.lib.eachSystem [
"x86_64-linux"
"aarch64-linux"
@ -14,11 +15,14 @@
"aarch64-darwin"
] (system:
let
pkgs = nixpkgs.legacyPackages.${system};
pkgs = import nixpkgs {
overlays = [ portable-svc.overlay ];
inherit system;
};
version = builtins.substring 0 8 self.lastModifiedDate;
in {
defaultPackage = pkgs.buildGoModule {
pname = "go-hello";
pname = "web-server";
inherit version;
src = ./.;
@ -34,9 +38,38 @@
vendorSha256 = "sha256-pQpattmS9VmO3ZIQUFn66az8GSmB4IvYhTTCFn6SUmo=";
};
packages = {};
packages = {
docker = let
web = self.defaultPackage.${system};
in pkgs.dockerTools.buildLayeredImage {
name = web.pname;
tag = web.version;
contents = [ web ];
defaultApp = self.defaultPackage.${system};
config = {
Cmd = [ "/bin/web-server" ];
WorkingDir = "/";
};
};
web-service = pkgs.substituteAll {
name = "web-server.service";
src = ./systemd/web-server.service.in;
web = self.defaultPackage.${system};
};
portable = let
web = self.defaultPackage.${system};
in pkgs.portableService {
inherit (web) version;
name = web.pname;
description = "A web server";
units = [ self.packages.${system}.web-service ];
};
};
defaultApp = utils.lib.mkApp {
drv = self.defaultPackage.${system};
};
devShell = pkgs.mkShell {
buildInputs = with pkgs; [ go gopls goimports go-tools ];

View File

@ -5,6 +5,7 @@ import (
"fmt"
"log"
"net/http"
"os"
)
var (
@ -15,7 +16,7 @@ func main() {
flag.Parse()
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "hello from nix!")
fmt.Fprintf(w, "PORTABLE=%s\n", os.Getenv("PORTABLE"))
})
log.Printf("listening for HTTP on %s", *bindhost)

View File

@ -0,0 +1,9 @@
[Unit]
Description=A web service
[Service]
DynamicUser=yes
ExecStart=@web@/bin/web-server
[Install]
WantedBy=multi-user.target