From f3b4c3fd4f2929a3d1e6e9b24a5ea6a5d6426b59 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Mon, 26 Jun 2023 12:32:36 -0400 Subject: [PATCH] Port to dream2nix --- bin/run | 3 - default.nix | 13 -- flake.lock | 473 +++++++++++++++++++++++++++++++++++++++++----------- flake.nix | 96 ++++++++--- 4 files changed, 450 insertions(+), 135 deletions(-) delete mode 100755 bin/run delete mode 100644 default.nix diff --git a/bin/run b/bin/run deleted file mode 100755 index a227217..0000000 --- a/bin/run +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash -set -xe -exec nix-shell --run 'cargo watch -x run' diff --git a/default.nix b/default.nix deleted file mode 100644 index 873ece4..0000000 --- a/default.nix +++ /dev/null @@ -1,13 +0,0 @@ -(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 = ./.; - }).defaultNix diff --git a/flake.lock b/flake.lock index f37bb1a..6b4875d 100644 --- a/flake.lock +++ b/flake.lock @@ -1,35 +1,47 @@ { "nodes": { + "all-cabal-json": { + "flake": false, + "locked": { + "lastModified": 1665552503, + "narHash": "sha256-r14RmRSwzv5c+bWKUDaze6pXM7nOsiz1H8nvFHJvufc=", + "owner": "nix-community", + "repo": "all-cabal-json", + "rev": "d7c0434eebffb305071404edcf9d5cd99703878e", + "type": "github" + }, + "original": { + "owner": "nix-community", + "ref": "hackage", + "repo": "all-cabal-json", + "type": "github" + } + }, "crane": { "flake": false, "locked": { - "lastModified": 1644785799, - "narHash": "sha256-VpAJO1L0XeBvtCuNGK4IDKp6ENHIpTrlaZT7yfBCvwo=", + "lastModified": 1681175776, + "narHash": "sha256-7SsUy9114fryHAZ8p1L6G6YSu7jjz55FddEwa2U8XZc=", "owner": "ipetkov", "repo": "crane", - "rev": "fc7a94f841347c88f2cb44217b2a3faa93e2a0b2", + "rev": "445a3d222947632b5593112bb817850e8a9cf737", "type": "github" }, "original": { "owner": "ipetkov", + "ref": "v0.12.1", "repo": "crane", "type": "github" } }, "devshell": { - "inputs": { - "flake-utils": "flake-utils", - "nixpkgs": [ - "nci", - "nixpkgs" - ] - }, + "flake": false, "locked": { - "lastModified": 1650900878, - "narHash": "sha256-qhNncMBSa9STnhiLfELEQpYC1L4GrYHNIzyCZ/pilsI=", + "lastModified": 1663445644, + "narHash": "sha256-+xVlcK60x7VY1vRJbNUEAHi17ZuoQxAIH4S4iUFUGBA=", "owner": "numtide", "repo": "devshell", - "rev": "d97df53b5ddaa1cfbea7cddbd207eb2634304733", + "rev": "e3dc3e21594fe07bdb24bdf1c8657acaa4cb8f66", "type": "github" }, "original": { @@ -40,46 +52,29 @@ }, "dream2nix": { "inputs": { - "alejandra": [ - "nci", - "nixpkgs" - ], + "all-cabal-json": "all-cabal-json", "crane": "crane", - "flake-utils-pre-commit": [ - "nci", - "nixpkgs" - ], - "gomod2nix": [ - "nci", - "nixpkgs" - ], - "mach-nix": [ - "nci", - "nixpkgs" - ], - "nixpkgs": [ - "nci", - "nixpkgs" - ], - "node2nix": [ - "nci", - "nixpkgs" - ], - "poetry2nix": [ - "nci", - "nixpkgs" - ], - "pre-commit-hooks": [ - "nci", - "nixpkgs" - ] + "devshell": "devshell", + "drv-parts": "drv-parts", + "flake-compat": "flake-compat", + "flake-parts": "flake-parts", + "flake-utils-pre-commit": "flake-utils-pre-commit", + "ghc-utils": "ghc-utils", + "gomod2nix": "gomod2nix", + "mach-nix": "mach-nix", + "nix-pypi-fetcher": "nix-pypi-fetcher", + "nixpkgs": "nixpkgs", + "nixpkgsV1": "nixpkgsV1", + "poetry2nix": "poetry2nix", + "pre-commit-hooks": "pre-commit-hooks", + "pruned-racket-catalog": "pruned-racket-catalog" }, "locked": { - "lastModified": 1651844867, - "narHash": "sha256-a+bAmmeIudRVY23ZkEB5W5xJumBY3ydsiDIGN/56NmQ=", + "lastModified": 1687429612, + "narHash": "sha256-lVQlsVmWLQt+bgckBjiKxcqq2Jx1RYxyI3zmtdQ5Acs=", "owner": "nix-community", "repo": "dream2nix", - "rev": "e5d0e9cdb00695b0b63d1f52ff3b39c0e3035fe3", + "rev": "6b750b01385718a6a84231d3c5451308978fa7de", "type": "github" }, "original": { @@ -88,14 +83,43 @@ "type": "github" } }, + "drv-parts": { + "inputs": { + "flake-compat": [ + "dream2nix", + "flake-compat" + ], + "flake-parts": [ + "dream2nix", + "flake-parts" + ], + "nixpkgs": [ + "dream2nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1680698112, + "narHash": "sha256-FgnobN/DvCjEsc0UAZEAdPLkL4IZi2ZMnu2K2bUaElc=", + "owner": "davhau", + "repo": "drv-parts", + "rev": "e8c2ec1157dc1edb002989669a0dbd935f430201", + "type": "github" + }, + "original": { + "owner": "davhau", + "repo": "drv-parts", + "type": "github" + } + }, "flake-compat": { "flake": false, "locked": { - "lastModified": 1650374568, - "narHash": "sha256-Z+s0J8/r907g149rllvwhb4pKi8Wam5ij0st8PwAh+E=", + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", "owner": "edolstra", "repo": "flake-compat", - "rev": "b4a34015c698c7793d592d66adbab377907a2be8", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", "type": "github" }, "original": { @@ -104,51 +128,208 @@ "type": "github" } }, - "flake-utils": { - "locked": { - "lastModified": 1642700792, - "narHash": "sha256-XqHrk7hFb+zBvRg6Ghl+AZDq03ov6OshJLiSWOoX5es=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "846b2ae0fc4cc943637d3d1def4454213e203cba", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "nci": { + "flake-parts": { "inputs": { - "devshell": "devshell", - "dream2nix": "dream2nix", - "nixpkgs": [ + "nixpkgs-lib": [ + "dream2nix", "nixpkgs" - ], - "rustOverlay": "rustOverlay" + ] }, "locked": { - "lastModified": 1651990362, - "narHash": "sha256-Yw32A18l9hx/+19PcUhuoOLuBXtlrFoea7OAM3R4pzs=", - "owner": "yusdacra", - "repo": "nix-cargo-integration", - "rev": "d187cd7b1e8c85521c3bad633a79fd25f584f42e", + "lastModified": 1675933616, + "narHash": "sha256-/rczJkJHtx16IFxMmAWu5nNYcSXNg1YYXTHoGjLrLUA=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "47478a4a003e745402acf63be7f9a092d51b83d7", "type": "github" }, "original": { - "owner": "yusdacra", - "repo": "nix-cargo-integration", + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "flake-parts_2": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1687762428, + "narHash": "sha256-DIf7mi45PKo+s8dOYF+UlXHzE0Wl/+k3tXUyAoAnoGE=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "37dd7bb15791c86d55c5121740a1887ab55ee836", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "flake-root": { + "locked": { + "lastModified": 1680964220, + "narHash": "sha256-dIdTYcf+KW9a4pKHsEbddvLVSfR1yiAJynzg2x0nfWg=", + "owner": "srid", + "repo": "flake-root", + "rev": "f1c0b93d05bdbea6c011136ba1a135c80c5b326c", + "type": "github" + }, + "original": { + "owner": "srid", + "repo": "flake-root", + "type": "github" + } + }, + "flake-utils-pre-commit": { + "locked": { + "lastModified": 1644229661, + "narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "ghc-utils": { + "flake": false, + "locked": { + "lastModified": 1662774800, + "narHash": "sha256-1Rd2eohGUw/s1tfvkepeYpg8kCEXiIot0RijapUjAkE=", + "ref": "refs/heads/master", + "rev": "bb3a2d3dc52ff0253fb9c2812bd7aa2da03e0fea", + "revCount": 1072, + "type": "git", + "url": "https://gitlab.haskell.org/bgamari/ghc-utils" + }, + "original": { + "type": "git", + "url": "https://gitlab.haskell.org/bgamari/ghc-utils" + } + }, + "gomod2nix": { + "flake": false, + "locked": { + "lastModified": 1627572165, + "narHash": "sha256-MFpwnkvQpauj799b4QTBJQFEddbD02+Ln5k92QyHOSk=", + "owner": "tweag", + "repo": "gomod2nix", + "rev": "67f22dd738d092c6ba88e420350ada0ed4992ae8", + "type": "github" + }, + "original": { + "owner": "tweag", + "repo": "gomod2nix", + "type": "github" + } + }, + "mach-nix": { + "flake": false, + "locked": { + "lastModified": 1634711045, + "narHash": "sha256-m5A2Ty88NChLyFhXucECj6+AuiMZPHXNbw+9Kcs7F6Y=", + "owner": "DavHau", + "repo": "mach-nix", + "rev": "4433f74a97b94b596fa6cd9b9c0402104aceef5d", + "type": "github" + }, + "original": { + "id": "mach-nix", + "type": "indirect" + } + }, + "mission-control": { + "locked": { + "lastModified": 1683658484, + "narHash": "sha256-JkGnWyYZxOnyOhztrxLSqaod6+O/3rRypq0dAqA/zn0=", + "owner": "Platonic-Systems", + "repo": "mission-control", + "rev": "a0c93bd764a3c25e6999397e9f5f119c1b124e38", + "type": "github" + }, + "original": { + "owner": "Platonic-Systems", + "repo": "mission-control", + "type": "github" + } + }, + "nix-pypi-fetcher": { + "flake": false, + "locked": { + "lastModified": 1669065297, + "narHash": "sha256-UStjXjNIuIm7SzMOWvuYWIHBkPUKQ8Id63BMJjnIDoA=", + "owner": "DavHau", + "repo": "nix-pypi-fetcher", + "rev": "a9885ac6a091576b5195d547ac743d45a2a615ac", + "type": "github" + }, + "original": { + "owner": "DavHau", + "repo": "nix-pypi-fetcher", "type": "github" } }, "nixpkgs": { "locked": { - "lastModified": 1651558728, - "narHash": "sha256-8HzyRnWlgZluUrVFNOfZAOlA1fghpOSezXvxhalGMUo=", + "lastModified": 1665580254, + "narHash": "sha256-hO61XPkp1Hphl4HGNzj1VvDH5URt7LI6LaY/385Eul4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "f634d427b0224a5f531ea5aa10c3960ba6ec5f0f", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-unstable", + "type": "indirect" + } + }, + "nixpkgs-lib": { + "locked": { + "dir": "lib", + "lastModified": 1685564631, + "narHash": "sha256-8ywr3AkblY4++3lIVxmrWZFzac7+f32ZEhH/A8pNscI=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "4f53efe34b3a8877ac923b9350c874e3dcd5dc0a", + "type": "github" + }, + "original": { + "dir": "lib", + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgsV1": { + "locked": { + "lastModified": 1686501370, + "narHash": "sha256-G0WuM9fqTPRc2URKP9Lgi5nhZMqsfHGrdEbrLvAPJcg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "75a5ebf473cd60148ba9aec0d219f72e5cf52519", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-unstable", + "type": "indirect" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1687681650, + "narHash": "sha256-M2If+gRcfpmaJy/XbfSsRzLlPpoU4nr0NHnKKl50fd8=", "owner": "nixos", "repo": "nixpkgs", - "rev": "cbe587c735b734405f56803e267820ee1559e6c1", + "rev": "1c9db9710cb23d60570ad4d7ab829c2d34403de3", "type": "github" }, "original": { @@ -158,26 +339,122 @@ "type": "github" } }, - "root": { - "inputs": { - "flake-compat": "flake-compat", - "nci": "nci", - "nixpkgs": "nixpkgs" - } - }, - "rustOverlay": { - "flake": false, + "nixpkgs_3": { "locked": { - "lastModified": 1651977622, - "narHash": "sha256-M3vm6mz+ypilmw3hkA6/GyDHH7ID85jWqeE9rtPWe8k=", - "owner": "oxalica", - "repo": "rust-overlay", - "rev": "c66fab76467a5df683ef50724a7bde54c315f967", + "lastModified": 1680945546, + "narHash": "sha256-8FuaH5t/aVi/pR1XxnF0qi4WwMYC+YxlfdsA0V+TEuQ=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "d9f759f2ea8d265d974a6e1259bd510ac5844c5d", "type": "github" }, "original": { - "owner": "oxalica", - "repo": "rust-overlay", + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "poetry2nix": { + "flake": false, + "locked": { + "lastModified": 1666918719, + "narHash": "sha256-BkK42fjAku+2WgCOv2/1NrPa754eQPV7gPBmoKQBWlc=", + "owner": "nix-community", + "repo": "poetry2nix", + "rev": "289efb187123656a116b915206e66852f038720e", + "type": "github" + }, + "original": { + "owner": "nix-community", + "ref": "1.36.0", + "repo": "poetry2nix", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-utils": [ + "dream2nix", + "flake-utils-pre-commit" + ], + "nixpkgs": [ + "dream2nix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1646153636, + "narHash": "sha256-AlWHMzK+xJ1mG267FdT8dCq/HvLCA6jwmx2ZUy5O8tY=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "b6bc0b21e1617e2b07d8205e7fae7224036dfa4b", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "pruned-racket-catalog": { + "flake": false, + "locked": { + "lastModified": 1672537287, + "narHash": "sha256-SuOvXVcLfakw18oJB/PuRMyvGyGG1+CQD3R+TGHIv44=", + "owner": "nix-community", + "repo": "pruned-racket-catalog", + "rev": "c8b89557fb53b36efa2ee48a769c7364df0f6262", + "type": "github" + }, + "original": { + "owner": "nix-community", + "ref": "catalog", + "repo": "pruned-racket-catalog", + "type": "github" + } + }, + "root": { + "inputs": { + "dream2nix": "dream2nix", + "flake-parts": "flake-parts_2", + "flake-root": "flake-root", + "mission-control": "mission-control", + "nixpkgs": "nixpkgs_2", + "systems": "systems", + "treefmt-nix": "treefmt-nix" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": "nixpkgs_3" + }, + "locked": { + "lastModified": 1687600980, + "narHash": "sha256-Tbu9Hj7JVX+rCYyUPJNQTPQqw382ahAFNoDVTrXnjFk=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "b100498935f04a70605dfde0edc6e311d865b869", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", "type": "github" } } diff --git a/flake.nix b/flake.nix index c3a2966..c7a1aaf 100644 --- a/flake.nix +++ b/flake.nix @@ -1,30 +1,84 @@ -# This file is pretty general, and you can adapt it in your project replacing -# only `name` and `description` below. - { - description = "My awesome Rust project"; - inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; - flake-compat = { - url = "github:edolstra/flake-compat"; - flake = false; - }; - nci.url = "github:yusdacra/nix-cargo-integration"; - nci.inputs.nixpkgs.follows = "nixpkgs"; + flake-parts.url = "github:hercules-ci/flake-parts"; + systems.url = "github:nix-systems/default"; + + # Rust + dream2nix.url = "github:nix-community/dream2nix"; + + # Dev tools + treefmt-nix.url = "github:numtide/treefmt-nix"; + mission-control.url = "github:Platonic-Systems/mission-control"; + flake-root.url = "github:srid/flake-root"; }; - outputs = { self, nixpkgs, nci, ... }: - nci.lib.makeOutputs { - # Documentation and examples: - # https://github.com/yusdacra/rust-nix-templater/blob/master/template/flake.nix - root = ./.; - overrides = { - shell = common: prev: { - packages = prev.packages ++ [ - common.pkgs.rust-analyzer - common.pkgs.cargo-watch + outputs = inputs: + inputs.flake-parts.lib.mkFlake { inherit inputs; } { + systems = import inputs.systems; + imports = [ + inputs.dream2nix.flakeModuleBeta + inputs.treefmt-nix.flakeModule + inputs.mission-control.flakeModule + inputs.flake-root.flakeModule + ]; + perSystem = { config, self', pkgs, lib, system, ... }: { + # Rust project definition + # cf. https://github.com/nix-community/dream2nix + dream2nix.inputs."rust-nix-template" = { + source = lib.sourceFilesBySuffices ./. [ + ".rs" + "Cargo.toml" + "Cargo.lock" ]; + projects."rust-nix-template" = { name, ... }: { + inherit name; + subsystem = "rust"; + translator = "cargo-lock"; + }; + }; + + # Flake outputs + packages = config.dream2nix.outputs.rust-nix-template.packages; + devShells.default = pkgs.mkShell { + inputsFrom = [ + config.dream2nix.outputs.rust-nix-template.devShells.default + config.treefmt.build.devShell + config.mission-control.devShell + config.flake-root.devShell + ]; + nativeBuildInputs = [ + pkgs.cargo-watch + ]; + }; + + # Add your auto-formatters here. + # cf. https://numtide.github.io/treefmt/ + treefmt.config = { + projectRootFile = "flake.nix"; + programs = { + nixpkgs-fmt.enable = true; + rustfmt.enable = true; + }; + }; + + # Makefile'esque but in Nix. Add your dev scripts here. + # cf. https://github.com/Platonic-Systems/mission-control + mission-control.scripts = { + fmt = { + exec = config.treefmt.build.wrapper; + description = "Auto-format project tree"; + }; + + run = { + exec = ''cargo run''; + description = "Run the project executable"; + }; + + watch = { + exec = ''cargo watch -x run''; + description = "Watch for changes and run the project executable"; + }; }; }; };