Skip to content

Commit 4f6330b

Browse files
authored
Merge pull request #113 from Artturin/nixbundleapi
flake: Use new nix bundle api
2 parents cdec674 + 94a1a53 commit 4f6330b

File tree

3 files changed

+91
-25
lines changed

3 files changed

+91
-25
lines changed

default.nix

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ rec {
1313
# in the context automatically.
1414
else "${target}";
1515

16-
arx = { archive, startup}:
16+
arx = { drvToBundle, archive, startup}:
1717
stdenv.mkDerivation {
18-
name = "arx";
18+
name = if drvToBundle != null then "${drvToBundle.pname}-arx" else "arx";
19+
passthru = {
20+
inherit drvToBundle;
21+
};
1922
buildCommand = ''
2023
# tmpdir has a additional `/` in the beginning to work around `QualifiedPath` checking for `|/|./|../|`
2124
${haskellPackages.arx}/bin/arx tmpx \
@@ -78,9 +81,9 @@ rec {
7881
meta.platforms = lib.platforms.linux;
7982
};
8083

81-
makebootstrap = { targets, startup }:
84+
makebootstrap = { targets, startup, drvToBundle ? null }:
8285
arx {
83-
inherit startup;
86+
inherit drvToBundle startup;
8487
archive = maketar {
8588
inherit targets;
8689
};

flake.lock

Lines changed: 35 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,55 @@
11
{
22
description = "The purely functional package manager";
33

4-
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
utils.url = "github:numtide/flake-utils";
7+
};
58

6-
outputs = { self, nixpkgs }: let
7-
systems = [ "x86_64-linux" "i686-linux" "aarch64-linux" ];
8-
forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f system);
9-
in {
10-
bundlers = {
11-
nix-bundle = { program, system }: let
12-
nixpkgs' = nixpkgs.legacyPackages.${system};
13-
nix-bundle = import self { nixpkgs = nixpkgs'; };
14-
script = nixpkgs'.writeScript "startup" ''
15-
#!/bin/sh
16-
.${nix-bundle.nix-user-chroot}/bin/nix-user-chroot -n ./nix -- ${program} "$@"
17-
'';
18-
in nix-bundle.makebootstrap {
19-
targets = [ script ];
20-
startup = ".${builtins.unsafeDiscardStringContext script} '\"$@\"'";
21-
};
22-
};
9+
outputs =
10+
inputs:
11+
let
12+
inherit (inputs.nixpkgs) lib;
2313

24-
defaultBundler = self.bundlers.nix-bundle;
25-
};
14+
getExe =
15+
x:
16+
lib.getExe' x (
17+
x.meta.mainProgram or (lib.warn
18+
"nix-bundle: Package ${
19+
lib.strings.escapeNixIdentifier x.meta.name or x.pname or x.name
20+
} does not have the meta.mainProgram attribute. Assuming you want '${lib.getName x}'."
21+
lib.getName
22+
x
23+
)
24+
);
25+
in
26+
inputs.utils.lib.eachDefaultSystem (
27+
system:
28+
let
29+
nix-bundle-fun =
30+
{
31+
drv,
32+
programPath ? getExe drv,
33+
}:
34+
let
35+
nixpkgs = inputs.nixpkgs.legacyPackages.${system};
36+
nix-bundle = import inputs.self { inherit nixpkgs; };
37+
script = nixpkgs.writeScript "startup" ''
38+
#!/bin/sh
39+
.${nix-bundle.nix-user-chroot}/bin/nix-user-chroot -n ./nix -- ${programPath} "$@"
40+
'';
41+
in
42+
nix-bundle.makebootstrap {
43+
drvToBundle = drv;
44+
targets = [ script ];
45+
startup = ".${builtins.unsafeDiscardStringContext script} '\"$@\"'";
46+
};
47+
in
48+
{
49+
bundlers = {
50+
default = inputs.self.bundlers.${system}.nix-bundle;
51+
nix-bundle = drv: nix-bundle-fun { inherit drv; };
52+
};
53+
}
54+
);
2655
}

0 commit comments

Comments
 (0)