diff --git a/core/WORKSPACE b/core/WORKSPACE index c992e4734..ddfa59e74 100644 --- a/core/WORKSPACE +++ b/core/WORKSPACE @@ -47,7 +47,7 @@ nixpkgs_local_repository( nix_file_content = "import ./nixpkgs.nix", nix_file_deps = [ "//:nixpkgs.nix", - "//:nixpkgs.json", + "//:flake.lock", ], ) @@ -72,7 +72,7 @@ nixpkgs_package( nixpkgs_package( name = "expr-test", nix_file_content = "let pkgs = import { 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"}, ) @@ -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", ], @@ -155,7 +155,7 @@ nixpkgs_package( attribute_path = "", nix_file_content = """let pkgs = import { config = {}; overlays = []; }; in pkgs.writeText "foo" "bar" """, nix_file_deps = [ - "//:nixpkgs.json", + "//:flake.lock", "//:nixpkgs.nix", "//tests:relative_imports/nixpkgs.nix", ], diff --git a/core/docs/dependencies_2.bzl b/core/docs/dependencies_2.bzl index 37cf1be5e..ca6c38cae 100644 --- a/core/docs/dependencies_2.bzl +++ b/core/docs/dependencies_2.bzl @@ -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() diff --git a/core/flake.lock b/core/flake.lock new file mode 120000 index 000000000..1985b6556 --- /dev/null +++ b/core/flake.lock @@ -0,0 +1 @@ +../flake.lock \ No newline at end of file diff --git a/core/nixpkgs.json b/core/nixpkgs.json deleted file mode 100644 index 524887447..000000000 --- a/core/nixpkgs.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "owner": "NixOS", - "repo": "nixpkgs", - "branch": "22.05", - "rev": "ce6aa13369b667ac2542593170993504932eb836", - "sha256": "0d643wp3l77hv2pmg2fi7vyxn4rwy0iyr8djcw1h5x72315ck9ik" -} diff --git a/core/nixpkgs.nix b/core/nixpkgs.nix index 120a30c38..5b3a2a3b8 100644 --- a/core/nixpkgs.nix +++ b/core/nixpkgs.nix @@ -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 diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..9ab1863d3 --- /dev/null +++ b/flake.lock @@ -0,0 +1,60 @@ +{ + "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1650374568, + "narHash": "sha256-Z+s0J8/r907g149rllvwhb4pKi8Wam5ij0st8PwAh+E=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "b4a34015c698c7793d592d66adbab377907a2be8", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1662099760, + "narHash": "sha256-MdZLCTJPeHi/9fg6R9fiunyDwP3XHJqDd51zWWz9px0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "67e45078141102f45eff1589a831aeaa3182b41e", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-22.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..6d28fccec --- /dev/null +++ b/flake.nix @@ -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 ]; + }; + }); +} diff --git a/shell.nix b/shell.nix index 59c9d0fd0..a8e628cca 100644 --- a/shell.nix +++ b/shell.nix @@ -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 ]; -}