Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduce flake #15

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
10 changes: 0 additions & 10 deletions build.nix

This file was deleted.

27 changes: 27 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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;
Copy link

@blaggacao blaggacao May 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd sort of expect this to be in a lib.${system} namespace. "Semantics over impl-detail [that it is system scoped]"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

potentially even make that function curriable with an instance of pkgs:

lib.js2nix pkgs {
      package-json = ./package.json;
      yarn-lock = ./yarn.lock;
}

I always feel immediately at home when there is special consideration put to the handling of pkgs instance. 😄

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback around the lib namespace @blaggacao, that's good point! I'll incorporate it in coming commit.

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
];
};
});
};
}
19 changes: 17 additions & 2 deletions package.nix
Original file line number Diff line number Diff line change
@@ -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
28 changes: 0 additions & 28 deletions shell.nix

This file was deleted.