Skip to content

Commit

Permalink
basic flake.nix support with lib.packs
Browse files Browse the repository at this point in the history
impure and sandbox options should be passed as:

$ nix build .#pkgs.zlib -L --impure --option sandbox false
  • Loading branch information
dguibert committed Nov 29, 2021
1 parent 9bc3a18 commit daf9a94
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 10 deletions.
45 changes: 45 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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;

};
}
14 changes: 7 additions & 7 deletions packs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ prefsUpdate = let
spackConfig = lib.recursiveUpdate;
spackPython = scalar;
spackPath = scalar;
spackEnv = lib.recursiveUpdate;
nixpkgsSrc = scalar;
nixpkgs = scalar;
verbose = scalar;
Expand All @@ -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";
Expand All @@ -102,33 +104,31 @@ 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
then repos
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)
Expand Down
5 changes: 2 additions & 3 deletions spack/config.nix
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit daf9a94

Please sign in to comment.