diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5324687..2bc5ca3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -47,8 +47,8 @@ jobs: with: name: js2nix authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' - - name: Run tests in nix-shell - run: nix-shell --run 'jest' + - name: Run tests in nix develop + run: nix develop -c jest lock-diff: needs: [build, tests] runs-on: ubuntu-latest @@ -60,6 +60,6 @@ jobs: name: js2nix authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' - name: Generate Nix expression from the yarn.lock file - run: nix-shell --run 'js2nix --lock ./yarn.lock --out ./yarn.lock.nix' + run: nix develop -c js2nix --lock ./yarn.lock --out ./yarn.lock.nix - name: Check git diff run: git diff --exit-code HEAD diff --git a/build.nix b/build.nix deleted file mode 100644 index 84a0b69..0000000 --- a/build.nix +++ /dev/null @@ -1,10 +0,0 @@ -{ pkgs ? import (builtins.fetchTarball "https://github.com/NixOS/nixpkgs/archive/13e0d337037b3f59eccbbdf3bc1fe7b1e55c93fd.tar.gz") { } }: - -let - js2nix = pkgs.callPackage ./default.nix { }; -in { - inherit (js2nix) - bin - proxy - node-gyp; -} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..5157471 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1653910874, + "narHash": "sha256-Jv+GDO2OKvSdMPgPkvE/j/QoVi4szWJ6G/UXJH1SdIA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "13e0d337037b3f59eccbbdf3bc1fe7b1e55c93fd", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "13e0d337037b3f59eccbbdf3bc1fe7b1e55c93fd", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..762eebd --- /dev/null +++ b/flake.nix @@ -0,0 +1,46 @@ +{ + description = "A js2nix flake"; + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs?rev=13e0d337037b3f59eccbbdf3bc1fe7b1e55c93fd"; + }; + + outputs = { self, nixpkgs }: + let + supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ]; + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + in + rec { + packages = forAllSystems (system: + let + pkgs' = nixpkgs.legacyPackages.${system}; + js2nix = pkgs'.callPackage ./. { }; + in + { + default = js2nix; + js2nix = js2nix.bin; + inherit (js2nix) proxy node-gyp; + }); + + devShells = forAllSystems (system: + let + pkgs' = nixpkgs.legacyPackages.${system}; + flakePkgs = packages.${system}; + env = flakePkgs.default { + package-json = ./package.json; + yarn-lock = ./yarn.lock; + }; + in + { + default = pkgs'.mkShellNoCC { + passthru.env = env; + packages = with pkgs'; [ + (env.nodeModules.override { prefix = "/lib/node_modules"; }) + nodejs + flakePkgs.js2nix + flakePkgs.node-gyp + flakePkgs.proxy + ]; + }; + }); + }; +} diff --git a/package.nix b/package.nix index 6d97582..2711d64 100644 --- a/package.nix +++ b/package.nix @@ -1,2 +1,17 @@ -let shell = import ./shell.nix { }; -in shell.env.nodeModules +{ pkgs ? ( + let + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + source = builtins.fetchTarball "https://github.com/NixOS/nixpkgs/archive/${lock.nodes.nixpkgs.locked.rev}.tar.gz"; + in + import source { } + ) +}: + +let + js2nix = pkgs.callPackage ./. { }; + env = js2nix { + package-json = ./package.json; + yarn-lock = ./yarn.lock; + }; +in +env.nodeModules diff --git a/shell.nix b/shell.nix deleted file mode 100644 index d2b5652..0000000 --- a/shell.nix +++ /dev/null @@ -1,28 +0,0 @@ -{ pkgs ? import - ( - builtins.fetchTarball "https://github.com/NixOS/nixpkgs/archive/13e0d337037b3f59eccbbdf3bc1fe7b1e55c93fd.tar.gz" - ) - { } -}: - -let - js2nix = pkgs.callPackage ./default.nix { }; - env = js2nix { - package-json = ./package.json; - yarn-lock = ./yarn.lock; - }; -in -pkgs.mkShell { - # Give the nix-build access to resulting artifact directly with an a standart folder - # structure instead of the structure that would be picked up by nodejs pachage setup-hook. - # To create a folder type: - # nix-build -o ./node_modules -A env.nodeModules ./shell.nix - passthru.env = env; - buildInputs = [ - (env.nodeModules.override { prefix = "/lib/node_modules"; }) - pkgs.nodejs - js2nix.bin - js2nix.proxy - js2nix.node-gyp - ]; -}