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

Convert to flake #265

Merged
merged 3 commits into from
Sep 15, 2022
Merged
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
8 changes: 4 additions & 4 deletions core/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ nixpkgs_local_repository(
nix_file_content = "import ./nixpkgs.nix",
nix_file_deps = [
"//:nixpkgs.nix",
"//:nixpkgs.json",
"//:flake.lock",
],
)

Expand All @@ -72,7 +72,7 @@ nixpkgs_package(
nixpkgs_package(
name = "expr-test",
nix_file_content = "let pkgs = import <nixpkgs> { config = {}; overlays = []; }; in pkgs.hello",
nix_file_deps = ["//:nixpkgs.json"],
nix_file_deps = ["//:flake.lock"],
# Deliberately not @nixpkgs, to test whether explict file works.
repositories = {"nixpkgs": "//:nixpkgs.nix"},
)
Expand Down Expand Up @@ -141,7 +141,7 @@ nixpkgs_package(
attribute_path = "hello",
nix_file = "//tests:relative_imports.nix",
nix_file_deps = [
"//:nixpkgs.json",
"//:flake.lock",
"//:nixpkgs.nix",
"//tests:relative_imports/nixpkgs.nix",
],
Expand All @@ -155,7 +155,7 @@ nixpkgs_package(
attribute_path = "",
nix_file_content = """let pkgs = import <nixpkgs> { config = {}; overlays = []; }; in pkgs.writeText "foo" "bar" """,
nix_file_deps = [
"//:nixpkgs.json",
"//:flake.lock",
"//:nixpkgs.nix",
"//tests:relative_imports/nixpkgs.nix",
],
Expand Down
2 changes: 1 addition & 1 deletion core/docs/dependencies_2.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def docs_dependencies_2():
nixpkgs_local_repository(
name = "nixpkgs",
nix_file = "@rules_nixpkgs_core//:nixpkgs.nix",
nix_file_deps = ["@rules_nixpkgs_core//:nixpkgs.json"],
nix_file_deps = ["@rules_nixpkgs_core//:flake.lock"],
)

rules_sh_dependencies()
Expand Down
1 change: 1 addition & 0 deletions core/flake.lock

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

7 changes: 0 additions & 7 deletions core/nixpkgs.json

This file was deleted.

14 changes: 8 additions & 6 deletions core/nixpkgs.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
let
# nixpkgs 21.11
spec = builtins.fromJSON (builtins.readFile ./nixpkgs.json);
nixpkgs = fetchTarball {
url = "https://github.com/${spec.owner}/${spec.repo}/archive/${spec.rev}.tar.gz";
sha256 = spec.sha256;
};
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
src = lock.nodes.nixpkgs.locked;
nixpkgs =
assert src.type == "github";
fetchTarball {
url = "https://github.com/${src.owner}/${src.repo}/archive/${src.rev}.tar.gz";
sha256 = src.narHash;
};
in
import nixpkgs
60 changes: 60 additions & 0 deletions flake.lock

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

21 changes: 21 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.05";
flake-compat = {
url = github:edolstra/flake-compat;
flake = false;
};
flake-utils.url = github:numtide/flake-utils;
};
outputs = { nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
in
{
devShells.default = with pkgs; mkShell {
name = "rules_nixpkgs_shell";
packages = [ bazel_5 bazel-buildtools cacert gcc nix git ];
};
});
}
20 changes: 10 additions & 10 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{ pkgs ? import ./core/nixpkgs.nix {
config = { };
overlays = [ ];
} }:
(import
(
let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
)
{ src = ./.; }
).shellNix

with pkgs;

mkShell {
name = "rules_nixpkgs_shell";
packages = [ bazel_5 bazel-buildtools cacert gcc nix git ];
}