Skip to content

Commit daf9a94

Browse files
committed
basic flake.nix support with lib.packs
impure and sandbox options should be passed as: $ nix build .#pkgs.zlib -L --impure --option sandbox false
1 parent 9bc3a18 commit daf9a94

File tree

4 files changed

+101
-10
lines changed

4 files changed

+101
-10
lines changed

flake.lock

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
description = "Flake for NixPACK";
3+
4+
#inputs.spack = { url="github:spack/spack"; flake=false; };
5+
inputs.spack = { url="github:flatironinstitute/spack/fi-nixpack"; flake=false; };
6+
inputs.nixpkgs.url = "github:dguibert/nixpkgs/pu-nixpack";
7+
8+
outputs = inputs: let
9+
nixpkgsFor = system: import inputs.nixpkgs {
10+
inherit system;
11+
};
12+
13+
nixosPacks = system: let
14+
pkgs = nixpkgsFor system;
15+
gccWithFortran = pkgs.wrapCC (pkgs.gcc.cc.override {
16+
langFortran = true;
17+
});
18+
in inputs.self.lib.packs {
19+
inherit system;
20+
os = "nixos21";
21+
global.verbose = "true";
22+
spackConfig.config.source_cache="/tmp/spack_cache";
23+
spackPython = "${pkgs.python3}/bin/python3";
24+
spackEnv = {
25+
# pure environment PATH
26+
#PATH="${pkgs.coreutils}/bin:${pkgs.gnumake}/bin:${pkgs.gnutar}/bin:${pkgs.gzip}/bin:${pkgs.gnused}/bin:${pkgs.glib}/bin"; # glib: locale
27+
PATH="/run/current-system/sw/bin:${pkgs.gnumake}/bin:${pkgs.binutils.bintools}/bin";
28+
LOCALE_ARCHIVE="/run/current-system/sw/lib/locale/locale-archive";
29+
};
30+
31+
package = {
32+
compiler = { name="gcc"; extern=gccWithFortran; version=gccWithFortran.version; };
33+
};
34+
};
35+
in {
36+
lib.packs = {
37+
...
38+
}@args: import ./packs ({
39+
inherit (inputs) spack nixpkgs;
40+
} // args);
41+
42+
packages.x86_64-linux = nixosPacks "x86_64-linux";
43+
44+
defaultPackage.x86_64-linux = inputs.self.packages.x86_64-linux.hello;
45+
46+
};
47+
}

packs/default.nix

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ prefsUpdate = let
6161
spackConfig = lib.recursiveUpdate;
6262
spackPython = scalar;
6363
spackPath = scalar;
64+
spackEnv = lib.recursiveUpdate;
6465
nixpkgsSrc = scalar;
6566
nixpkgs = scalar;
6667
verbose = scalar;
@@ -81,6 +82,7 @@ packsWithPrefs =
8182
, spackConfig ? {}
8283
, spackPython ? "/usr/bin/python3"
8384
, spackPath ? "/bin:/usr/bin"
85+
, spackEnv ? { PATH=spackPath; }
8486
, nixpkgsSrc ? null
8587
, nixpkgs ? fetchGit ({
8688
url = "git://github.com/NixOS/nixpkgs";
@@ -102,33 +104,31 @@ lib.fix (packs: with packs; {
102104
({ label = "withPrefs"; } // p));
103105

104106

105-
makeSpackConfig = import ../spack/config.nix packs spackPath;
107+
makeSpackConfig = import ../spack/config.nix packs spackEnv;
106108

107-
inherit spack spackPython spackPath;
109+
inherit spack spackPython spackEnv;
108110
spackConfig = makeSpackConfig (lib.recursiveUpdate defaultSpackConfig packPrefs.spackConfig);
109111

110-
spackNixLib = derivation {
112+
spackNixLib = derivation ({
111113
name = "nix-spack-py";
112114
inherit system;
113115
builder = ../spack/install.sh;
114116
src = ../spack/nixpack.py;
115-
PATH = spackPath;
116-
};
117+
} // spackEnv);
117118

118119
/* common attributes for running spack */
119120
spackBuilder = attrs: builtins.removeAttrs (derivation ({
120121
inherit (packs) system os spackConfig;
121122
builder = spackPython;
122123
PYTHONPATH = "${spackNixLib}:${spack}/lib/spack:${spack}/lib/spack/external";
123-
PATH = spackPath;
124124
LC_ALL = "en_US.UTF-8"; # work around spack bugs processing log files
125125
repos = if attrs ? withRepos
126126
then if attrs.withRepos
127127
then repos
128128
else null
129129
else map (r: r + "/repo.yaml") repos;
130130
spackCache = if attrs.withRepos or false then spackCacheRepos else spackCache;
131-
} // attrs)) ["PYTHONPATH" "PATH" "LC_ALL" "spackConfig" "spackCache" "passAsFile"];
131+
} // spackEnv // attrs)) ["PYTHONPATH" "PATH" "LC_ALL" "spackConfig" "spackCache" "passAsFile"];
132132

133133
/* pre-generated spack repo index cache (both with and without overlay repos) */
134134
makeSpackCache = withRepos: lib.when (builtins.isAttrs spackSrc)

spack/config.nix

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
packs: spackPath: config: derivation ({
1+
packs: spackEnv: config: derivation ({
22
inherit (packs.prefs) system;
33
name = "spackConfig";
44
builder = ./config.sh;
55
sections = builtins.attrNames config;
6-
PATH = spackPath;
7-
} // builtins.mapAttrs (n: v: builtins.toJSON { "${n}" = v; }) config)
6+
} // spackEnv // builtins.mapAttrs (n: v: builtins.toJSON { "${n}" = v; }) config)

0 commit comments

Comments
 (0)