nix: compile deps with the same elixir version

This commit is contained in:
Daniel Kempkens 2023-07-31 00:53:38 +02:00
parent ed89285fc8
commit 7cf7b03966
Signed by: daniel
SSH key fingerprint: SHA256:Ks/MyhQYcPRQiwMKLAKquWCdCPe3JXlb1WttgnAoSeM
4 changed files with 242 additions and 38 deletions

1
.gitignore vendored
View file

@ -18,5 +18,6 @@ erl_crash.dump
# nix # nix
/.direnv /.direnv
.pre-commit-config.yaml
/.elixir_ls /.elixir_ls
/result /result

View file

@ -1,5 +1,21 @@
{ {
"nodes": { "nodes": {
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1673956053,
"narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-parts": { "flake-parts": {
"inputs": { "inputs": {
"nixpkgs-lib": "nixpkgs-lib" "nixpkgs-lib": "nixpkgs-lib"
@ -18,6 +34,39 @@
"type": "github" "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": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1685518550,
"narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"gitignore": { "gitignore": {
"inputs": { "inputs": {
"nixpkgs": [ "nixpkgs": [
@ -40,11 +89,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1688859638, "lastModified": 1690720142,
"narHash": "sha256-GyRhX8GlTQqDWx43uBFEYEQ/WKEqDwjzABHxUCatAno=", "narHash": "sha256-GywuiZjBKfFkntQwpNQfL+Ksa2iGjPprBGL0/psgRZM=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "d485da9d0034a72ceb9679c2ab0156c073f66b82", "rev": "3acb5c4264c490e7714d503c7166a3fde0c51324",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -72,11 +121,91 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs-stable": {
"locked": {
"lastModified": 1685801374,
"narHash": "sha256-otaSUoFEMM+LjBI1XL/xGB5ao6IwnZOXc47qhIgJe8U=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "c37ca420157f4abc31e26f436c1145f8951ff373",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-23.05",
"repo": "nixpkgs",
"type": "github"
}
},
"pre-commit-hooks-nix": {
"inputs": {
"flake-compat": "flake-compat",
"flake-utils": "flake-utils",
"gitignore": [
"gitignore"
],
"nixpkgs": [
"nixpkgs"
],
"nixpkgs-stable": "nixpkgs-stable"
},
"locked": {
"lastModified": 1690743255,
"narHash": "sha256-dsJzQsyJGWCym1+LMyj2rbYmvjYmzeOrk7ypPrSFOPo=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "fcbf4705d98398d084e6cb1c826a0b90a91d22d7",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"type": "github"
}
},
"root": { "root": {
"inputs": { "inputs": {
"flake-parts": "flake-parts", "flake-parts": "flake-parts",
"flake-root": "flake-root",
"gitignore": "gitignore", "gitignore": "gitignore",
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs",
"pre-commit-hooks-nix": "pre-commit-hooks-nix",
"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"
]
},
"locked": {
"lastModified": 1689620039,
"narHash": "sha256-BtNwghr05z7k5YMdq+6nbue+nEalvDepuA7qdQMAKoQ=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "719c2977f958c41fa60a928e2fbc50af14844114",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
} }
} }
}, },

103
flake.nix
View file

@ -2,45 +2,87 @@
description = "weewx-proxy development environment"; description = "weewx-proxy development environment";
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
# Tools
flake-parts.url = "github:hercules-ci/flake-parts"; flake-parts.url = "github:hercules-ci/flake-parts";
flake-root.url = "github:srid/flake-root";
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
gitignore = { gitignore = {
url = "github:hercules-ci/gitignore.nix"; url = "github:hercules-ci/gitignore.nix";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
pre-commit-hooks-nix = {
url = "github:cachix/pre-commit-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.gitignore.follows = "gitignore";
};
}; };
outputs = inputs@{ flake-parts, gitignore, ... }: outputs = inputs@{ flake-parts, gitignore, ... }:
flake-parts.lib.mkFlake { inherit inputs; } { flake-parts.lib.mkFlake { inherit inputs; } {
systems = [ "aarch64-darwin" "x86_64-linux" "aarch64-linux" ]; systems = [ "aarch64-darwin" "x86_64-linux" "aarch64-linux" ];
perSystem = { pkgs, lib, self', ... }: imports = [
inputs.flake-root.flakeModule
inputs.treefmt-nix.flakeModule
inputs.pre-commit-hooks-nix.flakeModule
];
perSystem = { pkgs, config, lib, self', ... }:
let let
pname = "weewx-proxy"; pname = "weewx-proxy";
version = "0.0.1"; version = "0.0.1";
erlang = pkgs.beam.interpreters.erlangR26; erlang = pkgs.beam.interpreters.erlangR26;
beamPackages = pkgs.beam.packagesWith erlang; beamPackagesPrev = pkgs.beam.packagesWith erlang;
elixir = beamPackages.elixir_1_15; elixir = beamPackagesPrev.elixir_1_15;
beamPackages = beamPackagesPrev // rec {
inherit erlang elixir;
hex = beamPackagesPrev.hex.override { inherit elixir; };
buildMix = beamPackagesPrev.buildMix.override { inherit elixir erlang hex; };
mixRelease = beamPackagesPrev.mixRelease.override { inherit erlang elixir; };
};
inherit (pkgs.stdenv) isDarwin; inherit (pkgs.stdenv) isDarwin;
inherit (gitignore.lib) gitignoreSource; inherit (gitignore.lib) gitignoreSource;
in in
{ {
devShells.default = pkgs.mkShell { treefmt = {
packages = (with pkgs; [ inherit (config.flake-root) projectRootFile;
erlang flakeCheck = false;
elixir
beamPackages.elixir-ls programs = {
mix2nix mix-format = {
mosquitto enable = true;
]) ++ lib.optionals isDarwin (with pkgs.darwin.apple_sdk.frameworks; [ package = elixir;
CoreFoundation };
CoreServices
]);
ERL_INCLUDE_PATH = "${erlang}/lib/erlang/usr/include"; nixpkgs-fmt.enable = true;
shfmt.enable = true;
};
};
pre-commit = {
check.enable = false;
settings = {
excludes = [ "mix.nix" ];
hooks = {
deadnix.enable = true;
statix.enable = true;
treefmt.enable = true;
};
};
}; };
packages.default = beamPackages.mixRelease { packages.default = beamPackages.mixRelease {
@ -54,6 +96,9 @@
name = pname; name = pname;
tag = "v${version}"; tag = "v${version}";
config = { config = {
Env = [
"LANG=C.UTF-8"
];
ExposedPorts = { "4040/tcp" = { }; }; ExposedPorts = { "4040/tcp" = { }; };
Entrypoint = [ "${self'.packages.default}/bin/weewx_proxy" ]; Entrypoint = [ "${self'.packages.default}/bin/weewx_proxy" ];
Cmd = [ "start" ]; Cmd = [ "start" ];
@ -61,6 +106,34 @@
}; };
apps.default = { type = "app"; program = "${self'.packages.default}/bin/weewx_proxy"; }; apps.default = { type = "app"; program = "${self'.packages.default}/bin/weewx_proxy"; };
devShells.default = pkgs.mkShell {
name = pname;
nativeBuildInputs = [
erlang
elixir
] ++ lib.optionals isDarwin (with pkgs.darwin.apple_sdk.frameworks;
[
CoreFoundation
CoreServices
]);
packages = [
beamPackages.elixir-ls
pkgs.mix2nix
pkgs.mosquitto
];
inputsFrom = [
config.flake-root.devShell
config.treefmt.build.devShell
config.pre-commit.devShell
];
ERL_INCLUDE_PATH = "${erlang}/lib/erlang/usr/include";
TREEFMT_CONFIG_FILE = config.treefmt.build.configFile;
};
}; };
}; };
} }

39
mix.nix
View file

@ -1,4 +1,4 @@
{ lib, beamPackages, overrides ? (x: y: {}) }: { lib, beamPackages, overrides ? (x: y: { }) }:
let let
buildRebar3 = lib.makeOverridable beamPackages.buildRebar3; buildRebar3 = lib.makeOverridable beamPackages.buildRebar3;
@ -18,7 +18,7 @@ let
sha256 = "0ha6vmf5p3xlbf5w1msa89frhvfk535rnyfybz9wdmh6vdms8v96"; sha256 = "0ha6vmf5p3xlbf5w1msa89frhvfk535rnyfybz9wdmh6vdms8v96";
}; };
beamDeps = []; beamDeps = [ ];
}; };
cowboy = buildErlangMk rec { cowboy = buildErlangMk rec {
@ -57,7 +57,7 @@ let
sha256 = "1c4dgi8canscyjgddp22mjc69znvwy44wk3r7jrl2wvs6vv76fqn"; sha256 = "1c4dgi8canscyjgddp22mjc69znvwy44wk3r7jrl2wvs6vv76fqn";
}; };
beamDeps = []; beamDeps = [ ];
}; };
dialyxir = buildMix rec { dialyxir = buildMix rec {
@ -83,7 +83,7 @@ let
sha256 = "18gr9cvjar9rrmcj0crgwjb4np4adfbwcaxijajhwpjzvamwfq04"; sha256 = "18gr9cvjar9rrmcj0crgwjb4np4adfbwcaxijajhwpjzvamwfq04";
}; };
beamDeps = []; beamDeps = [ ];
}; };
erlex = buildMix rec { erlex = buildMix rec {
@ -96,7 +96,7 @@ let
sha256 = "0x8c1j62y748ldvlh46sxzv5514rpzm809vxn594vd7y25by5lif"; sha256 = "0x8c1j62y748ldvlh46sxzv5514rpzm809vxn594vd7y25by5lif";
}; };
beamDeps = []; beamDeps = [ ];
}; };
gen_state_machine = buildMix rec { gen_state_machine = buildMix rec {
@ -109,7 +109,7 @@ let
sha256 = "05gdy0cxsmg3j43xmd6vm3nzsi8vlk94kdzn15rypg5yfhjnan8a"; sha256 = "05gdy0cxsmg3j43xmd6vm3nzsi8vlk94kdzn15rypg5yfhjnan8a";
}; };
beamDeps = []; beamDeps = [ ];
}; };
hackney = buildRebar3 rec { hackney = buildRebar3 rec {
@ -161,7 +161,7 @@ let
sha256 = "18d70i31bz11nr6vgsjn5prvhkvwqbyf3xq22ck5cnsnzp6ixc7v"; sha256 = "18d70i31bz11nr6vgsjn5prvhkvwqbyf3xq22ck5cnsnzp6ixc7v";
}; };
beamDeps = []; beamDeps = [ ];
}; };
metrics = buildRebar3 rec { metrics = buildRebar3 rec {
@ -174,7 +174,7 @@ let
sha256 = "05lz15piphyhvvm3d1ldjyw0zsrvz50d2m5f2q3s8x2gvkfrmc39"; sha256 = "05lz15piphyhvvm3d1ldjyw0zsrvz50d2m5f2q3s8x2gvkfrmc39";
}; };
beamDeps = []; beamDeps = [ ];
}; };
mime = buildMix rec { mime = buildMix rec {
@ -187,7 +187,7 @@ let
sha256 = "0p50h0ki8ay5sraiqxiajgwy1829bvyagj65bj9wjny4cnin83fs"; sha256 = "0p50h0ki8ay5sraiqxiajgwy1829bvyagj65bj9wjny4cnin83fs";
}; };
beamDeps = []; beamDeps = [ ];
}; };
mimerl = buildRebar3 rec { mimerl = buildRebar3 rec {
@ -200,7 +200,7 @@ let
sha256 = "08wkw73dy449n68ssrkz57gikfzqk3vfnf264s31jn5aa1b5hy7j"; sha256 = "08wkw73dy449n68ssrkz57gikfzqk3vfnf264s31jn5aa1b5hy7j";
}; };
beamDeps = []; beamDeps = [ ];
}; };
parse_trans = buildRebar3 rec { parse_trans = buildRebar3 rec {
@ -213,7 +213,7 @@ let
sha256 = "12w8ai6b5s6b4hnvkav7hwxd846zdd74r32f84nkcmjzi1vrbk87"; sha256 = "12w8ai6b5s6b4hnvkav7hwxd846zdd74r32f84nkcmjzi1vrbk87";
}; };
beamDeps = []; beamDeps = [ ];
}; };
plug = buildMix rec { plug = buildMix rec {
@ -252,7 +252,7 @@ let
sha256 = "0hnqgzc3zas7j7wycgnkkdhaji5farkqccy2n4p1gqj5ccfrlm16"; sha256 = "0hnqgzc3zas7j7wycgnkkdhaji5farkqccy2n4p1gqj5ccfrlm16";
}; };
beamDeps = []; beamDeps = [ ];
}; };
ranch = buildRebar3 rec { ranch = buildRebar3 rec {
@ -265,7 +265,7 @@ let
sha256 = "1rfz5ld54pkd2w25jadyznia2vb7aw9bclck21fizargd39wzys9"; sha256 = "1rfz5ld54pkd2w25jadyznia2vb7aw9bclck21fizargd39wzys9";
}; };
beamDeps = []; beamDeps = [ ];
}; };
ssl_verify_fun = buildRebar3 rec { ssl_verify_fun = buildRebar3 rec {
@ -278,7 +278,7 @@ let
sha256 = "1y37pj5q6gk1vrnwg1vraws9yihrv9g4133w2qq1sh1piw71jk7y"; sha256 = "1y37pj5q6gk1vrnwg1vraws9yihrv9g4133w2qq1sh1piw71jk7y";
}; };
beamDeps = []; beamDeps = [ ];
}; };
systemd = buildRebar3 rec { systemd = buildRebar3 rec {
@ -304,7 +304,7 @@ let
sha256 = "1mgyx9zw92g6w8fp9pblm3b0bghwxwwcbslrixq23ipzisfwxnfs"; sha256 = "1mgyx9zw92g6w8fp9pblm3b0bghwxwwcbslrixq23ipzisfwxnfs";
}; };
beamDeps = []; beamDeps = [ ];
}; };
tortoise311 = buildMix rec { tortoise311 = buildMix rec {
@ -330,7 +330,7 @@ let
sha256 = "0v8v3l8j7g3ran3f9gc2nc1mkj6kwfdr6kshm2cf3r0zlv1xa2y5"; sha256 = "0v8v3l8j7g3ran3f9gc2nc1mkj6kwfdr6kshm2cf3r0zlv1xa2y5";
}; };
beamDeps = []; beamDeps = [ ];
}; };
tz = buildMix rec { tz = buildMix rec {
@ -343,7 +343,7 @@ let
sha256 = "0s4yggr8d5192qkzrzx85xpgz6pg233hn14ll1w2f0qyvlc0cjr2"; sha256 = "0s4yggr8d5192qkzrzx85xpgz6pg233hn14ll1w2f0qyvlc0cjr2";
}; };
beamDeps = []; beamDeps = [ ];
}; };
unicode_util_compat = buildRebar3 rec { unicode_util_compat = buildRebar3 rec {
@ -356,8 +356,9 @@ let
sha256 = "08952lw8cjdw8w171lv8wqbrxc4rcmb3jhkrdb7n06gngpbfdvi5"; sha256 = "08952lw8cjdw8w171lv8wqbrxc4rcmb3jhkrdb7n06gngpbfdvi5";
}; };
beamDeps = []; beamDeps = [ ];
}; };
}; };
in self in
self