From 8c67177e87384b0c8b20f1407ea9005b6e303730 Mon Sep 17 00:00:00 2001 From: Yuriy Taraday Date: Mon, 25 Sep 2023 17:47:52 +0200 Subject: [PATCH 1/2] Update flake.lock in the example It's using old Nickel version that will be incompatible with future changes. --- examples/c-hello-world/flake.lock | 115 ++++++++++++++---------------- 1 file changed, 55 insertions(+), 60 deletions(-) diff --git a/examples/c-hello-world/flake.lock b/examples/c-hello-world/flake.lock index d462423e..8fece025 100644 --- a/examples/c-hello-world/flake.lock +++ b/examples/c-hello-world/flake.lock @@ -3,11 +3,11 @@ "advisory-db": { "flake": false, "locked": { - "lastModified": 1684292571, - "narHash": "sha256-OpCnswRyIATPNoiQR4O7jE7iAyI9dekG7HfYhgZI3aI=", + "lastModified": 1688825073, + "narHash": "sha256-fK2huTDGHJc/oZjZWhMZMAt1nQSuuY6p41Y2pudtJdM=", "owner": "rustsec", "repo": "advisory-db", - "rev": "0e97e6e71f0dd52b4b4e0ab3fa6e5e5dd72f852a", + "rev": "5ceeefcbbabf4b510ef8ede121d6dc57d1a1f7f8", "type": "github" }, "original": { @@ -28,11 +28,11 @@ "rust-overlay": "rust-overlay" }, "locked": { - "lastModified": 1687310026, - "narHash": "sha256-20RHFbrnC+hsG4Hyeg/58LvQAK7JWfFItTPFAFamu8E=", + "lastModified": 1693608196, + "narHash": "sha256-qs1rDvXXjrKdobPvTdn9qKjV0/RE2uqCCTHD/c6AAo8=", "owner": "ipetkov", "repo": "crane", - "rev": "116b32c30b5ff28e49f4fcbeeb1bbe3544593204", + "rev": "80432e15452e55a72403da3bc91837508a4ccae3", "type": "github" }, "original": { @@ -54,11 +54,11 @@ "rust-overlay": "rust-overlay_3" }, "locked": { - "lastModified": 1684468982, - "narHash": "sha256-EoC1N5sFdmjuAP3UOkyQujSOT6EdcXTnRw8hPjJkEgc=", + "lastModified": 1688772518, + "narHash": "sha256-ol7gZxwvgLnxNSZwFTDJJ49xVY5teaSvF7lzlo3YQfM=", "owner": "ipetkov", "repo": "crane", - "rev": "99de890b6ef4b4aab031582125b6056b792a4a30", + "rev": "8b08e96c9af8c6e3a2b69af5a7fa168750fcf88e", "type": "github" }, "original": { @@ -138,11 +138,11 @@ "systems": "systems_2" }, "locked": { - "lastModified": 1685518550, - "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", + "lastModified": 1689068808, + "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=", "owner": "numtide", "repo": "flake-utils", - "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", + "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4", "type": "github" }, "original": { @@ -156,11 +156,11 @@ "systems": "systems_3" }, "locked": { - "lastModified": 1687171271, - "narHash": "sha256-BJlq+ozK2B1sJDQXS3tzJM5a+oVZmi1q0FlBK/Xqv7M=", + "lastModified": 1692799911, + "narHash": "sha256-3eihraek4qL744EvQXsK1Ha6C3CR7nnT8X2qWap4RNk=", "owner": "numtide", "repo": "flake-utils", - "rev": "abfb11bd1aec8ced1c9bb9adfe68018230f4fb3c", + "rev": "f9e7cf818399d17d347f847525c5a5a8032e4e44", "type": "github" }, "original": { @@ -174,11 +174,11 @@ "systems": "systems_4" }, "locked": { - "lastModified": 1681202837, - "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", + "lastModified": 1687709756, + "narHash": "sha256-Y5wKlQSkgEK2weWdOu4J3riRd+kV/VCgHsqLNTTWQ/0=", "owner": "numtide", "repo": "flake-utils", - "rev": "cfacdce06f30d2b68473a46042957675eebb3401", + "rev": "dbabf0ca0c0c4bce6ea5eaf65af5cb694d2082c7", "type": "github" }, "original": { @@ -192,11 +192,11 @@ "systems": "systems_5" }, "locked": { - "lastModified": 1681202837, - "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", + "lastModified": 1687709756, + "narHash": "sha256-Y5wKlQSkgEK2weWdOu4J3riRd+kV/VCgHsqLNTTWQ/0=", "owner": "numtide", "repo": "flake-utils", - "rev": "cfacdce06f30d2b68473a46042957675eebb3401", + "rev": "dbabf0ca0c0c4bce6ea5eaf65af5cb694d2082c7", "type": "github" }, "original": { @@ -256,11 +256,11 @@ "topiary": "topiary" }, "locked": { - "lastModified": 1690820202, - "narHash": "sha256-PreZbPJbydpHDCP3hZS/a4QB2Pz1pDAuVfRXnCaMmhs=", + "lastModified": 1693991699, + "narHash": "sha256-TPS9sLQFogqVbWREN3ppb9sijHJepD54YcxmktqC33Q=", "owner": "tweag", "repo": "nickel", - "rev": "aa4bb20b3e612f7b9797f926df26e53440c3f288", + "rev": "be9269a44320a7d33d76415761d67ce386b0c58c", "type": "github" }, "original": { @@ -271,11 +271,11 @@ }, "nix-filter": { "locked": { - "lastModified": 1681154353, - "narHash": "sha256-MCJ5FHOlbfQRFwN0brqPbCunLEVw05D/3sRVoNVt2tI=", + "lastModified": 1687178632, + "narHash": "sha256-HS7YR5erss0JCaUijPeyg2XrisEb959FIct3n2TMGbE=", "owner": "numtide", "repo": "nix-filter", - "rev": "f529f42792ade8e32c4be274af6b6d60857fbee7", + "rev": "d90c75e8319d0dd9be67d933d8eb9d0894ec9174", "type": "github" }, "original": { @@ -286,11 +286,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1689008574, - "narHash": "sha256-VFMgyHDiqsGDkRg73alv6OdHJAqhybryWHv77bSCGIw=", + "lastModified": 1685931219, + "narHash": "sha256-8EWeOZ6LKQfgAjB/USffUSELPRjw88A+xTcXnOUvO5M=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "4a729ce4b1fe5ec4fffc71c67c96aa5184ebb462", + "rev": "7409480d5c8584a1a83c422530419efe4afb0d19", "type": "github" }, "original": { @@ -317,11 +317,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1687502512, - "narHash": "sha256-dBL/01TayOSZYxtY4cMXuNCBk8UMLoqRZA+94xiFpJA=", + "lastModified": 1693565476, + "narHash": "sha256-ya00zHt7YbPo3ve/wNZ/6nts61xt7wK/APa6aZAfey0=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "3ae20aa58a6c0d1ca95c9b11f59a2d12eebc511f", + "rev": "aa8aa7e2ea35ce655297e8322dc82bf77a31d04b", "type": "github" }, "original": { @@ -365,19 +365,14 @@ "inputs": { "flake-utils": "flake-utils", "nickel": "nickel", - "nixpkgs": "nixpkgs_4", - "topiary": [ - "organist", - "nickel", - "topiary" - ] + "nixpkgs": "nixpkgs_4" }, "locked": { - "lastModified": 1691591567, - "narHash": "sha256-g6HM9x+QiTJEpUu/pR79hRdo7/YGetS7MPYtbD3opLE=", + "lastModified": 1695631921, + "narHash": "sha256-LsV5CXtvFvtjLyBc0YsskeVWvG4S+eItAK4ftKNYBrs=", "owner": "nickel-lang", "repo": "organist", - "rev": "e01a9a9a169bcdbe1b21d12787b3f8fc988cc887", + "rev": "c83761ebdf3de3e6bd8fc184af6af7f00d5ddded", "type": "github" }, "original": { @@ -403,11 +398,11 @@ "nixpkgs-stable": "nixpkgs-stable" }, "locked": { - "lastModified": 1687251716, - "narHash": "sha256-+sFS41thsB5U+lY/dBYPSmU4AJ7nz/VdM1WD35fXVeM=", + "lastModified": 1692274144, + "narHash": "sha256-BxTQuRUANQ81u8DJznQyPmRsg63t4Yc+0kcyq6OLz8s=", "owner": "cachix", "repo": "pre-commit-hooks.nix", - "rev": "7807e1851d95828ed98491930d2d9e7ddbe65da4", + "rev": "7e3517c03d46159fdbf8c0e5c97f82d5d4b0c8fa", "type": "github" }, "original": { @@ -438,11 +433,11 @@ ] }, "locked": { - "lastModified": 1685759304, - "narHash": "sha256-I3YBH6MS3G5kGzNuc1G0f9uYfTcNY9NYoRc3QsykLk4=", + "lastModified": 1691374719, + "narHash": "sha256-HCodqnx1Mi2vN4f3hjRPc7+lSQy18vRn8xWW68GeQOg=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "c535b4f3327910c96dcf21851bbdd074d0760290", + "rev": "b520a3889b24aaf909e287d19d406862ced9ffc9", "type": "github" }, "original": { @@ -465,11 +460,11 @@ ] }, "locked": { - "lastModified": 1687573996, - "narHash": "sha256-F7pDERmi8MomkMhcUW88IW6RRrxAk7QO2PXs+LMpxpI=", + "lastModified": 1693620498, + "narHash": "sha256-GPhAI2YayaSs3WYeVVbGN3K4mvRTbui/ii7YGoABZBs=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "ec002586144fe0f48039dced270c188f0b8213ab", + "rev": "cdf3b15af70f2db17d5f47822f12016f1a89bd73", "type": "github" }, "original": { @@ -496,11 +491,11 @@ ] }, "locked": { - "lastModified": 1683080331, - "narHash": "sha256-nGDvJ1DAxZIwdn6ww8IFwzoHb2rqBP4wv/65Wt5vflk=", + "lastModified": 1688351637, + "narHash": "sha256-CLTufJ29VxNOIZ8UTg0lepsn3X03AmopmaLTTeHDCL4=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "d59c3fa0cba8336e115b376c2d9e91053aa59e56", + "rev": "f9b92316727af9e6c7fee4a761242f7f46880329", "type": "github" }, "original": { @@ -515,11 +510,11 @@ "nixpkgs": "nixpkgs_3" }, "locked": { - "lastModified": 1684808436, - "narHash": "sha256-WG5LgB1+Oguj4H4Bpqr5GoLSc382LyGlaToiOw5xhwA=", + "lastModified": 1689042658, + "narHash": "sha256-p7cQAFNt5kX19sZvK74CmY0nTrtujpZg6sZUiV1ntAk=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "a227d4571dd1f948138a40ea8b0d0c413eefb44b", + "rev": "d7181bb2237035df17cab9295c95f987f5c527e6", "type": "github" }, "original": { @@ -632,11 +627,11 @@ "rust-overlay": "rust-overlay_4" }, "locked": { - "lastModified": 1687343293, - "narHash": "sha256-y/kXyPN3dni8qAnAFvO0lWmJ6cWEcuJTt77NvR/BUGg=", + "lastModified": 1692863481, + "narHash": "sha256-DVtBD72proHmrcCXQWkfyecTYX9ugbd9cV8SD6VZoxk=", "owner": "tweag", "repo": "topiary", - "rev": "cba199369aca42cb00221a1ac0e27e9a02cf636f", + "rev": "577fe940aa0b9dae478b463bddd1238e20f86e3a", "type": "github" }, "original": { From 0a38264ced4def9499e669f342f3076eac2d7e2a Mon Sep 17 00:00:00 2001 From: Yuriy Taraday Date: Mon, 25 Sep 2023 16:43:37 +0200 Subject: [PATCH 2/2] Allow to specify some flake outputs from Nickel Add `flake` field to `project.ncl` that allows to specify certain flake outputs. For example, you can add lines like these to run `hello` as an app or a check: flake.apps.hello.program = nix-s%"%{import_nix "nixpkgs#hello"}/bin/hello"%, flake.checks.hello = import_nix "nixpkgs#hello", I will be gragually migrating apps and checks from our `flake.nix` to `project.ncl` using this. Part of https://github.com/nickel-lang/organist/issues/58 --- flake.nix | 29 ++++++++++++++++------------- lib/contracts.ncl | 8 ++++++++ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/flake.nix b/flake.nix index ce87588c..62bc8a09 100644 --- a/flake.nix +++ b/flake.nix @@ -35,21 +35,24 @@ flake-utils.lib.eachSystem systems (system: let lib = self.lib.${system}; pkgs = nixpkgs.legacyPackages.${system}; + nickelOutputs = lib.importNcl { + inherit baseDir flakeInputs lockFileContents; + }; in - { - apps.regenerate-lockfile = lib.regenerateLockFileApp lockFileContents; - } - // pkgs.lib.optionalAttrs (builtins.readDir baseDir ? "project.ncl") rec { - nickelOutputs = lib.importNcl { - inherit baseDir flakeInputs lockFileContents; - }; - packages = - if nickelOutputs ? packages && nickelOutputs.packages ? default - then { - default = nickelOutputs.packages.default; + # Can't do just `{inherit nickelOutputs;} // nickelOutputs.flake` because of infinite recursion over self + pkgs.lib.optionalAttrs (builtins.readDir baseDir ? "project.ncl") { + inherit nickelOutputs; + packages = nickelOutputs.packages or {} // nickelOutputs.flake.packages or {}; + checks = nickelOutputs.flake.checks or {}; + # Can't define this app in Nickel, yet + apps = + { + regenerate-lockfile = lib.regenerateLockFileApp lockFileContents; } - else {}; - devShells = nickelOutputs.shells or {}; + // nickelOutputs.flake.apps or {}; + # We can't just copy `shells` to `flake.devShells` in the contract + # because of a bug in Nickel: https://github.com/tweag/nickel/issues/1630 + devShells = nickelOutputs.shells or {} // nickelOutputs.flake.devShells or {}; }); computedOutputs = outputsFromNickel ./. inputs { diff --git a/lib/contracts.ncl b/lib/contracts.ncl index a6a74314..d81cc72f 100644 --- a/lib/contracts.ncl +++ b/lib/contracts.ncl @@ -309,6 +309,13 @@ from the Nix world) or a derivation defined in Nickel. "default" | NickelDerivation = dev, }, + FlakeOutputs = { + packages | { _ | Derivation } | optional, + checks | { _ | Derivation } | optional, + devShells | { _ | Derivation } | optional, + apps | { _ | { type = "app", program | NixString } } | optional, + }, + # TODO: have the actual contract for the result of an expression. It's pretty # open (could be an integer, a derivation, a record of derivations, etc.) but # it still obeys some rules: if the `type` field is set to a known predefined @@ -320,6 +327,7 @@ from the Nix world) or a derivation defined in Nickel. shells | OrganistShells | optional, + flake | FlakeOutputs | optional, .. }, }