From d5d4a1d96c926461f9ea8ae5fefd7665699eeaa1 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Wed, 18 Dec 2024 09:30:00 -0600 Subject: [PATCH] Break up flake --- templates/elixir/flake.lock | 27 ++++++++++ templates/elixir/flake.nix | 78 ++-------------------------- templates/elixir/nix/boilerplate.nix | 16 ++++++ templates/elixir/nix/overlays.nix | 16 ++++++ templates/elixir/nix/packages.nix | 24 +++++++++ templates/elixir/nix/shells.nix | 15 ++++++ 6 files changed, 103 insertions(+), 73 deletions(-) create mode 100644 templates/elixir/flake.lock create mode 100644 templates/elixir/nix/boilerplate.nix create mode 100644 templates/elixir/nix/overlays.nix create mode 100644 templates/elixir/nix/packages.nix create mode 100644 templates/elixir/nix/shells.nix diff --git a/templates/elixir/flake.lock b/templates/elixir/flake.lock new file mode 100644 index 0000000..9055d38 --- /dev/null +++ b/templates/elixir/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1734435836, + "narHash": "sha256-kMBQ5PRiFLagltK0sH+08aiNt3zGERC2297iB6vrvlU=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "4989a246d7a390a859852baddb1013f825435cee", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/templates/elixir/flake.nix b/templates/elixir/flake.nix index ec7904f..aaeea38 100644 --- a/templates/elixir/flake.nix +++ b/templates/elixir/flake.nix @@ -3,79 +3,11 @@ nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; }; - outputs = { - self, - nixpkgs, - ... - }: let - inherit (self) outputs; - - supportedSystems = [ - "aarch64-linux" - "x86_64-linux" - - "x86_64-darwin" - "aarch64-darwin" - ]; - - forAllSystems = nixpkgs.lib.genAttrs supportedSystems; - - overlay = final: prev: { - erlangPackages = prev.beam.packagesWith prev.erlang_26; - erlang = final.erlangPackages.erlang; - elixir = final.erlangPackages.elixir_1_16; - - mixRelease = final.erlangPackages.mixRelease.override { - elixir = final.elixir; - }; - fetchMixDeps = final.erlangPackages.fetchMixDeps.override { - elixir = final.elixir; - }; - - elixir-ls = prev.elixir-ls.override {elixir = final.elixir;}; - }; - - nixpkgsFor = system: ((import nixpkgs {inherit system;}).extend overlay); + outputs = inputs: let + inherit (import nix/boilerplate.nix inputs) call; in { - packages = forAllSystems (system: let - pkgs = nixpkgsFor system; - - inherit (pkgs) beamPackages; - inherit (beamPackages) mixRelease fetchMixDeps; - - version = "0.1.0"; - src = ./.; - pname = "api.lyte.dev"; - in { - /* - this-package = mixRelease { - inherit pname version src; - mixFodDeps = fetchMixDeps { - inherit version src; - pname = "mix-deps-${pname}"; - hash = pkgs.lib.fakeSha256; - }; - buildInputs = with pkgs; [sqlite]; - HOME = "$(pwd)"; - MIX_XDG = "$HOME"; - }; - - default = outputs.packages.${system}.this-package; - */ - }); - - devShells = forAllSystems (system: let - pkgs = nixpkgsFor system; - in { - default = pkgs.mkShell { - shellHook = "export LOCALE_ARCHIVE=/usr/lib/locale/locale-archive"; - buildInputs = with pkgs; [ - elixir - elixir-ls - - inotify-tools - ]; - }; - }); + overlays = import nix/overlays.nix; + packages = call (import nix/packages.nix); + devShells = call (import nix/shells.nix); }; } diff --git a/templates/elixir/nix/boilerplate.nix b/templates/elixir/nix/boilerplate.nix new file mode 100644 index 0000000..2778326 --- /dev/null +++ b/templates/elixir/nix/boilerplate.nix @@ -0,0 +1,16 @@ +inputs @ { + nixpkgs, + self, + ... +}: let + forSelfOverlay = + if builtins.hasAttr "forSelf" self.overlays + then self.overlays.forSelf + else (_: p: p); +in rec { + systems = ["aarch64-linux" "x86_64-linux" "x86_64-darwin" "aarch64-darwin"]; + forSystems = nixpkgs.lib.genAttrs systems; + pkgsFor = system: ((import nixpkgs {inherit system;}).extend forSelfOverlay); + genPkgs = func: (forSystems (system: func (pkgsFor system))); + call = imported: genPkgs (pkgs: imported (inputs // {inherit pkgs;})); +} diff --git a/templates/elixir/nix/overlays.nix b/templates/elixir/nix/overlays.nix new file mode 100644 index 0000000..912427f --- /dev/null +++ b/templates/elixir/nix/overlays.nix @@ -0,0 +1,16 @@ +{ + forrSelf = final: prev: { + erlangPackages = prev.beam.packagesWith prev.erlang_28; + erlang = final.erlangPackages.erlang; + elixir = final.erlangPackages.elixir_1_17; + + mixRelease = final.erlangPackages.mixRelease.override { + elixir = final.elixir; + }; + fetchMixDeps = final.erlangPackages.fetchMixDeps.override { + elixir = final.elixir; + }; + + elixir-ls = prev.elixir-ls.override {elixir = final.elixir;}; + }; +} diff --git a/templates/elixir/nix/packages.nix b/templates/elixir/nix/packages.nix new file mode 100644 index 0000000..42e6288 --- /dev/null +++ b/templates/elixir/nix/packages.nix @@ -0,0 +1,24 @@ +{ + pkgs, + self, + ... +}: { + my-package = let + version = "1.0.0"; + src = ./.; + pname = "my-package"; + in + pkgs.beamPackages.mixRelease { + inherit pname version src; + mixFodDeps = pkgs.beamPackages.fetchMixDeps { + inherit version src; + pname = "mix-deps-${pname}"; + hash = pkgs.lib.fakeSha256; + }; + # buildInputs = with pkgs; []; + # HOME = "$(pwd)"; + # MIX_XDG = "$HOME"; + }; + + default = self.packages.${pkgs.system}.my-package; +} diff --git a/templates/elixir/nix/shells.nix b/templates/elixir/nix/shells.nix new file mode 100644 index 0000000..7a7512a --- /dev/null +++ b/templates/elixir/nix/shells.nix @@ -0,0 +1,15 @@ +{ + pkgs, + # self, + ... +}: { + elixir-dev = pkgs.mkShell { + shellHook = "export LOCALE_ARCHIVE=/usr/lib/locale/locale-archive"; + # inputsFrom = [self.packages.${pkgs.system}.my-package]; + buildInputs = with pkgs; [ + elixir + elixir-ls + inotify-tools + ]; + }; +}