From 4534f3e02826e628302d980af6e9d223ac727e9d Mon Sep 17 00:00:00 2001
From: Daniel Firth <dan.firth@homotopic.tech>
Date: Mon, 20 Feb 2023 10:04:39 +0000
Subject: [PATCH] switch flake-utils to flake-parts

---
 flake.lock |  60 +++++++++++++------
 flake.nix  | 170 +++++++++++++++++++++++++++--------------------------
 2 files changed, 129 insertions(+), 101 deletions(-)

diff --git a/flake.lock b/flake.lock
index 4db7b5c8..261c2f6e 100644
--- a/flake.lock
+++ b/flake.lock
@@ -1,20 +1,24 @@
 {
   "nodes": {
-    "flake-utils": {
+    "flake-parts": {
+      "inputs": {
+        "nixpkgs-lib": "nixpkgs-lib"
+      },
       "locked": {
-        "lastModified": 1659877975,
-        "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
-        "owner": "numtide",
-        "repo": "flake-utils",
-        "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
+        "lastModified": 1675933616,
+        "narHash": "sha256-/rczJkJHtx16IFxMmAWu5nNYcSXNg1YYXTHoGjLrLUA=",
+        "owner": "hercules-ci",
+        "repo": "flake-parts",
+        "rev": "47478a4a003e745402acf63be7f9a092d51b83d7",
         "type": "github"
       },
       "original": {
-        "id": "flake-utils",
-        "type": "indirect"
+        "owner": "hercules-ci",
+        "repo": "flake-parts",
+        "type": "github"
       }
     },
-    "flake-utils_2": {
+    "flake-utils": {
       "locked": {
         "lastModified": 1667077288,
         "narHash": "sha256-bdC8sFNDpT0HK74u9fUkpbf1MEzVYJ+ka7NXCdgBoaA=",
@@ -29,7 +33,7 @@
         "type": "github"
       }
     },
-    "flake-utils_3": {
+    "flake-utils_2": {
       "locked": {
         "lastModified": 1659877975,
         "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
@@ -43,7 +47,7 @@
         "type": "indirect"
       }
     },
-    "flake-utils_4": {
+    "flake-utils_3": {
       "locked": {
         "lastModified": 1644229661,
         "narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=",
@@ -58,7 +62,7 @@
         "type": "github"
       }
     },
-    "flake-utils_5": {
+    "flake-utils_4": {
       "locked": {
         "lastModified": 1644229661,
         "narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=",
@@ -73,7 +77,7 @@
         "type": "github"
       }
     },
-    "flake-utils_6": {
+    "flake-utils_5": {
       "locked": {
         "lastModified": 1644229661,
         "narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=",
@@ -151,7 +155,7 @@
     },
     "horizon-gen-nix-flake": {
       "inputs": {
-        "flake-utils": "flake-utils_2",
+        "flake-utils": "flake-utils",
         "get-flake": "get-flake_2",
         "horizon-gen-nix": "horizon-gen-nix",
         "horizon-platform": "horizon-platform",
@@ -190,7 +194,7 @@
     },
     "horizon-platform": {
       "inputs": {
-        "flake-utils": "flake-utils_3",
+        "flake-utils": "flake-utils_2",
         "get-flake": "get-flake_3",
         "horizon-gen-nix": "horizon-gen-nix_2",
         "lint-utils": "lint-utils",
@@ -228,7 +232,7 @@
     },
     "lint-utils": {
       "inputs": {
-        "flake-utils": "flake-utils_4",
+        "flake-utils": "flake-utils_3",
         "nixpkgs": "nixpkgs"
       },
       "locked": {
@@ -247,7 +251,7 @@
     },
     "lint-utils_2": {
       "inputs": {
-        "flake-utils": "flake-utils_5",
+        "flake-utils": "flake-utils_4",
         "nixpkgs": [
           "horizon-gen-nix-flake",
           "nixpkgs"
@@ -269,7 +273,7 @@
     },
     "lint-utils_3": {
       "inputs": {
-        "flake-utils": "flake-utils_6",
+        "flake-utils": "flake-utils_5",
         "nixpkgs": "nixpkgs_4"
       },
       "locked": {
@@ -302,6 +306,24 @@
         "type": "github"
       }
     },
+    "nixpkgs-lib": {
+      "locked": {
+        "dir": "lib",
+        "lastModified": 1675183161,
+        "narHash": "sha256-Zq8sNgAxDckpn7tJo7V1afRSk2eoVbu3OjI1QklGLNg=",
+        "owner": "NixOS",
+        "repo": "nixpkgs",
+        "rev": "e1e1b192c1a5aab2960bf0a0bd53a2e8124fa18e",
+        "type": "github"
+      },
+      "original": {
+        "dir": "lib",
+        "owner": "NixOS",
+        "ref": "nixos-unstable",
+        "repo": "nixpkgs",
+        "type": "github"
+      }
+    },
     "nixpkgs_2": {
       "locked": {
         "lastModified": 1665830552,
@@ -368,7 +390,7 @@
     },
     "root": {
       "inputs": {
-        "flake-utils": "flake-utils",
+        "flake-parts": "flake-parts",
         "get-flake": "get-flake",
         "horizon-gen-nix-flake": "horizon-gen-nix-flake",
         "horizon-platform": "horizon-platform_2",
diff --git a/flake.nix b/flake.nix
index 901f1f44..710c4636 100644
--- a/flake.nix
+++ b/flake.nix
@@ -1,6 +1,10 @@
 {
+
+  description = "Haskell Horizon Platform";
+
   inputs = {
     get-flake.url = "github:ursi/get-flake";
+    flake-parts.url = "github:hercules-ci/flake-parts";
     horizon-gen-nix-flake.url = "git+https://gitlab.homotopic.tech/horizon/horizon-gen-nix";
     horizon-platform = {
       url = "git+https://gitlab.homotopic.tech/horizon/horizon-platform";
@@ -14,104 +18,106 @@
     inputs@
     { self
     , get-flake
-    , flake-utils
+    , flake-parts
     , horizon-platform
     , horizon-gen-nix-flake
     , lint-utils
     , nixpkgs
     , ...
     }:
-    flake-utils.lib.eachSystem [ "x86_64-linux" ]
-      (system:
-      let
-        pkgs = nixpkgs.legacyPackages.${system};
-      in
-      with pkgs.lib;
-      with pkgs.writers;
-      with lint-utils.writers.${system};
-      let
-
-        horizon-platform-prev = get-flake horizon-platform;
-
-        horizon-gen-nix = pkgs.writeShellApplication {
-          name = "horizon-gen-nix";
-          runtimeInputs = with pkgs; [ ghc cabal-install ];
-          text = ''
-            cabal update
-            ${horizon-gen-nix-flake.legacyPackages.${system}.horizon-gen-nix}/bin/horizon-gen-nix;
-            ${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt pkgs/*
-            ${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt initial-packages.nix
-          '';
-        };
+    flake-parts.lib.mkFlake { inherit inputs; } {
+      systems = [ "x86_64-linux" ];
+      perSystem = { config, system, ... }:
+        let
+          pkgs = nixpkgs.legacyPackages.${system};
+        in
+        with pkgs.lib;
+        with pkgs.writers;
+        with lint-utils.writers.${system};
+        let
+
+          horizon-platform-prev = get-flake horizon-platform;
+
+          horizon-gen-nix = pkgs.writeShellApplication {
+            name = "horizon-gen-nix";
+            runtimeInputs = with pkgs; [ ghc cabal-install ];
+            text = ''
+              cabal update
+              ${horizon-gen-nix-flake.legacyPackages.${system}.horizon-gen-nix}/bin/horizon-gen-nix;
+              ${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt pkgs/*
+              ${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt initial-packages.nix
+            '';
+          };
 
-        haskellLib = pkgs.haskell.lib.compose;
-
-        legacyPackages = pkgs.callPackage (nixpkgs + /pkgs/development/haskell-modules) {
-          buildHaskellPackages = pkgs.haskell.packages.ghc944;
-          compilerConfig = pkgs.callPackage ./configuration-ghc.nix { inherit haskellLib; };
-          configurationArm = { pkgs, haskellLib }: self: super: { };
-          configurationCommon = import ./configuration.nix;
-          configurationDarwin = { pkgs, haskellLib }: self: super: { };
-          configurationNix = { pkgs, haskellLib }: self: super: { };
-          ghc = pkgs.haskell.compiler.ghc944;
-          inherit haskellLib;
-          initialPackages = import ./initial-packages.nix;
-          nonHackagePackages = self: super: { };
-        };
+          haskellLib = pkgs.haskell.lib.compose;
+
+          legacyPackages = pkgs.callPackage (nixpkgs + /pkgs/development/haskell-modules) {
+            buildHaskellPackages = pkgs.haskell.packages.ghc944;
+            compilerConfig = pkgs.callPackage ./configuration-ghc.nix { inherit haskellLib; };
+            configurationArm = { pkgs, haskellLib }: self: super: { };
+            configurationCommon = import ./configuration.nix;
+            configurationDarwin = { pkgs, haskellLib }: self: super: { };
+            configurationNix = { pkgs, haskellLib }: self: super: { };
+            ghc = pkgs.haskell.compiler.ghc944;
+            inherit haskellLib;
+            initialPackages = import ./initial-packages.nix;
+            nonHackagePackages = self: super: { };
+          };
 
-        packages = filterAttrs
-          (n: v: v != null
-            && builtins.typeOf v == "set"
-            && pkgs.lib.hasAttr "type" v
-            && v.type == "derivation"
-            && v.meta.broken == false)
-          legacyPackages;
-
-        run-impure-tests = writePorcelainOrDieBin {
-          name = "run-impure-tests";
-          src = ./.;
-          command = ''
-            export PATH=$PATH:${pkgs.nix-prefetch-git}/bin:${pkgs.cabal-install}/bin
-            cabal update
-            rm pkgs -rf && nix run .#horizon-gen-nix;
-            nixpkgs-fmt pkgs/*
-          '';
-          advice = "Try removing the offending packages from pkgs/ and running nix run .#horizon-gen-nix";
-        };
+          packages = filterAttrs
+            (n: v: v != null
+              && builtins.typeOf v == "set"
+              && pkgs.lib.hasAttr "type" v
+              && v.type == "derivation"
+              && v.meta.broken == false)
+            legacyPackages;
+
+          run-impure-tests = writePorcelainOrDieBin {
+            name = "run-impure-tests";
+            src = ./.;
+            command = ''
+              export PATH=$PATH:${pkgs.nix-prefetch-git}/bin:${pkgs.cabal-install}/bin
+              cabal update
+              rm pkgs -rf && nix run .#horizon-gen-nix;
+              nixpkgs-fmt pkgs/*
+            '';
+            advice = "Try removing the offending packages from pkgs/ and running nix run .#horizon-gen-nix";
+          };
 
-        run-impure-tests-app = {
-          type = "app";
-          program = "${run-impure-tests}/bin/run-impure-tests";
-        };
+          run-impure-tests-app = {
+            type = "app";
+            program = "${run-impure-tests}/bin/run-impure-tests";
+          };
 
-        procex = import ./shell/default.nix { haskellPackages = horizon-platform-prev.legacyPackages.${system}; inherit (pkgs) runCommand writeShellScriptBin; };
-      in
-      {
+          procex = import ./shell/default.nix { haskellPackages = horizon-platform-prev.legacyPackages.${system}; inherit (pkgs) runCommand writeShellScriptBin; };
+        in
+        {
 
-        apps = {
+          apps = {
 
-          horizon-gen-nix = {
-            type = "app";
-            program = "${horizon-gen-nix}/bin/horizon-gen-nix";
-          };
+            horizon-gen-nix = {
+              type = "app";
+              program = "${horizon-gen-nix}/bin/horizon-gen-nix";
+            };
 
-          procex = {
-            type = "app";
-            program = "${procex}/bin/procex-shell";
-          };
+            procex = {
+              type = "app";
+              program = "${procex}/bin/procex-shell";
+            };
 
-          run-impure-tests = run-impure-tests-app;
-        };
+            run-impure-tests = run-impure-tests-app;
+          };
 
-        checks = with lint-utils.linters.${system}; {
-          dhall-format = dhall-format { src = self; };
-          nixpkgs-fmt = nixpkgs-fmt { src = self; };
-          stylish-haskell = stylish-haskell { src = self; };
-        };
+          checks = with lint-utils.linters.${system}; {
+            dhall-format = dhall-format { src = self; };
+            nixpkgs-fmt = nixpkgs-fmt { src = self; };
+            stylish-haskell = stylish-haskell { src = self; };
+          };
 
-        inherit legacyPackages;
+          inherit legacyPackages;
 
-        inherit packages;
+          inherit packages;
 
-      });
+        };
+    };
 }
-- 
GitLab