From 16b429be54eaf41f2588b508033373f3932638f2 Mon Sep 17 00:00:00 2001 From: Ivan Reshetnikov Date: Fri, 23 Feb 2024 22:17:15 +0500 Subject: [PATCH] feat(nix): write a working nix flake --- flake.lock | 34 ++++++++++++++++++++++++++++++++++ flake.nix | 52 +++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 73 insertions(+), 13 deletions(-) diff --git a/flake.lock b/flake.lock index 69da053..672d496 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,23 @@ { "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1708566995, @@ -18,8 +36,24 @@ }, "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", diff --git a/flake.nix b/flake.nix index bf9cd71..7254cd0 100644 --- a/flake.nix +++ b/flake.nix @@ -3,19 +3,45 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-23.11"; + flake-utils.url = "github:numtide/flake-utils"; }; - outputs = { self, nixpkgs }: - let - system = "x86_64-linux"; - pkgs = nixpkgs.legacyPackages.${system}; - in - { - devShells.${system}.default = pkgs.mkShell { - buildInputs = [ - pkgs.nodejs_20 - pkgs.imagemagick - ]; - }; - }; + outputs = { self, nixpkgs, flake-utils }: flake-utils.lib.eachDefaultSystem (system: + let + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; + packageName = "comfycamp"; + in + { + devShells.default = pkgs.mkShell { + buildInputs = [ + pkgs.nodejs_20 + pkgs.imagemagick + ]; + }; + + + packages.${packageName} = pkgs.buildNpmPackage { + name = "${packageName}"; + + src = ./.; + npmDepsHash = "sha256-Nprdi+LX7/fSnrxeJzkbHX13FKM172E8wy6L+nxC/iE="; + + buildInputs = [ + pkgs.nodejs_20 + pkgs.vips # required by sharp + ]; + nativeBuildInputs = [ + pkgs.pkg-config # required by sharp + ]; + installPhase = '' + mkdir $out + npm run build + cp -r dist/* $out + ''; + }; + + defaultPackage = self.packages.${system}.${packageName}; + } + ); }