From 7ffd4fdd26b666b3801789dcc774856ce4f1a04f Mon Sep 17 00:00:00 2001 From: Alessandro Candido Date: Tue, 8 Aug 2023 19:08:25 +0200 Subject: [PATCH 01/16] Add nix files --- .envrc | 11 ++ .gitignore | 2 + flake.lock | 376 +++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 45 +++++++ 4 files changed, 434 insertions(+) create mode 100644 .envrc create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.envrc b/.envrc new file mode 100644 index 00000000..b351dff3 --- /dev/null +++ b/.envrc @@ -0,0 +1,11 @@ +if ! has nix_direnv_version || ! nix_direnv_version 2.2.1; then + source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.1/direnvrc" "sha256-zelF0vLbEl5uaqrfIzbgNzJWGmLzCmYAkInj/LNxvKs=" +fi + +nix_direnv_watch_file devenv.nix +nix_direnv_watch_file devenv.lock +nix_direnv_watch_file devenv.yaml +if ! use flake . --impure +then + echo "devenv could not be built. The devenv environment was not loaded. Make the necessary changes to devenv.nix and hit enter to try again." >&2 +fi diff --git a/.gitignore b/.gitignore index ea8c4bf7..c305a71e 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /target + +.devenv/ diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..5509f9b7 --- /dev/null +++ b/flake.lock @@ -0,0 +1,376 @@ +{ + "nodes": { + "devenv": { + "inputs": { + "flake-compat": "flake-compat", + "nix": "nix", + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks" + }, + "locked": { + "lastModified": 1691413946, + "narHash": "sha256-IQ9gWBnUMJaXXev9vjnUJDfX0y4tOprGF773xD0rwHA=", + "owner": "cachix", + "repo": "devenv", + "rev": "b4ce82b6a54022c688f9f916b9f7a9c9ed959de1", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "devenv", + "type": "github" + } + }, + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1691475627, + "narHash": "sha256-aOgYmNqXyCHw1vaNDv5GqUAURiPMVej4xQNE37bCF8g=", + "owner": "nix-community", + "repo": "fenix", + "rev": "72b64bd857cacd2733ce99fbf0603bbe335d357c", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "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-compat_2": { + "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-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" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1685518550, + "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", + "type": "github" + }, + "original": { + "id": "flake-utils", + "type": "indirect" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "devenv", + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1660459072, + "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "lowdown-src": { + "flake": false, + "locked": { + "lastModified": 1633514407, + "narHash": "sha256-Dw32tiMjdK9t3ETl5fzGrutQTzh2rufgZV4A/BbxuD4=", + "owner": "kristapsdz", + "repo": "lowdown", + "rev": "d2c2b44ff6c27b936ec27358a2653caaef8f73b8", + "type": "github" + }, + "original": { + "owner": "kristapsdz", + "repo": "lowdown", + "type": "github" + } + }, + "nix": { + "inputs": { + "lowdown-src": "lowdown-src", + "nixpkgs": [ + "devenv", + "nixpkgs" + ], + "nixpkgs-regression": "nixpkgs-regression" + }, + "locked": { + "lastModified": 1676545802, + "narHash": "sha256-EK4rZ+Hd5hsvXnzSzk2ikhStJnD63odF7SzsQ8CuSPU=", + "owner": "domenkozar", + "repo": "nix", + "rev": "7c91803598ffbcfe4a55c44ac6d49b2cf07a527f", + "type": "github" + }, + "original": { + "owner": "domenkozar", + "ref": "relaxed-flakes", + "repo": "nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1678875422, + "narHash": "sha256-T3o6NcQPwXjxJMn2shz86Chch4ljXgZn746c2caGxd8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "126f49a01de5b7e35a43fd43f891ecf6d3a51459", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-python": { + "inputs": { + "flake-compat": "flake-compat_2", + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs_3" + }, + "locked": { + "lastModified": 1690216544, + "narHash": "sha256-fWZVYvyoGTNzRnr6MDd0O2FLA2GwLCkSOlZbOxEBuk0=", + "owner": "cachix", + "repo": "nixpkgs-python", + "rev": "64b32e82cba00c8a1fdc53618ae8b5502866fe96", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "nixpkgs-python", + "type": "github" + } + }, + "nixpkgs-regression": { + "locked": { + "lastModified": 1643052045, + "narHash": "sha256-uGJ0VXIhWKGXxkeNnq4TvV3CIOkUJ3PAoLZ3HMzNVMw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2", + "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" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1688392541, + "narHash": "sha256-lHrKvEkCPTUO+7tPfjIcb7Trk6k31rz18vkyqmkeJfY=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "ea4c80b39be4c09702b0cb3b42eab59e2ba4f24b", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-22.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1685974512, + "narHash": "sha256-WLPHpe96RbPRO9iDtCxgsYkadTheRq7wqXWdGpR6g7w=", + "owner": "domenkozar", + "repo": "nixpkgs", + "rev": "1102477695918daba466123cc2ef694ed3a49939", + "type": "github" + }, + "original": { + "owner": "domenkozar", + "ref": "cpython-moduralize", + "repo": "nixpkgs", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": [ + "devenv", + "flake-compat" + ], + "flake-utils": "flake-utils", + "gitignore": "gitignore", + "nixpkgs": [ + "devenv", + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1688056373, + "narHash": "sha256-2+SDlNRTKsgo3LBRiMUcoEUb6sDViRNQhzJquZ4koOI=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "5843cf069272d92b60c3ed9e55b7a8989c01d4c7", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "devenv": "devenv", + "fenix": "fenix", + "nixpkgs": "nixpkgs_2", + "nixpkgs-python": "nixpkgs-python", + "systems": "systems_3" + } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1691410619, + "narHash": "sha256-npJ8zOZ/CQoZu+0kN5NU9iC5JbmbsucyK1DayPmHWPs=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "d9e9ca29814e95bb40db2216ed0973d9ba54b6a2", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_3": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..a2fafac2 --- /dev/null +++ b/flake.nix @@ -0,0 +1,45 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.11"; + systems.url = "github:nix-systems/default"; + devenv.url = "github:cachix/devenv"; + nixpkgs-python.url = "github:cachix/nixpkgs-python"; + fenix.url = "github:nix-community/fenix"; + fenix.inputs.nixpkgs.follows = "nixpkgs"; + }; + + nixConfig = { + extra-trusted-public-keys = "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw="; + extra-substituters = "https://devenv.cachix.org"; + }; + + outputs = { self, nixpkgs, devenv, systems, ... } @ inputs: + let + forEachSystem = nixpkgs.lib.genAttrs (import systems); + in + { + devShells = forEachSystem + (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + in + { + default = devenv.lib.mkShell { + inherit inputs pkgs; + modules = [ + { + languages.python = { + enable = true; + venv.enable = true; + version = "3.11"; + }; + languages.rust = { + enable = true; + channel = "stable"; + }; + } + ]; + }; + }); + }; +} From 81e26f8f503abd8d4cb7358aabff37300e8d9750 Mon Sep 17 00:00:00 2001 From: Alessandro Candido Date: Wed, 11 Oct 2023 19:11:55 +0200 Subject: [PATCH 02/16] Add maturin, update nixos distribution --- flake.lock | 8 +++---- flake.nix | 67 +++++++++++++++++++++++++++++------------------------- 2 files changed, 40 insertions(+), 35 deletions(-) diff --git a/flake.lock b/flake.lock index 5509f9b7..3732b67e 100644 --- a/flake.lock +++ b/flake.lock @@ -241,16 +241,16 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1688392541, - "narHash": "sha256-lHrKvEkCPTUO+7tPfjIcb7Trk6k31rz18vkyqmkeJfY=", + "lastModified": 1696697597, + "narHash": "sha256-q26Qv4DQ+h6IeozF2o1secyQG0jt2VUT3V0K58jr3pg=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "ea4c80b39be4c09702b0cb3b42eab59e2ba4f24b", + "rev": "5a237aecb57296f67276ac9ab296a41c23981f56", "type": "github" }, "original": { "owner": "NixOS", - "ref": "nixos-22.11", + "ref": "nixos-23.05", "repo": "nixpkgs", "type": "github" } diff --git a/flake.nix b/flake.nix index a2fafac2..dc2b473c 100644 --- a/flake.nix +++ b/flake.nix @@ -1,6 +1,6 @@ { inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.11"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05"; systems.url = "github:nix-systems/default"; devenv.url = "github:cachix/devenv"; nixpkgs-python.url = "github:cachix/nixpkgs-python"; @@ -8,38 +8,43 @@ fenix.inputs.nixpkgs.follows = "nixpkgs"; }; + outputs = { + self, + nixpkgs, + devenv, + systems, + ... + } @ inputs: let + forEachSystem = nixpkgs.lib.genAttrs (import systems); + in { + devShells = + forEachSystem + (system: let + pkgs = nixpkgs.legacyPackages.${system}; + in { + default = devenv.lib.mkShell { + inherit inputs pkgs; + modules = [ + { + packages = with pkgs; [maturin]; + + languages.python = { + enable = true; + venv.enable = true; + version = "3.11"; + }; + languages.rust = { + enable = true; + channel = "stable"; + }; + } + ]; + }; + }); + }; + nixConfig = { extra-trusted-public-keys = "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw="; extra-substituters = "https://devenv.cachix.org"; }; - - outputs = { self, nixpkgs, devenv, systems, ... } @ inputs: - let - forEachSystem = nixpkgs.lib.genAttrs (import systems); - in - { - devShells = forEachSystem - (system: - let - pkgs = nixpkgs.legacyPackages.${system}; - in - { - default = devenv.lib.mkShell { - inherit inputs pkgs; - modules = [ - { - languages.python = { - enable = true; - venv.enable = true; - version = "3.11"; - }; - languages.rust = { - enable = true; - channel = "stable"; - }; - } - ]; - }; - }); - }; } From fe11ee9e3927c03d5214c7068d549d843e8a1df4 Mon Sep 17 00:00:00 2001 From: Alessandro Candido Date: Sat, 24 Feb 2024 15:20:54 +0100 Subject: [PATCH 03/16] Add lhapdf dependency, setup shell to ease its usage --- flake.nix | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index dc2b473c..7dd8a186 100644 --- a/flake.nix +++ b/flake.nix @@ -21,12 +21,25 @@ forEachSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; + pwd = builtins.getEnv "PWD"; + path = builtins.getEnv "PATH"; + prefix = "${pwd}/target/prefix"; + lhapath = "${prefix}/share/LHAPDF"; in { default = devenv.lib.mkShell { inherit inputs pkgs; modules = [ { - packages = with pkgs; [maturin]; + packages = with pkgs; [maturin lhapdf]; + + env = { + PREFIX = prefix; + PATH = "${path}:${prefix}/bin"; + LHAPDF_DATA_PATH = lhapath; + }; + enterShell = '' + mkdir -p ${lhapath} + ''; languages.python = { enable = true; From 63f5af60c6b2841ebac81e784c1e917e1ab57b4f Mon Sep 17 00:00:00 2001 From: Alessandro Candido Date: Sun, 25 Feb 2024 10:25:30 +0100 Subject: [PATCH 04/16] Propagate Python version to the LHAPDF package --- flake.nix | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index 7dd8a186..89d7c428 100644 --- a/flake.nix +++ b/flake.nix @@ -29,8 +29,14 @@ default = devenv.lib.mkShell { inherit inputs pkgs; modules = [ - { - packages = with pkgs; [maturin lhapdf]; + ({config, ...}: { + packages = with pkgs; [ + maturin + (lhapdf.override { + python = + config.languages.python.package; + }) + ]; env = { PREFIX = prefix; @@ -50,7 +56,7 @@ enable = true; channel = "stable"; }; - } + }) ]; }; }); From de231016438668f3998ba67417283d00b96fe78a Mon Sep 17 00:00:00 2001 From: Alessandro Candido Date: Sun, 25 Feb 2024 10:28:16 +0100 Subject: [PATCH 05/16] Use PATH variable from module system If taken directly from the environment, it will lose all the additions made by the Nix packages Accessing the value from the configuration will always improve self-consistency --- flake.nix | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index 89d7c428..a979095f 100644 --- a/flake.nix +++ b/flake.nix @@ -22,14 +22,15 @@ (system: let pkgs = nixpkgs.legacyPackages.${system}; pwd = builtins.getEnv "PWD"; - path = builtins.getEnv "PATH"; prefix = "${pwd}/target/prefix"; lhapath = "${prefix}/share/LHAPDF"; in { default = devenv.lib.mkShell { inherit inputs pkgs; modules = [ - ({config, ...}: { + ({config, ...}: let + path = config.system.path; + in { packages = with pkgs; [ maturin (lhapdf.override { From 8273e9125f061d62073d14ba56dd161696097646 Mon Sep 17 00:00:00 2001 From: Alessandro Candido Date: Sun, 25 Feb 2024 11:54:31 +0100 Subject: [PATCH 06/16] Drop path extension, temporarily --- flake.nix | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/flake.nix b/flake.nix index a979095f..bae3eb8a 100644 --- a/flake.nix +++ b/flake.nix @@ -28,9 +28,7 @@ default = devenv.lib.mkShell { inherit inputs pkgs; modules = [ - ({config, ...}: let - path = config.system.path; - in { + ({config, ...}: { packages = with pkgs; [ maturin (lhapdf.override { @@ -41,7 +39,6 @@ env = { PREFIX = prefix; - PATH = "${path}:${prefix}/bin"; LHAPDF_DATA_PATH = lhapath; }; enterShell = '' From a641decc59172003831608e4e95997ecf055d4f2 Mon Sep 17 00:00:00 2001 From: Alessandro Candido Date: Sun, 25 Feb 2024 12:55:20 +0100 Subject: [PATCH 07/16] Set pineappl PATH in the trivial way Just run a shell export command right before entering the shell --- flake.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/flake.nix b/flake.nix index bae3eb8a..ea008d41 100644 --- a/flake.nix +++ b/flake.nix @@ -42,6 +42,9 @@ LHAPDF_DATA_PATH = lhapath; }; enterShell = '' + # update path before entering the shell, when Nix packages updates + # already happened + export PATH=${prefix}/bin:$PATH mkdir -p ${lhapath} ''; From c2fdc4b2903e9cab5d1a01dd703fb5202125ba8a Mon Sep 17 00:00:00 2001 From: Alessandro Candido Date: Sun, 25 Feb 2024 15:10:21 +0100 Subject: [PATCH 08/16] Document Nix files added to the repo --- .gitignore | 1 + docs/maintainers-guide.md | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/.gitignore b/.gitignore index c305a71e..cd52e691 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /target +# Devenv files, to handle the development shell defined by the flake .devenv/ diff --git a/docs/maintainers-guide.md b/docs/maintainers-guide.md index cd31d69c..c9f493df 100644 --- a/docs/maintainers-guide.md +++ b/docs/maintainers-guide.md @@ -33,6 +33,7 @@ fastNLO tables to PineAPPL grids - `pineappl_py`: the crate that builds PineAPPL's Python interface - `xtask`: crate for [cargo-xtask] commands +- `.envrc`: [direnv] hooks (mainly enable Nix shell) - `.gitignore`: PineAPPL's Git ignore rules - `.readthedocs.yml`: configuration for PineAPPL's [Read-the-Docs] Python interface documentation @@ -44,6 +45,9 @@ - `README.md`: PineAPPL's repository README file. This file also serves as the homepage of [PineAPPL's website] - `_config.yml`: configuration file for PineAPPL's Github-pages website +- `flake.lock`: Nix [flake lock file] +- `flake.nix`: Nix [flake], which tracks cross-language dependencies to define a + reproducible build for the PineAPPL packages, and a suitable development shell - `install-capi.sh`: POSIX-compliant shell script to download and install PineAPPL's pre-built CAPI @@ -57,6 +61,9 @@ [lock file]: https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html [license v3]: https://www.gnu.org/licenses/gpl-3.0.en.html [PineAPPL's website]: https://nnpdf.github.io/pineappl/ +[flake]: https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html#flake-format +[flake lock file]: https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html#lock-files +[direnv]: https://direnv.net/ ## Abbreviations and terminology From d3c31d7cb4b3aa7a033ac34e672e37d52f824f24 Mon Sep 17 00:00:00 2001 From: Alessandro Candido Date: Thu, 21 Mar 2024 20:17:07 +0100 Subject: [PATCH 09/16] fix: Upgrade direnv watch directives --- .envrc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.envrc b/.envrc index b351dff3..46f1751e 100644 --- a/.envrc +++ b/.envrc @@ -2,9 +2,9 @@ if ! has nix_direnv_version || ! nix_direnv_version 2.2.1; then source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.1/direnvrc" "sha256-zelF0vLbEl5uaqrfIzbgNzJWGmLzCmYAkInj/LNxvKs=" fi -nix_direnv_watch_file devenv.nix -nix_direnv_watch_file devenv.lock -nix_direnv_watch_file devenv.yaml +watch_file devenv.nix +watch_file devenv.lock +watch_file devenv.yaml if ! use flake . --impure then echo "devenv could not be built. The devenv environment was not loaded. Make the necessary changes to devenv.nix and hit enter to try again." >&2 From 7b64d94ad70c431a074ff442265e75e0a7995c9b Mon Sep 17 00:00:00 2001 From: Alessandro Candido Date: Tue, 16 Apr 2024 13:32:43 +0200 Subject: [PATCH 10/16] fix: Remove fixed Python version If not specifically needed, the default should be good enough --- flake.lock | 87 +----------------------------------------------------- flake.nix | 2 -- 2 files changed, 1 insertion(+), 88 deletions(-) diff --git a/flake.lock b/flake.lock index 3732b67e..5ea56460 100644 --- a/flake.lock +++ b/flake.lock @@ -58,22 +58,6 @@ "type": "github" } }, - "flake-compat_2": { - "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-utils": { "inputs": { "systems": "systems" @@ -92,23 +76,6 @@ "type": "github" } }, - "flake-utils_2": { - "inputs": { - "systems": "systems_2" - }, - "locked": { - "lastModified": 1685518550, - "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", - "type": "github" - }, - "original": { - "id": "flake-utils", - "type": "indirect" - } - }, "gitignore": { "inputs": { "nixpkgs": [ @@ -187,26 +154,6 @@ "type": "github" } }, - "nixpkgs-python": { - "inputs": { - "flake-compat": "flake-compat_2", - "flake-utils": "flake-utils_2", - "nixpkgs": "nixpkgs_3" - }, - "locked": { - "lastModified": 1690216544, - "narHash": "sha256-fWZVYvyoGTNzRnr6MDd0O2FLA2GwLCkSOlZbOxEBuk0=", - "owner": "cachix", - "repo": "nixpkgs-python", - "rev": "64b32e82cba00c8a1fdc53618ae8b5502866fe96", - "type": "github" - }, - "original": { - "owner": "cachix", - "repo": "nixpkgs-python", - "type": "github" - } - }, "nixpkgs-regression": { "locked": { "lastModified": 1643052045, @@ -255,22 +202,6 @@ "type": "github" } }, - "nixpkgs_3": { - "locked": { - "lastModified": 1685974512, - "narHash": "sha256-WLPHpe96RbPRO9iDtCxgsYkadTheRq7wqXWdGpR6g7w=", - "owner": "domenkozar", - "repo": "nixpkgs", - "rev": "1102477695918daba466123cc2ef694ed3a49939", - "type": "github" - }, - "original": { - "owner": "domenkozar", - "ref": "cpython-moduralize", - "repo": "nixpkgs", - "type": "github" - } - }, "pre-commit-hooks": { "inputs": { "flake-compat": [ @@ -304,8 +235,7 @@ "devenv": "devenv", "fenix": "fenix", "nixpkgs": "nixpkgs_2", - "nixpkgs-python": "nixpkgs-python", - "systems": "systems_3" + "systems": "systems_2" } }, "rust-analyzer-src": { @@ -354,21 +284,6 @@ "repo": "default", "type": "github" } - }, - "systems_3": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } } }, "root": "root", diff --git a/flake.nix b/flake.nix index ea008d41..e8012456 100644 --- a/flake.nix +++ b/flake.nix @@ -3,7 +3,6 @@ nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05"; systems.url = "github:nix-systems/default"; devenv.url = "github:cachix/devenv"; - nixpkgs-python.url = "github:cachix/nixpkgs-python"; fenix.url = "github:nix-community/fenix"; fenix.inputs.nixpkgs.follows = "nixpkgs"; }; @@ -51,7 +50,6 @@ languages.python = { enable = true; venv.enable = true; - version = "3.11"; }; languages.rust = { enable = true; From 5f9627a4529d615c809ec44bb4397738703fcc9e Mon Sep 17 00:00:00 2001 From: Alessandro Candido Date: Tue, 23 Apr 2024 16:57:07 +0200 Subject: [PATCH 11/16] build: First attempt to package PineAPPL with crane --- flake.lock | 43 +++++++++++++++++++++++++++++++++++++++++-- flake.nix | 42 +++++++++++++++++++++++++++++------------- 2 files changed, 70 insertions(+), 15 deletions(-) diff --git a/flake.lock b/flake.lock index 5ea56460..48027055 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,25 @@ { "nodes": { + "crane": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1713738183, + "narHash": "sha256-qd/MuLm7OfKQKyd4FAMqV4H6zYyOfef5lLzRrmXwKJM=", + "owner": "ipetkov", + "repo": "crane", + "rev": "f6c6a2fb1b8bd9b65d65ca9342dd0eb180a63f11", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, "devenv": { "inputs": { "flake-compat": "flake-compat", @@ -76,6 +96,24 @@ "type": "github" } }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "gitignore": { "inputs": { "nixpkgs": [ @@ -232,10 +270,11 @@ }, "root": { "inputs": { + "crane": "crane", "devenv": "devenv", "fenix": "fenix", - "nixpkgs": "nixpkgs_2", - "systems": "systems_2" + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs_2" } }, "rust-analyzer-src": { diff --git a/flake.nix b/flake.nix index e8012456..ca29d2f4 100644 --- a/flake.nix +++ b/flake.nix @@ -1,8 +1,12 @@ { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05"; - systems.url = "github:nix-systems/default"; + flake-utils.url = "github:numtide/flake-utils"; devenv.url = "github:cachix/devenv"; + crane = { + url = "github:ipetkov/crane"; + inputs.nixpkgs.follows = "nixpkgs"; + }; fenix.url = "github:nix-community/fenix"; fenix.inputs.nixpkgs.follows = "nixpkgs"; }; @@ -10,21 +14,34 @@ outputs = { self, nixpkgs, + flake-utils, + crane, devenv, - systems, ... - } @ inputs: let - forEachSystem = nixpkgs.lib.genAttrs (import systems); - in { - devShells = - forEachSystem - (system: let - pkgs = nixpkgs.legacyPackages.${system}; + } @ inputs: + flake-utils.lib.eachDefaultSystem (system: let + pkgs = nixpkgs.legacyPackages.${system}; + in { + packages = let + craneLib = crane.lib.${system}; + pineappl = craneLib.buildPackage { + src = craneLib.cleanCargoSource (craneLib.path ./.); + strictDeps = true; + # buildInputs = [ # Add additional build inputs here ] + }; + in { + default = { + packages.default = pineappl; + packages.pineappl-py = null; + }; + }; + + devShells.default = let pwd = builtins.getEnv "PWD"; prefix = "${pwd}/target/prefix"; lhapath = "${prefix}/share/LHAPDF"; - in { - default = devenv.lib.mkShell { + in + devenv.lib.mkShell { inherit inputs pkgs; modules = [ ({config, ...}: { @@ -58,8 +75,7 @@ }) ]; }; - }); - }; + }); nixConfig = { extra-trusted-public-keys = "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw="; From d8a992a1e1effb71ea998c38a567a8a6b8d88dd5 Mon Sep 17 00:00:00 2001 From: Alessandro Candido Date: Tue, 23 Apr 2024 17:49:32 +0200 Subject: [PATCH 12/16] build: Package the CLI as well --- flake.lock | 8 +-- flake.nix | 143 ++++++++++++++++++++++++++++++++++------------------- 2 files changed, 96 insertions(+), 55 deletions(-) diff --git a/flake.lock b/flake.lock index 48027055..3be9fc15 100644 --- a/flake.lock +++ b/flake.lock @@ -226,16 +226,16 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1696697597, - "narHash": "sha256-q26Qv4DQ+h6IeozF2o1secyQG0jt2VUT3V0K58jr3pg=", + "lastModified": 1713714899, + "narHash": "sha256-+z/XjO3QJs5rLE5UOf015gdVauVRQd2vZtsFkaXBq2Y=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "5a237aecb57296f67276ac9ab296a41c23981f56", + "rev": "6143fc5eeb9c4f00163267708e26191d1e918932", "type": "github" }, "original": { "owner": "NixOS", - "ref": "nixos-23.05", + "ref": "nixos-unstable", "repo": "nixpkgs", "type": "github" } diff --git a/flake.nix b/flake.nix index ca29d2f4..b3e7be00 100644 --- a/flake.nix +++ b/flake.nix @@ -1,6 +1,6 @@ { inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; flake-utils.url = "github:numtide/flake-utils"; devenv.url = "github:cachix/devenv"; crane = { @@ -21,61 +21,102 @@ } @ inputs: flake-utils.lib.eachDefaultSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; - in { - packages = let - craneLib = crane.lib.${system}; - pineappl = craneLib.buildPackage { - src = craneLib.cleanCargoSource (craneLib.path ./.); - strictDeps = true; - # buildInputs = [ # Add additional build inputs here ] - }; - in { - default = { - packages.default = pineappl; - packages.pineappl-py = null; - }; - }; + in let + inherit (pkgs) lib; + craneLib = crane.lib.${system}; - devShells.default = let - pwd = builtins.getEnv "PWD"; - prefix = "${pwd}/target/prefix"; - lhapath = "${prefix}/share/LHAPDF"; - in - devenv.lib.mkShell { - inherit inputs pkgs; - modules = [ - ({config, ...}: { - packages = with pkgs; [ - maturin - (lhapdf.override { - python = - config.languages.python.package; - }) - ]; + src = craneLib.cleanCargoSource (craneLib.path ./.); + # Common arguments can be set here to avoid repeating them later + commonArgs = { + inherit src; + strictDeps = true; + }; - env = { - PREFIX = prefix; - LHAPDF_DATA_PATH = lhapath; - }; - enterShell = '' - # update path before entering the shell, when Nix packages updates - # already happened - export PATH=${prefix}/bin:$PATH - mkdir -p ${lhapath} - ''; + cargoArtifacts = craneLib.buildDepsOnly commonArgs; + individualCrateArgs = + commonArgs + // { + inherit cargoArtifacts; + inherit (craneLib.crateNameFromCargoToml {inherit src;}) version; + }; - languages.python = { - enable = true; - venv.enable = true; - }; - languages.rust = { - enable = true; - channel = "stable"; - }; - }) + fileSetForCrate = crate: + lib.fileset.toSource { + root = ./.; + fileset = lib.fileset.unions [ + ./Cargo.toml + ./Cargo.lock + crate ]; }; - }); + + pineappl = craneLib.buildPackage (individualCrateArgs + // { + pname = "pineappl"; + cargoExtraArgs = "-p pineappl"; + src = fileSetForCrate ./pineappl; + }); + cli = craneLib.buildPackage (individualCrateArgs + // { + pname = "pineappl_cli"; + cargoExtraArgs = "-p pineappl_cli"; + src = fileSetForCrate ./pineappl_cli; + buildInputs = with pkgs; [lhapdf]; + }); + # TODO: build with maturin + py = null; + in + { + packages = { + default = cli; + cli = cli; + lib = pineappl; + pineappl-py = py; + }; + + apps.default = cli; + } + // { + devShells.default = let + pwd = builtins.getEnv "PWD"; + prefix = "${pwd}/target/prefix"; + lhapath = "${prefix}/share/LHAPDF"; + in + devenv.lib.mkShell { + inherit inputs pkgs; + modules = [ + ({config, ...}: { + packages = with pkgs; [ + maturin + (lhapdf.override { + python = + config.languages.python.package; + }) + ]; + + env = { + PREFIX = prefix; + LHAPDF_DATA_PATH = lhapath; + }; + enterShell = '' + # update path before entering the shell, when Nix packages updates + # already happened + export PATH=${prefix}/bin:$PATH + mkdir -p ${lhapath} + ''; + + languages.python = { + enable = true; + venv.enable = true; + }; + languages.rust = { + enable = true; + channel = "stable"; + }; + }) + ]; + }; + }); nixConfig = { extra-trusted-public-keys = "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw="; From 4b6f20cebaee7ce98eacbeaf6ab1c2fb88284683 Mon Sep 17 00:00:00 2001 From: Alessandro Candido Date: Tue, 23 Apr 2024 18:15:48 +0200 Subject: [PATCH 13/16] build: Fix warning, provide pkg-config to CLI build --- flake.nix | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index b3e7be00..d4572bce 100644 --- a/flake.nix +++ b/flake.nix @@ -37,7 +37,13 @@ commonArgs // { inherit cargoArtifacts; - inherit (craneLib.crateNameFromCargoToml {inherit src;}) version; + inherit + ((builtins.fromTOML (builtins.readFile (src + + "/Cargo.toml"))) + .workspace + .package) + version + ; }; fileSetForCrate = crate: @@ -61,7 +67,7 @@ pname = "pineappl_cli"; cargoExtraArgs = "-p pineappl_cli"; src = fileSetForCrate ./pineappl_cli; - buildInputs = with pkgs; [lhapdf]; + buildInputs = with pkgs; [pkg-config lhapdf]; }); # TODO: build with maturin py = null; From b38d2ae19bc7b8984ed8d9587dce0e9d57f779bc Mon Sep 17 00:00:00 2001 From: Alessandro Candido Date: Tue, 23 Apr 2024 23:50:27 +0200 Subject: [PATCH 14/16] build: Finally fix CLI package --- flake.nix | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/flake.nix b/flake.nix index d4572bce..e049a27d 100644 --- a/flake.nix +++ b/flake.nix @@ -26,17 +26,16 @@ craneLib = crane.lib.${system}; src = craneLib.cleanCargoSource (craneLib.path ./.); - # Common arguments can be set here to avoid repeating them later commonArgs = { inherit src; - strictDeps = true; + strictDeps = false; + buildInputs = with pkgs; [lhapdf]; + nativeBuildInputs = with pkgs; [pkg-config]; }; - cargoArtifacts = craneLib.buildDepsOnly commonArgs; individualCrateArgs = commonArgs // { - inherit cargoArtifacts; inherit ((builtins.fromTOML (builtins.readFile (src + "/Cargo.toml"))) @@ -44,6 +43,7 @@ .package) version ; + doCheck = false; }; fileSetForCrate = crate: @@ -53,21 +53,30 @@ ./Cargo.toml ./Cargo.lock crate + # TODO: avoid passing all the folders + # (if strictly needed, at least avoid doing it explicitly) + ./pineappl + ./pineappl_applgrid + ./pineappl_capi + ./pineappl_fastnlo + ./pineappl_py + ./xtask ]; }; - pineappl = craneLib.buildPackage (individualCrateArgs - // { - pname = "pineappl"; - cargoExtraArgs = "-p pineappl"; - src = fileSetForCrate ./pineappl; - }); + pineappl = + craneLib.buildPackage + (individualCrateArgs + // { + pname = "pineappl"; + cargoExtraArgs = "-p pineappl"; + src = fileSetForCrate ./pineappl; + }); cli = craneLib.buildPackage (individualCrateArgs // { pname = "pineappl_cli"; cargoExtraArgs = "-p pineappl_cli"; src = fileSetForCrate ./pineappl_cli; - buildInputs = with pkgs; [pkg-config lhapdf]; }); # TODO: build with maturin py = null; From 91c6a36e8290e6a8ffc6a02a608368f65d3d7b28 Mon Sep 17 00:00:00 2001 From: Alessandro Candido Date: Tue, 23 Apr 2024 23:55:34 +0200 Subject: [PATCH 15/16] build: Avoid packaging the PineAPPL library It is never used as a shared object, thus there is no need --- flake.nix | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/flake.nix b/flake.nix index e049a27d..d821825b 100644 --- a/flake.nix +++ b/flake.nix @@ -58,23 +58,16 @@ ./pineappl ./pineappl_applgrid ./pineappl_capi + ./pineappl_cli ./pineappl_fastnlo ./pineappl_py ./xtask ]; }; - pineappl = - craneLib.buildPackage - (individualCrateArgs - // { - pname = "pineappl"; - cargoExtraArgs = "-p pineappl"; - src = fileSetForCrate ./pineappl; - }); cli = craneLib.buildPackage (individualCrateArgs // { - pname = "pineappl_cli"; + pname = "pineappl"; cargoExtraArgs = "-p pineappl_cli"; src = fileSetForCrate ./pineappl_cli; }); @@ -85,7 +78,6 @@ packages = { default = cli; cli = cli; - lib = pineappl; pineappl-py = py; }; From 9bd3077cfeb405e42d8557a0ec6f1d5ef6cfc454 Mon Sep 17 00:00:00 2001 From: Alessandro Candido Date: Wed, 24 Apr 2024 14:43:53 +0200 Subject: [PATCH 16/16] build: Further simplifications --- flake.nix | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/flake.nix b/flake.nix index d821825b..f5c9b1fb 100644 --- a/flake.nix +++ b/flake.nix @@ -26,26 +26,23 @@ craneLib = crane.lib.${system}; src = craneLib.cleanCargoSource (craneLib.path ./.); + # The following could be done automatically by Crane, but it will look for a + # top-level package name as well (not present in PineAPPL). Thus, doing it + # manually will save a Crane warning. + version = + (builtins.fromTOML (builtins.readFile (src + + "/Cargo.toml"))) + .workspace + .package + .version; commonArgs = { - inherit src; + inherit src version; strictDeps = false; buildInputs = with pkgs; [lhapdf]; nativeBuildInputs = with pkgs; [pkg-config]; + doCheck = false; }; - individualCrateArgs = - commonArgs - // { - inherit - ((builtins.fromTOML (builtins.readFile (src - + "/Cargo.toml"))) - .workspace - .package) - version - ; - doCheck = false; - }; - fileSetForCrate = crate: lib.fileset.toSource { root = ./.; @@ -65,12 +62,17 @@ ]; }; - cli = craneLib.buildPackage (individualCrateArgs + defaultName = "pineappl"; + cargoArtifacts = craneLib.buildDepsOnly (commonArgs // {pname = defaultName;}); + cli = craneLib.buildPackage ( + commonArgs // { - pname = "pineappl"; + pname = defaultName; cargoExtraArgs = "-p pineappl_cli"; + inherit cargoArtifacts; src = fileSetForCrate ./pineappl_cli; - }); + } + ); # TODO: build with maturin py = null; in