Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternate commands #74

Open
tomberek opened this issue Feb 25, 2021 · 1 comment
Open

Alternate commands #74

tomberek opened this issue Feb 25, 2021 · 1 comment

Comments

@tomberek
Copy link
Collaborator

tomberek commented Feb 25, 2021

The proposed interface in the RFC exposed a -c, --command to allow for program names other than the default. I got something like this working, but not sure if there's a better way.

PROGRAM=mb-util nix bundle nixpkgs#mbutil --bundler .#defaultBundler
{
  description = " description";
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs";
    nix-bundle.url = "github:matthewbauer/nix-bundle";
  };
  outputs = { self, nixpkgs, nix-bundle  }:
    {
    bundlers = {
      nix-bundle = { program, system }: let
        nixpkgs' = nixpkgs.legacyPackages.${system};
        nix-bundl = import nix-bundle { nixpkgs = nixpkgs'; };
        envProg = builtins.getEnv "PROGRAM";
        prog = if envProg == ""
              then program
              else "${builtins.dirOf program}/${envProg}";
        script = nixpkgs'.writeScript "startup" ''
          #!/bin/sh
          .${nix-bundl.nix-user-chroot}/bin/nix-user-chroot -n ./nix -- "${prog}"
        '';
          #${program} "$@"
      in nix-bundl.makebootstrap {
        targets = [ script ];
        startup = ".${builtins.unsafeDiscardStringContext script} '\"$@\"'";
      };
    };

    defaultBundler = self.bundlers.nix-bundle;
    }
    ;
}
@tomberek
Copy link
Collaborator Author

Slightly less hacky:

{
  description = " description";
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    nix-bundle.url = "github:matthewbauer/nix-bundle";
  };
  outputs = { self, nixpkgs, nix-bundle  }:
    {
    bundlers = {
      nix-bundle = { program, system }: let
        legacy = nixpkgs.legacyPackages.${system};
        nix-bundle-prog = import nix-bundle { nixpkgs = legacy; };
        script = legacy.writeScript "startup" ''
          #!/bin/sh
          PROG="$1"
          shift
          .${nix-bundle-prog.nix-user-chroot}/bin/nix-user-chroot -n ./nix -- "${builtins.dirOf program}/$PROG" "$@"
        '';
      in nix-bundle-prog.makebootstrap {
        targets = [ script ];
        startup = ".${builtins.unsafeDiscardStringContext script} '\"$@\"'";
      };
    };
    defaultBundler = self.bundlers.nix-bundle;
    };
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant