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;
};
}; };
}; };
} }

View file

@ -359,5 +359,6 @@ let
beamDeps = [ ]; beamDeps = [ ];
}; };
}; };
in self in
self