浏览代码

Nix flake

Joeri Exelmans 2 年之前
父节点
当前提交
24a2448866
共有 2 个文件被更改,包括 117 次插入0 次删除
  1. 61 0
      flake.lock
  2. 56 0
      flake.nix

+ 61 - 0
flake.lock

@@ -0,0 +1,61 @@
+{
+  "nodes": {
+    "flake-utils": {
+      "inputs": {
+        "systems": "systems"
+      },
+      "locked": {
+        "lastModified": 1681202837,
+        "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=",
+        "owner": "numtide",
+        "repo": "flake-utils",
+        "rev": "cfacdce06f30d2b68473a46042957675eebb3401",
+        "type": "github"
+      },
+      "original": {
+        "owner": "numtide",
+        "repo": "flake-utils",
+        "type": "github"
+      }
+    },
+    "nixpkgs": {
+      "locked": {
+        "lastModified": 1681920287,
+        "narHash": "sha256-+/d6XQQfhhXVfqfLROJoqj3TuG38CAeoT6jO1g9r1k0=",
+        "owner": "NixOS",
+        "repo": "nixpkgs",
+        "rev": "645bc49f34fa8eff95479f0345ff57e55b53437e",
+        "type": "github"
+      },
+      "original": {
+        "owner": "NixOS",
+        "ref": "nixos-unstable",
+        "repo": "nixpkgs",
+        "type": "github"
+      }
+    },
+    "root": {
+      "inputs": {
+        "flake-utils": "flake-utils",
+        "nixpkgs": "nixpkgs"
+      }
+    },
+    "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
+}

+ 56 - 0
flake.nix

@@ -0,0 +1,56 @@
+{
+  inputs = {
+    nixpkgs.url = github:NixOS/nixpkgs/nixos-unstable;
+    flake-utils.url = github:numtide/flake-utils;
+  };
+
+  outputs = { self, nixpkgs, flake-utils }:
+    flake-utils.lib.eachDefaultSystem (system:
+      let
+        pkgs = nixpkgs.legacyPackages.${system};
+      in rec {
+      packages = rec {
+        # Just the contents of src/main/webapp
+        webRoot = pkgs.stdenv.mkDerivation {
+          name = "drawio-msdl";
+          src = ./src/main/webapp;
+          installPhase = ''
+            mkdir -p $out/share
+            cp -r $src/* $out/share
+          '';
+        };
+        # Absolute minimal web server serving 'webRoot'
+        staticServer = pkgs.stdenv.mkDerivation rec {
+          name = "drawio-msdl-staticserver";
+          src = ./src/main/webapp;
+          lighttpConfig = pkgs.writeTextFile {
+            name = "lighttpd.conf";
+            text = ''
+              server.document-root = "${webRoot}/share"
+              server.port = 8700
+              server.upload-dirs = ( "/tmp" )
+              index-file.names = ( "index.html" )
+              mimetype.assign = (
+                ".html" => "text/html", 
+                ".txt" => "text/plain",
+                ".xml" => "text/xml",
+                ".css" => "text/css",
+                ".jpg" => "image/jpeg",
+                ".png" => "image/png",
+                ".webp" => "image/webp",
+                ".svg" => "image/svg+xml",
+                ".js" => "application/javascript",
+              )
+            '';
+          };
+          script = pkgs.writeShellScript "drawio-msdl-staticserver.sh" ''            exec ${pkgs.lighttpd}/bin/lighttpd -f ${lighttpConfig} -D
+          '';
+          installPhase = ''
+            mkdir -p $out/bin
+            ln -s ${script} $out/bin/drawio-msdl-staticserver
+          '';
+        };
+      };
+      defaultPackage = packages.webRoot;
+    });
+}