-
Notifications
You must be signed in to change notification settings - Fork 148
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
[SPIKE] Get cross-compilation working using iohk haskell.nix #764
base: main
Are you sure you want to change the base?
Conversation
Where I got stuck: c98d471. I'm not sure if I didn't get qemu binfmt set up correctly on my host system, or if something else is wrong. If anyone else can get this working, that would be amazing! Even getting any cross-compilation target up to the point where it's clearly building one of the haskell dependencies would be great progress. |
Possibly-useful information: https://discourse.nixos.org/t/how-to-configure-qemu-binfmt-wrapper-on-a-non-nixos-machine/7879 |
I can try to have a look somewhere today / tomorrow 🤔 |
Okay, I got something "working" (pretty much out of the box actually). The main issue comes actually from this
I'd suggest also to quickly setup and enable cachix (for which there's also a drop-in Github action The patch below is a bit "brutal", as it drops mostly everything that was there regarding Nix, including the nix-shell (which seems to pre-exist prior to the PR). The nix-shell is quite separate anyway so it can be re-added if necessary. 0001-Enable-compilation-of-static-executable-using-HaskellNix-musl64.patchFrom 872d96fff23ae20228b507e3fdf1398fc3584558 Mon Sep 17 00:00:00 2001
From: KtorZ <[email protected]>
Date: Sun, 27 Mar 2022 14:42:58 +0200
Subject: [PATCH] Enable compilation of static executable using Haskell.nix +
musl64
---
.plan.nix/avh4-lib.nix | 74 -------------
.plan.nix/elm-format-lib.nix | 86 ---------------
.plan.nix/elm-format-markdown.nix | 37 -------
.plan.nix/elm-format-test-lib.nix | 67 ------------
.plan.nix/elm-format.nix | 72 ------------
default.nix | 41 +++----
nix/sources.json | 38 -------
nix/sources.nix | 176 ------------------------------
release.nix | 27 -----
9 files changed, 22 insertions(+), 596 deletions(-)
delete mode 100644 .plan.nix/avh4-lib.nix
delete mode 100644 .plan.nix/elm-format-lib.nix
delete mode 100644 .plan.nix/elm-format-markdown.nix
delete mode 100644 .plan.nix/elm-format-test-lib.nix
delete mode 100644 .plan.nix/elm-format.nix
delete mode 100644 nix/sources.json
delete mode 100644 nix/sources.nix
delete mode 100644 release.nix
diff --git a/.plan.nix/avh4-lib.nix b/.plan.nix/avh4-lib.nix
deleted file mode 100644
index be80b457..00000000
--- a/.plan.nix/avh4-lib.nix
+++ /dev/null
@@ -1,74 +0,0 @@
-{ system
- , compiler
- , flags
- , pkgs
- , hsPkgs
- , pkgconfPkgs
- , errorHandler
- , config
- , ... }:
- {
- flags = {};
- package = {
- specVersion = "2.4";
- identifier = { name = "avh4-lib"; version = "0.0.0.1"; };
- license = "BSD-3-Clause";
- copyright = "See https://github.com/avh4/elm-format/blob/master/LICENSE";
- maintainer = "[email protected]";
- author = "Aaron VonderHaar";
- homepage = "";
- url = "";
- synopsis = "Common code for haskell projects";
- description = "";
- buildType = "Simple";
- isLocal = true;
- };
- components = {
- "library" = {
- depends = [
- (hsPkgs."ansi-terminal" or (errorHandler.buildDepError "ansi-terminal"))
- (hsPkgs."ansi-wl-pprint" or (errorHandler.buildDepError "ansi-wl-pprint"))
- (hsPkgs."array" or (errorHandler.buildDepError "array"))
- (hsPkgs."base" or (errorHandler.buildDepError "base"))
- (hsPkgs."bimap" or (errorHandler.buildDepError "bimap"))
- (hsPkgs."binary" or (errorHandler.buildDepError "binary"))
- (hsPkgs."bytestring" or (errorHandler.buildDepError "bytestring"))
- (hsPkgs."containers" or (errorHandler.buildDepError "containers"))
- (hsPkgs."directory" or (errorHandler.buildDepError "directory"))
- (hsPkgs."filepath" or (errorHandler.buildDepError "filepath"))
- (hsPkgs."mtl" or (errorHandler.buildDepError "mtl"))
- (hsPkgs."process" or (errorHandler.buildDepError "process"))
- (hsPkgs."relude" or (errorHandler.buildDepError "relude"))
- (hsPkgs."text" or (errorHandler.buildDepError "text"))
- ];
- buildable = true;
- };
- tests = {
- "al-tests" = {
- depends = [
- (hsPkgs."ansi-terminal" or (errorHandler.buildDepError "ansi-terminal"))
- (hsPkgs."ansi-wl-pprint" or (errorHandler.buildDepError "ansi-wl-pprint"))
- (hsPkgs."array" or (errorHandler.buildDepError "array"))
- (hsPkgs."base" or (errorHandler.buildDepError "base"))
- (hsPkgs."bimap" or (errorHandler.buildDepError "bimap"))
- (hsPkgs."binary" or (errorHandler.buildDepError "binary"))
- (hsPkgs."bytestring" or (errorHandler.buildDepError "bytestring"))
- (hsPkgs."containers" or (errorHandler.buildDepError "containers"))
- (hsPkgs."directory" or (errorHandler.buildDepError "directory"))
- (hsPkgs."filepath" or (errorHandler.buildDepError "filepath"))
- (hsPkgs."mtl" or (errorHandler.buildDepError "mtl"))
- (hsPkgs."process" or (errorHandler.buildDepError "process"))
- (hsPkgs."relude" or (errorHandler.buildDepError "relude"))
- (hsPkgs."text" or (errorHandler.buildDepError "text"))
- (hsPkgs."tasty" or (errorHandler.buildDepError "tasty"))
- (hsPkgs."tasty-hspec" or (errorHandler.buildDepError "tasty-hspec"))
- (hsPkgs."tasty-hunit" or (errorHandler.buildDepError "tasty-hunit"))
- ];
- build-tools = [
- (hsPkgs.buildPackages.tasty-discover.components.exes.tasty-discover or (pkgs.buildPackages.tasty-discover or (errorHandler.buildToolDepError "tasty-discover:tasty-discover")))
- ];
- buildable = true;
- };
- };
- };
- } // rec { src = (pkgs.lib).mkDefault ../avh4-lib; }
diff --git a/.plan.nix/elm-format-lib.nix b/.plan.nix/elm-format-lib.nix
deleted file mode 100644
index fec2929e..00000000
--- a/.plan.nix/elm-format-lib.nix
+++ /dev/null
@@ -1,86 +0,0 @@
-{ system
- , compiler
- , flags
- , pkgs
- , hsPkgs
- , pkgconfPkgs
- , errorHandler
- , config
- , ... }:
- {
- flags = {};
- package = {
- specVersion = "2.4";
- identifier = { name = "elm-format-lib"; version = "0.0.0.1"; };
- license = "BSD-3-Clause";
- copyright = "See https://github.com/avh4/elm-format/blob/master/LICENSE";
- maintainer = "[email protected]";
- author = "Aaron VonderHaar";
- homepage = "";
- url = "";
- synopsis = "Common code used by elm-format and elm-refactor";
- description = "";
- buildType = "Simple";
- isLocal = true;
- };
- components = {
- "library" = {
- depends = [
- (hsPkgs."aeson" or (errorHandler.buildDepError "aeson"))
- (hsPkgs."ansi-terminal" or (errorHandler.buildDepError "ansi-terminal"))
- (hsPkgs."ansi-wl-pprint" or (errorHandler.buildDepError "ansi-wl-pprint"))
- (hsPkgs."array" or (errorHandler.buildDepError "array"))
- (hsPkgs."base" or (errorHandler.buildDepError "base"))
- (hsPkgs."bimap" or (errorHandler.buildDepError "bimap"))
- (hsPkgs."binary" or (errorHandler.buildDepError "binary"))
- (hsPkgs."bytestring" or (errorHandler.buildDepError "bytestring"))
- (hsPkgs."containers" or (errorHandler.buildDepError "containers"))
- (hsPkgs."directory" or (errorHandler.buildDepError "directory"))
- (hsPkgs."filepath" or (errorHandler.buildDepError "filepath"))
- (hsPkgs."ghc-prim" or (errorHandler.buildDepError "ghc-prim"))
- (hsPkgs."mtl" or (errorHandler.buildDepError "mtl"))
- (hsPkgs."optparse-applicative" or (errorHandler.buildDepError "optparse-applicative"))
- (hsPkgs."process" or (errorHandler.buildDepError "process"))
- (hsPkgs."relude" or (errorHandler.buildDepError "relude"))
- (hsPkgs."text" or (errorHandler.buildDepError "text"))
- (hsPkgs."avh4-lib" or (errorHandler.buildDepError "avh4-lib"))
- (hsPkgs."elm-format-markdown" or (errorHandler.buildDepError "elm-format-markdown"))
- ];
- buildable = true;
- };
- tests = {
- "efl-tests" = {
- depends = [
- (hsPkgs."aeson" or (errorHandler.buildDepError "aeson"))
- (hsPkgs."ansi-terminal" or (errorHandler.buildDepError "ansi-terminal"))
- (hsPkgs."ansi-wl-pprint" or (errorHandler.buildDepError "ansi-wl-pprint"))
- (hsPkgs."array" or (errorHandler.buildDepError "array"))
- (hsPkgs."base" or (errorHandler.buildDepError "base"))
- (hsPkgs."bimap" or (errorHandler.buildDepError "bimap"))
- (hsPkgs."binary" or (errorHandler.buildDepError "binary"))
- (hsPkgs."bytestring" or (errorHandler.buildDepError "bytestring"))
- (hsPkgs."containers" or (errorHandler.buildDepError "containers"))
- (hsPkgs."directory" or (errorHandler.buildDepError "directory"))
- (hsPkgs."filepath" or (errorHandler.buildDepError "filepath"))
- (hsPkgs."ghc-prim" or (errorHandler.buildDepError "ghc-prim"))
- (hsPkgs."mtl" or (errorHandler.buildDepError "mtl"))
- (hsPkgs."optparse-applicative" or (errorHandler.buildDepError "optparse-applicative"))
- (hsPkgs."process" or (errorHandler.buildDepError "process"))
- (hsPkgs."relude" or (errorHandler.buildDepError "relude"))
- (hsPkgs."text" or (errorHandler.buildDepError "text"))
- (hsPkgs."avh4-lib" or (errorHandler.buildDepError "avh4-lib"))
- (hsPkgs."elm-format-markdown" or (errorHandler.buildDepError "elm-format-markdown"))
- (hsPkgs."split" or (errorHandler.buildDepError "split"))
- (hsPkgs."tasty" or (errorHandler.buildDepError "tasty"))
- (hsPkgs."tasty-hspec" or (errorHandler.buildDepError "tasty-hspec"))
- (hsPkgs."tasty-hunit" or (errorHandler.buildDepError "tasty-hunit"))
- (hsPkgs."elm-format-test-lib" or (errorHandler.buildDepError "elm-format-test-lib"))
- ];
- build-tools = [
- (hsPkgs.buildPackages.tasty-discover.components.exes.tasty-discover or (pkgs.buildPackages.tasty-discover or (errorHandler.buildToolDepError "tasty-discover:tasty-discover")))
- ];
- buildable = true;
- };
- };
- };
- } // rec { src = (pkgs.lib).mkDefault ../elm-format-lib; }
diff --git a/.plan.nix/elm-format-markdown.nix b/.plan.nix/elm-format-markdown.nix
deleted file mode 100644
index 5c4e3ff0..00000000
--- a/.plan.nix/elm-format-markdown.nix
+++ /dev/null
@@ -1,37 +0,0 @@
-{ system
- , compiler
- , flags
- , pkgs
- , hsPkgs
- , pkgconfPkgs
- , errorHandler
- , config
- , ... }:
- {
- flags = {};
- package = {
- specVersion = "2.4";
- identifier = { name = "elm-format-markdown"; version = "0.0.0.1"; };
- license = "BSD-3-Clause";
- copyright = "See https://github.com/avh4/elm-format/blob/master/LICENSE";
- maintainer = "[email protected]";
- author = "Aaron VonderHaar";
- homepage = "";
- url = "";
- synopsis = "Markdown parsing for Elm documentation comments";
- description = "";
- buildType = "Simple";
- isLocal = true;
- };
- components = {
- "library" = {
- depends = [
- (hsPkgs."base" or (errorHandler.buildDepError "base"))
- (hsPkgs."containers" or (errorHandler.buildDepError "containers"))
- (hsPkgs."mtl" or (errorHandler.buildDepError "mtl"))
- (hsPkgs."text" or (errorHandler.buildDepError "text"))
- ];
- buildable = true;
- };
- };
- } // rec { src = (pkgs.lib).mkDefault ../elm-format-markdown; }
diff --git a/.plan.nix/elm-format-test-lib.nix b/.plan.nix/elm-format-test-lib.nix
deleted file mode 100644
index d716a4e4..00000000
--- a/.plan.nix/elm-format-test-lib.nix
+++ /dev/null
@@ -1,67 +0,0 @@
-{ system
- , compiler
- , flags
- , pkgs
- , hsPkgs
- , pkgconfPkgs
- , errorHandler
- , config
- , ... }:
- {
- flags = {};
- package = {
- specVersion = "2.4";
- identifier = { name = "elm-format-test-lib"; version = "0.0.0.1"; };
- license = "BSD-3-Clause";
- copyright = "See https://github.com/avh4/elm-format/blob/master/LICENSE";
- maintainer = "[email protected]";
- author = "Aaron VonderHaar";
- homepage = "";
- url = "";
- synopsis = "Test helpers used by elm-format-tests and elm-refactor-tests";
- description = "";
- buildType = "Simple";
- isLocal = true;
- };
- components = {
- "library" = {
- depends = [
- (hsPkgs."base" or (errorHandler.buildDepError "base"))
- (hsPkgs."containers" or (errorHandler.buildDepError "containers"))
- (hsPkgs."filepath" or (errorHandler.buildDepError "filepath"))
- (hsPkgs."hspec-core" or (errorHandler.buildDepError "hspec-core"))
- (hsPkgs."hspec-golden" or (errorHandler.buildDepError "hspec-golden"))
- (hsPkgs."mtl" or (errorHandler.buildDepError "mtl"))
- (hsPkgs."split" or (errorHandler.buildDepError "split"))
- (hsPkgs."tasty" or (errorHandler.buildDepError "tasty"))
- (hsPkgs."tasty-hspec" or (errorHandler.buildDepError "tasty-hspec"))
- (hsPkgs."tasty-hunit" or (errorHandler.buildDepError "tasty-hunit"))
- (hsPkgs."text" or (errorHandler.buildDepError "text"))
- (hsPkgs."avh4-lib" or (errorHandler.buildDepError "avh4-lib"))
- ];
- buildable = true;
- };
- tests = {
- "elm-format-test-lib-tests" = {
- depends = [
- (hsPkgs."base" or (errorHandler.buildDepError "base"))
- (hsPkgs."containers" or (errorHandler.buildDepError "containers"))
- (hsPkgs."filepath" or (errorHandler.buildDepError "filepath"))
- (hsPkgs."hspec-core" or (errorHandler.buildDepError "hspec-core"))
- (hsPkgs."hspec-golden" or (errorHandler.buildDepError "hspec-golden"))
- (hsPkgs."mtl" or (errorHandler.buildDepError "mtl"))
- (hsPkgs."split" or (errorHandler.buildDepError "split"))
- (hsPkgs."tasty" or (errorHandler.buildDepError "tasty"))
- (hsPkgs."tasty-hspec" or (errorHandler.buildDepError "tasty-hspec"))
- (hsPkgs."tasty-hunit" or (errorHandler.buildDepError "tasty-hunit"))
- (hsPkgs."text" or (errorHandler.buildDepError "text"))
- (hsPkgs."avh4-lib" or (errorHandler.buildDepError "avh4-lib"))
- ];
- build-tools = [
- (hsPkgs.buildPackages.tasty-discover.components.exes.tasty-discover or (pkgs.buildPackages.tasty-discover or (errorHandler.buildToolDepError "tasty-discover:tasty-discover")))
- ];
- buildable = true;
- };
- };
- };
- } // rec { src = (pkgs.lib).mkDefault .././.././elm-format-test-lib; }
\ No newline at end of file
diff --git a/.plan.nix/elm-format.nix b/.plan.nix/elm-format.nix
deleted file mode 100644
index 8e1eea5f..00000000
--- a/.plan.nix/elm-format.nix
+++ /dev/null
@@ -1,72 +0,0 @@
-{ system
- , compiler
- , flags
- , pkgs
- , hsPkgs
- , pkgconfPkgs
- , errorHandler
- , config
- , ... }:
- {
- flags = {};
- package = {
- specVersion = "2.4";
- identifier = { name = "elm-format"; version = "0.8.5"; };
- license = "BSD-3-Clause";
- copyright = "See https://github.com/avh4/elm-format/blob/master/LICENSE";
- maintainer = "[email protected]";
- author = "Aaron VonderHaar";
- homepage = "https://elm-lang.org";
- url = "";
- synopsis = "A source code formatter for Elm";
- description = "A simple way to format your Elm code according to the official\nstyle guide.";
- buildType = "Simple";
- isLocal = true;
- };
- components = {
- exes = {
- "elm-format" = {
- depends = [
- (hsPkgs."aeson" or (errorHandler.buildDepError "aeson"))
- (hsPkgs."ansi-wl-pprint" or (errorHandler.buildDepError "ansi-wl-pprint"))
- (hsPkgs."base" or (errorHandler.buildDepError "base"))
- (hsPkgs."bytestring" or (errorHandler.buildDepError "bytestring"))
- (hsPkgs."containers" or (errorHandler.buildDepError "containers"))
- (hsPkgs."optparse-applicative" or (errorHandler.buildDepError "optparse-applicative"))
- (hsPkgs."relude" or (errorHandler.buildDepError "relude"))
- (hsPkgs."text" or (errorHandler.buildDepError "text"))
- (hsPkgs."avh4-lib" or (errorHandler.buildDepError "avh4-lib"))
- (hsPkgs."elm-format-lib" or (errorHandler.buildDepError "elm-format-lib"))
- ];
- buildable = true;
- };
- };
- tests = {
- "elm-format-tests" = {
- depends = [
- (hsPkgs."aeson" or (errorHandler.buildDepError "aeson"))
- (hsPkgs."ansi-wl-pprint" or (errorHandler.buildDepError "ansi-wl-pprint"))
- (hsPkgs."base" or (errorHandler.buildDepError "base"))
- (hsPkgs."bytestring" or (errorHandler.buildDepError "bytestring"))
- (hsPkgs."containers" or (errorHandler.buildDepError "containers"))
- (hsPkgs."optparse-applicative" or (errorHandler.buildDepError "optparse-applicative"))
- (hsPkgs."relude" or (errorHandler.buildDepError "relude"))
- (hsPkgs."text" or (errorHandler.buildDepError "text"))
- (hsPkgs."avh4-lib" or (errorHandler.buildDepError "avh4-lib"))
- (hsPkgs."elm-format-lib" or (errorHandler.buildDepError "elm-format-lib"))
- (hsPkgs."mtl" or (errorHandler.buildDepError "mtl"))
- (hsPkgs."tasty" or (errorHandler.buildDepError "tasty"))
- (hsPkgs."tasty-hspec" or (errorHandler.buildDepError "tasty-hspec"))
- (hsPkgs."tasty-hunit" or (errorHandler.buildDepError "tasty-hunit"))
- (hsPkgs."tasty-quickcheck" or (errorHandler.buildDepError "tasty-quickcheck"))
- (hsPkgs."QuickCheck" or (errorHandler.buildDepError "QuickCheck"))
- (hsPkgs."quickcheck-io" or (errorHandler.buildDepError "quickcheck-io"))
- (hsPkgs."bimap" or (errorHandler.buildDepError "bimap"))
- (hsPkgs."cmark" or (errorHandler.buildDepError "cmark"))
- (hsPkgs."elm-format-test-lib" or (errorHandler.buildDepError "elm-format-test-lib"))
- ];
- buildable = true;
- };
- };
- };
- } // rec { src = (pkgs.lib).mkDefault ../.; }
diff --git a/default.nix b/default.nix
index 97ab8e8b..a6027fde 100644
--- a/default.nix
+++ b/default.nix
@@ -1,21 +1,24 @@
-{ sources ? import ./nix/sources.nix { }, pkgs ? null }:
-
+{ compiler ? "ghc901"
+, system ? builtins.currentSystem
+, haskellNix ? import
+ (builtins.fetchTarball
+ "https://github.com/input-output-hk/haskell.nix/archive/bc471e5235246ca015cd6755adfe1feaa8761498.tar.gz")
+ { }
+, nixpkgsSrc ? haskellNix.sources.nixpkgs-2111
+, nixpkgsArgs ? haskellNix.nixpkgsArgs
+}:
let
- haskell-nix = if pkgs == null then
- let
- haskellNix = import sources.haskellNix { };
- finalPkgs =
- import haskellNix.sources.nixpkgs-unstable haskellNix.nixpkgsArgs;
- in finalPkgs.haskell-nix
-
- else
- let haskellNix = import sources.haskellNix { inherit pkgs; };
- in haskellNix.pkgs.haskell-nix;
-
- pkgSet = haskell-nix.mkCabalProjectPkgSet {
- plan-pkgs = import ./pkgs.nix;
- pkg-def-extras = [ ];
- modules = [ ];
+ pkgs = import nixpkgsSrc (nixpkgsArgs // {
+ overlays =
+ haskellNix.overlays;
+ });
+ musl64 = pkgs.pkgsCross.musl64;
+in
+musl64.haskell-nix.project {
+ src = musl64.haskell-nix.haskellLib.cleanSourceWith {
+ name = "elm-format";
+ src = ./.;
};
-
-in pkgSet.config.hsPkgs
+ projectFileName = "cabal.project";
+ compiler-nix-name = compiler;
+}
diff --git a/nix/sources.json b/nix/sources.json
deleted file mode 100644
index efb0e573..00000000
--- a/nix/sources.json
+++ /dev/null
@@ -1,38 +0,0 @@
-{
- "haskellNix": {
- "branch": "master",
- "description": "Alternative Haskell Infrastructure for Nixpkgs",
- "homepage": "https://input-output-hk.github.io/haskell.nix",
- "owner": "input-output-hk",
- "repo": "haskell.nix",
- "rev": "b87bc95b041e322ab00e136bb34ac526839536fc",
- "sha256": "1c7rj110anz69110mygx5xr9g5rx93xwgn9yx1ak5755i9hpxj6p",
- "type": "tarball",
- "url": "https://github.com/input-output-hk/haskell.nix/archive/b87bc95b041e322ab00e136bb34ac526839536fc.tar.gz",
- "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
- },
- "niv": {
- "branch": "master",
- "description": "Easy dependency management for Nix projects",
- "homepage": "https://github.com/nmattia/niv",
- "owner": "nmattia",
- "repo": "niv",
- "rev": "9cb7ef336bb71fd1ca84fc7f2dff15ef4b033f2a",
- "sha256": "1ajyqr8zka1zlb25jx1v4xys3zqmdy3prbm1vxlid6ah27a8qnzh",
- "type": "tarball",
- "url": "https://github.com/nmattia/niv/archive/9cb7ef336bb71fd1ca84fc7f2dff15ef4b033f2a.tar.gz",
- "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
- },
- "nixpkgs": {
- "branch": "nixpkgs-unstable",
- "description": "Nix Packages collection",
- "homepage": "",
- "owner": "NixOS",
- "repo": "nixpkgs",
- "rev": "ca9356fd340488c3f0b46048c4aceefa1b792518",
- "sha256": "0grzpbsns34n6x93vhahfc9fjj9p5w93sykm2bkgvjxdafqk48kq",
- "type": "tarball",
- "url": "https://github.com/NixOS/nixpkgs/archive/ca9356fd340488c3f0b46048c4aceefa1b792518.tar.gz",
- "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
- }
-}
diff --git a/nix/sources.nix b/nix/sources.nix
deleted file mode 100644
index feb35384..00000000
--- a/nix/sources.nix
+++ /dev/null
@@ -1,176 +0,0 @@
-# This file has been generated by Niv.
-
-let
-
- #
- # The fetchers. fetch_<type> fetches specs of type <type>.
- #
-
- fetch_file = pkgs: name: spec:
- let
- name' = sanitizeName name + "-src";
- in
- if spec.builtin or true then
- builtins_fetchurl { inherit (spec) url sha256; name = name'; }
- else
- pkgs.fetchurl { inherit (spec) url sha256; name = name'; };
-
- fetch_tarball = pkgs: name: spec:
- let
- name' = sanitizeName name + "-src";
- in
- if spec.builtin or true then
- builtins_fetchTarball { name = name'; inherit (spec) url sha256; }
- else
- pkgs.fetchzip { name = name'; inherit (spec) url sha256; };
-
- fetch_git = name: spec:
- let
- ref =
- if spec ? ref then spec.ref else
- if spec ? branch then "refs/heads/${spec.branch}" else
- if spec ? tag then "refs/tags/${spec.tag}" else
- abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!";
- submodules = if spec ? submodules then spec.submodules else false;
- in
- builtins.fetchGit { url = spec.repo; inherit (spec) rev; inherit ref; }
- // (if builtins.compareVersions builtins.nixVersion "2.4" >= 0 then { inherit submodules; } else { });
-
- fetch_local = spec: spec.path;
-
- fetch_builtin-tarball = name: throw
- ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`.
- $ niv modify ${name} -a type=tarball -a builtin=true'';
-
- fetch_builtin-url = name: throw
- ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`.
- $ niv modify ${name} -a type=file -a builtin=true'';
-
- #
- # Various helpers
- #
-
- # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695
- sanitizeName = name:
- (
- concatMapStrings (s: if builtins.isList s then "-" else s)
- (
- builtins.split "[^[:alnum:]+._?=-]+"
- ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name)
- )
- );
-
- # The set of packages used when specs are fetched using non-builtins.
- mkPkgs = sources: system:
- let
- sourcesNixpkgs =
- import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; };
- hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;
- hasThisAsNixpkgsPath = <nixpkgs> == ./.;
- in
- if builtins.hasAttr "nixpkgs" sources
- then sourcesNixpkgs
- else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then
- import <nixpkgs> {}
- else
- abort
- ''
- Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
- add a package called "nixpkgs" to your sources.json.
- '';
-
- # The actual fetching function.
- fetch = pkgs: name: spec:
-
- if ! builtins.hasAttr "type" spec then
- abort "ERROR: niv spec ${name} does not have a 'type' attribute"
- else if spec.type == "file" then fetch_file pkgs name spec
- else if spec.type == "tarball" then fetch_tarball pkgs name spec
- else if spec.type == "git" then fetch_git name spec
- else if spec.type == "local" then fetch_local spec
- else if spec.type == "builtin-tarball" then fetch_builtin-tarball name
- else if spec.type == "builtin-url" then fetch_builtin-url name
- else
- abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}";
-
- # If the environment variable NIV_OVERRIDE_${name} is set, then use
- # the path directly as opposed to the fetched source.
- replace = name: drv:
- let
- saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name;
- ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}";
- in
- if ersatz == "" then drv else
- # this turns the string into an actual Nix path (for both absolute and
- # relative paths)
- if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}";
-
- # Ports of functions for older nix versions
-
- # a Nix version of mapAttrs if the built-in doesn't exist
- mapAttrs = builtins.mapAttrs or (
- f: set: with builtins;
- listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set))
- );
-
- # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295
- range = first: last: if first > last then [] else builtins.genList (n: first + n) (last - first + 1);
-
- # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257
- stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1));
-
- # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269
- stringAsChars = f: s: concatStrings (map f (stringToCharacters s));
- concatMapStrings = f: list: concatStrings (map f list);
- concatStrings = builtins.concatStringsSep "";
-
- # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331
- optionalAttrs = cond: as: if cond then as else {};
-
- # fetchTarball version that is compatible between all the versions of Nix
- builtins_fetchTarball = { url, name ? null, sha256 }@attrs:
- let
- inherit (builtins) lessThan nixVersion fetchTarball;
- in
- if lessThan nixVersion "1.12" then
- fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
- else
- fetchTarball attrs;
-
- # fetchurl version that is compatible between all the versions of Nix
- builtins_fetchurl = { url, name ? null, sha256 }@attrs:
- let
- inherit (builtins) lessThan nixVersion fetchurl;
- in
- if lessThan nixVersion "1.12" then
- fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
- else
- fetchurl attrs;
-
- # Create the final "sources" from the config
- mkSources = config:
- mapAttrs (
- name: spec:
- if builtins.hasAttr "outPath" spec
- then abort
- "The values in sources.json should not have an 'outPath' attribute"
- else
- spec // { outPath = replace name (fetch config.pkgs name spec); }
- ) config.sources;
-
- # The "config" used by the fetchers
- mkConfig =
- { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null
- , sources ? if isNull sourcesFile then {} else builtins.fromJSON (builtins.readFile sourcesFile)
- , system ? builtins.currentSystem
- , pkgs ? mkPkgs sources system
- }: rec {
- # The sources, i.e. the attribute set of spec name to spec
- inherit sources;
-
- # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers
- inherit pkgs;
- };
-
-in
-mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); }
diff --git a/release.nix b/release.nix
deleted file mode 100644
index f1958245..00000000
--- a/release.nix
+++ /dev/null
@@ -1,27 +0,0 @@
-{ sources ? import ./nix/sources.nix { } }:
-let
- project = import ./default.nix;
- pkgsNative = import sources.nixpkgs { };
-
- pkgsLinux = pkgsNative;
- pkgsMac = import sources.nixpkgs {
- crossSystem = pkgsNative.lib.systems.examples.x86_64-darwin;
- };
- pkgsWin = import sources.nixpkgs {
- crossSystem = pkgsNative.lib.systems.examples.mingw32;
- };
-
- pkgsTest = import sources.nixpkgs {
- crossSystem = pkgsNative.lib.systems.examples.aarch64-multiplatform;
- };
-
- linux = project { pkgs = pkgsLinux; };
- mac = project { pkgs = pkgsMac; };
- win = project { pkgs = pkgsWin; };
- test = project { pkgs = pkgsTest; };
-in {
- elm-format-linux = linux.elm-format.components.exes.elm-format;
- #elm-format-mac = mac.elm-format.components.exes.elm-format;
- #elm-format-win = win.elm-format.components.exes.elm-format;
- elm-format-test = test.elm-format.components.exes.elm-format;
-}
--
2.34.1 |
(Technically, this is "emulated compilation", not true "cross compilation"). See https://input-output-hk.github.io/haskell.nix/tutorials/cross-compilation.html
Can this be used to build mac, windows, and static linux binaries? The ideal target set would be:
musl x86_64-linux(edit 2023-02-20: this now works in plain nixpkgs withpkgsStatic
)musl aarch64-linux(edit 2023-02-20: this now works in plain nixpkgs withpkgsCross.(...).pkgsStatic
)TODO
nix-build -A elm-format.components.exes
builds the native binary to./result/bin/elm-format
nix-build release.nix
builds cross-compiled binariesnix-shell --pure --command ./build.sh
should still work and build the native binary to_build/elm-format
References