From daf9a940c0847a348358ca884924370bc1614558 Mon Sep 17 00:00:00 2001 From: David Guibert Date: Mon, 29 Nov 2021 11:29:02 +0100 Subject: [PATCH] basic flake.nix support with lib.packs impure and sandbox options should be passed as: $ nix build .#pkgs.zlib -L --impure --option sandbox false --- flake.lock | 45 +++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 47 +++++++++++++++++++++++++++++++++++++++++++++++ packs/default.nix | 14 +++++++------- spack/config.nix | 5 ++--- 4 files changed, 101 insertions(+), 10 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..a23406c --- /dev/null +++ b/flake.lock @@ -0,0 +1,45 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1636225307, + "narHash": "sha256-9h+5H44KIplCAJ26JLa5lC68vKC9pjTzq1c8IlWn/tI=", + "owner": "dguibert", + "repo": "nixpkgs", + "rev": "ecd445b9d09c4740409bc204d2f98d88b9c884cd", + "type": "github" + }, + "original": { + "owner": "dguibert", + "ref": "pu-nixpack", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "spack": "spack" + } + }, + "spack": { + "flake": false, + "locked": { + "lastModified": 1636689990, + "narHash": "sha256-Gl63hr4Tgwu3FSsy2eW4hOgpaEspiEXUy7VGlN96guw=", + "owner": "flatironinstitute", + "repo": "spack", + "rev": "1e32391fb75401d47206d0100eb444e3804c185a", + "type": "github" + }, + "original": { + "owner": "flatironinstitute", + "ref": "fi-nixpack", + "repo": "spack", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..0feecaa --- /dev/null +++ b/flake.nix @@ -0,0 +1,47 @@ +{ + description = "Flake for NixPACK"; + + #inputs.spack = { url="github:spack/spack"; flake=false; }; + inputs.spack = { url="github:flatironinstitute/spack/fi-nixpack"; flake=false; }; + inputs.nixpkgs.url = "github:dguibert/nixpkgs/pu-nixpack"; + + outputs = inputs: let + nixpkgsFor = system: import inputs.nixpkgs { + inherit system; + }; + + nixosPacks = system: let + pkgs = nixpkgsFor system; + gccWithFortran = pkgs.wrapCC (pkgs.gcc.cc.override { + langFortran = true; + }); + in inputs.self.lib.packs { + inherit system; + os = "nixos21"; + global.verbose = "true"; + spackConfig.config.source_cache="/tmp/spack_cache"; + spackPython = "${pkgs.python3}/bin/python3"; + spackEnv = { + # pure environment PATH + #PATH="${pkgs.coreutils}/bin:${pkgs.gnumake}/bin:${pkgs.gnutar}/bin:${pkgs.gzip}/bin:${pkgs.gnused}/bin:${pkgs.glib}/bin"; # glib: locale + PATH="/run/current-system/sw/bin:${pkgs.gnumake}/bin:${pkgs.binutils.bintools}/bin"; + LOCALE_ARCHIVE="/run/current-system/sw/lib/locale/locale-archive"; + }; + + package = { + compiler = { name="gcc"; extern=gccWithFortran; version=gccWithFortran.version; }; + }; + }; + in { + lib.packs = { + ... + }@args: import ./packs ({ + inherit (inputs) spack nixpkgs; + } // args); + + packages.x86_64-linux = nixosPacks "x86_64-linux"; + + defaultPackage.x86_64-linux = inputs.self.packages.x86_64-linux.hello; + + }; +} diff --git a/packs/default.nix b/packs/default.nix index 9a4b187..4ca3c45 100644 --- a/packs/default.nix +++ b/packs/default.nix @@ -61,6 +61,7 @@ prefsUpdate = let spackConfig = lib.recursiveUpdate; spackPython = scalar; spackPath = scalar; + spackEnv = lib.recursiveUpdate; nixpkgsSrc = scalar; nixpkgs = scalar; verbose = scalar; @@ -81,6 +82,7 @@ packsWithPrefs = , spackConfig ? {} , spackPython ? "/usr/bin/python3" , spackPath ? "/bin:/usr/bin" + , spackEnv ? { PATH=spackPath; } , nixpkgsSrc ? null , nixpkgs ? fetchGit ({ url = "git://github.com/NixOS/nixpkgs"; @@ -102,25 +104,23 @@ lib.fix (packs: with packs; { ({ label = "withPrefs"; } // p)); - makeSpackConfig = import ../spack/config.nix packs spackPath; + makeSpackConfig = import ../spack/config.nix packs spackEnv; - inherit spack spackPython spackPath; + inherit spack spackPython spackEnv; spackConfig = makeSpackConfig (lib.recursiveUpdate defaultSpackConfig packPrefs.spackConfig); - spackNixLib = derivation { + spackNixLib = derivation ({ name = "nix-spack-py"; inherit system; builder = ../spack/install.sh; src = ../spack/nixpack.py; - PATH = spackPath; - }; + } // spackEnv); /* common attributes for running spack */ spackBuilder = attrs: builtins.removeAttrs (derivation ({ inherit (packs) system os spackConfig; builder = spackPython; PYTHONPATH = "${spackNixLib}:${spack}/lib/spack:${spack}/lib/spack/external"; - PATH = spackPath; LC_ALL = "en_US.UTF-8"; # work around spack bugs processing log files repos = if attrs ? withRepos then if attrs.withRepos @@ -128,7 +128,7 @@ lib.fix (packs: with packs; { else null else map (r: r + "/repo.yaml") repos; spackCache = if attrs.withRepos or false then spackCacheRepos else spackCache; - } // attrs)) ["PYTHONPATH" "PATH" "LC_ALL" "spackConfig" "spackCache" "passAsFile"]; + } // spackEnv // attrs)) ["PYTHONPATH" "PATH" "LC_ALL" "spackConfig" "spackCache" "passAsFile"]; /* pre-generated spack repo index cache (both with and without overlay repos) */ makeSpackCache = withRepos: lib.when (builtins.isAttrs spackSrc) diff --git a/spack/config.nix b/spack/config.nix index be0bc9c..8c3bfab 100644 --- a/spack/config.nix +++ b/spack/config.nix @@ -1,7 +1,6 @@ -packs: spackPath: config: derivation ({ +packs: spackEnv: config: derivation ({ inherit (packs.prefs) system; name = "spackConfig"; builder = ./config.sh; sections = builtins.attrNames config; - PATH = spackPath; -} // builtins.mapAttrs (n: v: builtins.toJSON { "${n}" = v; }) config) +} // spackEnv // builtins.mapAttrs (n: v: builtins.toJSON { "${n}" = v; }) config)