From 2e52e651a5926b5bda586f9991976cb4a96b5360 Mon Sep 17 00:00:00 2001 From: mitchmindtree Date: Sun, 29 Sep 2024 02:30:33 +1000 Subject: [PATCH 1/2] [ refactor ] Add a nix overlay --- flake.nix | 52 ++++++++++++--------------------------------- nix/buildIdris.nix | 3 ++- nix/idris2Api.nix | 11 ++++++++++ nix/overlay.nix | 26 +++++++++++++++++++++++ nix/package.nix | 4 ++-- nix/text-editor.nix | 4 ++-- 6 files changed, 56 insertions(+), 44 deletions(-) create mode 100644 nix/idris2Api.nix create mode 100644 nix/overlay.nix diff --git a/flake.nix b/flake.nix index 3d3e26eef3..5edcd55606 100644 --- a/flake.nix +++ b/flake.nix @@ -22,44 +22,18 @@ description = "A custom Idris 2 package with dependencies"; }; defaultTemplate = templates.pkg; + overlays.default = import ./nix/overlay.nix { + inherit idris2Version; + shortRev = self.shortRev or null; + }; version = idris2Version; }; per-system = { config ? { }, overlays ? [ ] }: system: let - pkgs = import nixpkgs { inherit config system overlays; }; - chezSupportsSystem = (system == "x86_64-linux") - || (pkgs.lib.versionAtLeast pkgs.chez.version "10.0.0"); - chez = if chezSupportsSystem then - pkgs.chez - else - pkgs.chez-racket; - idris2Support = pkgs.callPackage ./nix/support.nix { inherit idris2Version; }; - idris2Bootstrap = pkgs.callPackage ./nix/package.nix { - inherit idris2Version chez; - idris2Bootstrap = null; - support = idris2Support; - srcRev = self.shortRev or "dirty"; - }; - idris2Pkg = pkgs.callPackage ./nix/package.nix { - inherit idris2Version chez idris2Bootstrap; - support = idris2Support; - srcRev = self.shortRev or "dirty"; - }; - buildIdris = pkgs.callPackage ./nix/buildIdris.nix { - inherit idris2Version; - idris2 = idris2Pkg; - support = idris2Support; - }; - idris2ApiPkg = buildIdris { - src = ./.; - ipkgName = "idris2api"; - version = idris2Version; - idrisLibraries = [ ]; - preBuild = '' - export IDRIS2_PREFIX=$out/lib - make src/IdrisPaths.idr - ''; + pkgs = import nixpkgs { + inherit config system; + overlays = overlays ++ [ self.overlays.default ]; }; stdenv' = with pkgs; if stdenv.isDarwin then overrideSDK stdenv "11.0" else stdenv; in { @@ -69,16 +43,16 @@ idris = self; }; packages = rec { - support = idris2Support; - idris2 = idris2Pkg; - idris2Api = idris2ApiPkg.library { withSource = true; }; + inherit (pkgs.idris2Packages) support idris2; + idris2Api = pkgs.idris2Packages.idris2Api.library { withSource = true; }; default = idris2; } // (import ./nix/text-editor.nix { - inherit pkgs idris-emacs-src idris2Pkg; + inherit (pkgs) idris2; + inherit pkgs idris-emacs-src; }); - inherit buildIdris; + inherit (pkgs.idris2Packages) buildIdris; devShells.default = pkgs.mkShell.override { stdenv = stdenv'; } { - packages = idris2Pkg.buildInputs; + packages = pkgs.idris2.buildInputs; }; }; in lib.mkOvrOptsFlake diff --git a/nix/buildIdris.nix b/nix/buildIdris.nix index 9aa49394b0..f194416e85 100644 --- a/nix/buildIdris.nix +++ b/nix/buildIdris.nix @@ -1,4 +1,4 @@ -{ stdenv, lib, idris2Version, idris2, jq, support, makeWrapper }: +{ stdenv, lib, idris2Version, idris2Packages, jq, makeWrapper }: # Usage: let # pkg = idris2Pkg.buildIdris { # src = ...; @@ -20,6 +20,7 @@ let # loop over idrisLibraries and normalize them by turning any that are # direct outputs of the buildIdris function into the `.library {}` # property. + inherit (idris2Packages) idris2 support; idrisLibraryLibs = map (idrisLib: if lib.isDerivation idrisLib then idrisLib diff --git a/nix/idris2Api.nix b/nix/idris2Api.nix new file mode 100644 index 0000000000..097e939844 --- /dev/null +++ b/nix/idris2Api.nix @@ -0,0 +1,11 @@ +{ idris2Packages, idris2Version }: +idris2Packages.buildIdris { + src = ./..; + ipkgName = "idris2api"; + version = idris2Version; + idrisLibraries = [ ]; + preBuild = '' + export IDRIS2_PREFIX=$out/lib + make src/IdrisPaths.idr + ''; +} diff --git a/nix/overlay.nix b/nix/overlay.nix new file mode 100644 index 0000000000..251db46d59 --- /dev/null +++ b/nix/overlay.nix @@ -0,0 +1,26 @@ +{ idris2Version, shortRev ? null }: +final: prev: +let + chezSupportsSystem = (prev.system == "x86_64-linux") + || (prev.lib.versionAtLeast prev.chez.version "10.0.0"); + chez = if chezSupportsSystem then prev.chez else prev.chez-racket; + idris2Bootstrap = prev.callPackage ./package.nix { + inherit chez idris2Version; + inherit (final.idris2Packages) support; + idris2Bootstrap = null; + srcRev = if shortRev == null then "dirty" else shortRev; + }; +in +{ + idris2Packages = prev.idris2Packages // { + support = prev.callPackage ./support.nix { inherit idris2Version; }; + idris2 = prev.callPackage ./package.nix { + inherit chez idris2Bootstrap idris2Version; + inherit (final.idris2Packages) support; + srcRev = if shortRev == null then "dirty" else shortRev; + }; + buildIdris = final.callPackage ./buildIdris.nix { inherit idris2Version; }; + idris2Api = final.callPackage ./idris2Api.nix { inherit idris2Version; }; + }; + idris2 = final.idris2Packages.idris2; +} diff --git a/nix/package.nix b/nix/package.nix index 2ee33cfbde..8197754482 100644 --- a/nix/package.nix +++ b/nix/package.nix @@ -1,5 +1,5 @@ -{ stdenv, lib, chez, clang, gmp, makeWrapper, installShellFiles, support, idris2Version -, srcRev, gambit, nodejs, zsh, idris2Bootstrap ? null }: +{ stdenv, lib, chez, clang, gmp, makeWrapper, installShellFiles, idris2Version +, srcRev, gambit, nodejs, support, zsh, idris2Bootstrap ? null }: # Uses scheme to bootstrap the build of idris2 let diff --git a/nix/text-editor.nix b/nix/text-editor.nix index 6b360cac13..b743d7dd7a 100644 --- a/nix/text-editor.nix +++ b/nix/text-editor.nix @@ -1,4 +1,4 @@ -{ pkgs, idris-emacs-src, idris2Pkg }: +{ pkgs, idris-emacs-src, idris2 }: with pkgs; let init-file = ./init.el; @@ -19,7 +19,7 @@ in rec { idris-emacs = emacsWithPackages [ idris2-mode ]; emacs-dev = makeEmacsWrapper "emacs-dev" idris-emacs init-file; emacs-with-idris = writeShellScriptBin "emacs-with-idris" '' - export PATH=${idris2Pkg}/bin:$PATH + export PATH=${idris2}/bin:$PATH ${emacs-dev}/bin/emacs-dev $@ ''; } From e2430b517c7975c09ab83d25069a1124f2ac12d6 Mon Sep 17 00:00:00 2001 From: mitchmindtree Date: Mon, 30 Sep 2024 19:58:11 +1000 Subject: [PATCH 2/2] [ refactor ] Declare overlay in terms of flake package outputs --- flake.nix | 59 +++++++++++++++++++++++++++++++++++---------- nix/buildIdris.nix | 3 +-- nix/idris2Api.nix | 4 +-- nix/overlay.nix | 26 -------------------- nix/package.nix | 4 +-- nix/text-editor.nix | 4 +-- 6 files changed, 53 insertions(+), 47 deletions(-) delete mode 100644 nix/overlay.nix diff --git a/flake.nix b/flake.nix index 5edcd55606..77eaa54c06 100644 --- a/flake.nix +++ b/flake.nix @@ -22,18 +22,51 @@ description = "A custom Idris 2 package with dependencies"; }; defaultTemplate = templates.pkg; - overlays.default = import ./nix/overlay.nix { - inherit idris2Version; - shortRev = self.shortRev or null; - }; version = idris2Version; + overlays.default = final: prev: + let + outputPackages = prev.lib.filterAttrs + (n: _: n != "default" && n != "idris2Api") + self.packages.${prev.system}; + idris2Api = final.callPackage ./nix/idris2Api.nix { + inherit (final.idris2Packages) buildIdris; + inherit idris2Version; + }; + in + { + idris2Packages = prev.idris2Packages // outputPackages // { inherit idris2Api; }; + idris2 = final.idris2Packages.idris2; + }; }; per-system = { config ? { }, overlays ? [ ] }: system: let - pkgs = import nixpkgs { - inherit config system; - overlays = overlays ++ [ self.overlays.default ]; + pkgs = import nixpkgs { inherit config system overlays; }; + chezSupportsSystem = (system == "x86_64-linux") + || (pkgs.lib.versionAtLeast pkgs.chez.version "10.0.0"); + chez = if chezSupportsSystem then + pkgs.chez + else + pkgs.chez-racket; + idris2Support = pkgs.callPackage ./nix/support.nix { inherit idris2Version; }; + idris2Bootstrap = pkgs.callPackage ./nix/package.nix { + inherit idris2Version chez; + idris2Bootstrap = null; + support = idris2Support; + srcRev = self.shortRev or "dirty"; + }; + idris2Pkg = pkgs.callPackage ./nix/package.nix { + inherit idris2Version chez idris2Bootstrap; + support = idris2Support; + srcRev = self.shortRev or "dirty"; + }; + buildIdris = pkgs.callPackage ./nix/buildIdris.nix { + inherit idris2Version; + idris2 = idris2Pkg; + support = idris2Support; + }; + idris2ApiPkg = pkgs.callPackage ./nix/idris2Api.nix { + inherit idris2Version buildIdris; }; stdenv' = with pkgs; if stdenv.isDarwin then overrideSDK stdenv "11.0" else stdenv; in { @@ -43,16 +76,16 @@ idris = self; }; packages = rec { - inherit (pkgs.idris2Packages) support idris2; - idris2Api = pkgs.idris2Packages.idris2Api.library { withSource = true; }; + support = idris2Support; + idris2 = idris2Pkg; + idris2Api = idris2ApiPkg.library { withSource = true; }; default = idris2; } // (import ./nix/text-editor.nix { - inherit (pkgs) idris2; - inherit pkgs idris-emacs-src; + inherit pkgs idris-emacs-src idris2Pkg; }); - inherit (pkgs.idris2Packages) buildIdris; + inherit buildIdris; devShells.default = pkgs.mkShell.override { stdenv = stdenv'; } { - packages = pkgs.idris2.buildInputs; + packages = idris2Pkg.buildInputs; }; }; in lib.mkOvrOptsFlake diff --git a/nix/buildIdris.nix b/nix/buildIdris.nix index f194416e85..9aa49394b0 100644 --- a/nix/buildIdris.nix +++ b/nix/buildIdris.nix @@ -1,4 +1,4 @@ -{ stdenv, lib, idris2Version, idris2Packages, jq, makeWrapper }: +{ stdenv, lib, idris2Version, idris2, jq, support, makeWrapper }: # Usage: let # pkg = idris2Pkg.buildIdris { # src = ...; @@ -20,7 +20,6 @@ let # loop over idrisLibraries and normalize them by turning any that are # direct outputs of the buildIdris function into the `.library {}` # property. - inherit (idris2Packages) idris2 support; idrisLibraryLibs = map (idrisLib: if lib.isDerivation idrisLib then idrisLib diff --git a/nix/idris2Api.nix b/nix/idris2Api.nix index 097e939844..23234c7a5e 100644 --- a/nix/idris2Api.nix +++ b/nix/idris2Api.nix @@ -1,5 +1,5 @@ -{ idris2Packages, idris2Version }: -idris2Packages.buildIdris { +{ buildIdris, idris2Version }: +buildIdris { src = ./..; ipkgName = "idris2api"; version = idris2Version; diff --git a/nix/overlay.nix b/nix/overlay.nix deleted file mode 100644 index 251db46d59..0000000000 --- a/nix/overlay.nix +++ /dev/null @@ -1,26 +0,0 @@ -{ idris2Version, shortRev ? null }: -final: prev: -let - chezSupportsSystem = (prev.system == "x86_64-linux") - || (prev.lib.versionAtLeast prev.chez.version "10.0.0"); - chez = if chezSupportsSystem then prev.chez else prev.chez-racket; - idris2Bootstrap = prev.callPackage ./package.nix { - inherit chez idris2Version; - inherit (final.idris2Packages) support; - idris2Bootstrap = null; - srcRev = if shortRev == null then "dirty" else shortRev; - }; -in -{ - idris2Packages = prev.idris2Packages // { - support = prev.callPackage ./support.nix { inherit idris2Version; }; - idris2 = prev.callPackage ./package.nix { - inherit chez idris2Bootstrap idris2Version; - inherit (final.idris2Packages) support; - srcRev = if shortRev == null then "dirty" else shortRev; - }; - buildIdris = final.callPackage ./buildIdris.nix { inherit idris2Version; }; - idris2Api = final.callPackage ./idris2Api.nix { inherit idris2Version; }; - }; - idris2 = final.idris2Packages.idris2; -} diff --git a/nix/package.nix b/nix/package.nix index 8197754482..2ee33cfbde 100644 --- a/nix/package.nix +++ b/nix/package.nix @@ -1,5 +1,5 @@ -{ stdenv, lib, chez, clang, gmp, makeWrapper, installShellFiles, idris2Version -, srcRev, gambit, nodejs, support, zsh, idris2Bootstrap ? null }: +{ stdenv, lib, chez, clang, gmp, makeWrapper, installShellFiles, support, idris2Version +, srcRev, gambit, nodejs, zsh, idris2Bootstrap ? null }: # Uses scheme to bootstrap the build of idris2 let diff --git a/nix/text-editor.nix b/nix/text-editor.nix index b743d7dd7a..6b360cac13 100644 --- a/nix/text-editor.nix +++ b/nix/text-editor.nix @@ -1,4 +1,4 @@ -{ pkgs, idris-emacs-src, idris2 }: +{ pkgs, idris-emacs-src, idris2Pkg }: with pkgs; let init-file = ./init.el; @@ -19,7 +19,7 @@ in rec { idris-emacs = emacsWithPackages [ idris2-mode ]; emacs-dev = makeEmacsWrapper "emacs-dev" idris-emacs init-file; emacs-with-idris = writeShellScriptBin "emacs-with-idris" '' - export PATH=${idris2}/bin:$PATH + export PATH=${idris2Pkg}/bin:$PATH ${emacs-dev}/bin/emacs-dev $@ ''; }