Discussion:
Import remote packages in NixOps/NixOS
(too old to reply)
Eric Sagnes
2016-03-08 05:42:41 UTC
Permalink
It is possible to import foreign modules in NixOps by doing:

```
{
network.description = "Web server";

webserver = { config, pkgs, ... }:
let
myModuleSrc = (import <nixpkgs> {}).fetchFromGitHub {
owner = "me";
repo = "myModule";
rev = "v1.0";
sha256 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
};
in
{
imports = [ "${myModuleSrc}/module.nix" ];
services.myModule.enable = true;
};
}
```

Presupposing that the remote package provides a nix build expression,
is it possible to directly import it in a similar way?
Pseudo code that is not working:

```
{
network.description = "Web server";

webserver = { config, pkgs, ... }:
let
myPackageSrc = (import <nixpkgs> {}).fetchFromGitHub {
owner = "me";
repo = "myPackage";
rev = "v1.0";
sha256 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
};
in
{
environment.systemPackages = [
(import "${myPackageSrc}/release.nix")
];

};
}
```

(The above complains about coercing a function to a string.)

Cheers,
--
Eric Sagnes
サニエ エリック
Rok Garbas
2016-03-08 16:24:02 UTC
Permalink
Hi,
Post by Eric Sagnes
```
{
network.description = "Web server";
let
myModuleSrc = (import <nixpkgs> {}).fetchFromGitHub {
owner = "me";
repo = "myModule";
rev = "v1.0";
sha256 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
};
in
{
imports = [ "${myModuleSrc}/module.nix" ];
services.myModule.enable = true;
};
}
```
Presupposing that the remote package provides a nix build expression,
is it possible to directly import it in a similar way?
```
{
network.description = "Web server";
let
myPackageSrc = (import <nixpkgs> {}).fetchFromGitHub {
owner = "me";
repo = "myPackage";
rev = "v1.0";
sha256 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
};
in
{
environment.systemPackages = [
(import "${myPackageSrc}/release.nix")
];
};
}
```
(The above complains about coercing a function to a string.)
you can also just use builtins.fetchFromTarball.

for above you probably will want to do

(import "${myPackagesSrc}/release.nix" { ... })
--
Rok Garbas - https://.garbas.si
Eric Sagnes
2016-03-08 23:15:49 UTC
Permalink
Thank you, it works perfectly with the `{}` at the end of the import!
Post by Rok Garbas
Hi,
Post by Eric Sagnes
```
{
network.description = "Web server";
let
myModuleSrc = (import <nixpkgs> {}).fetchFromGitHub {
owner = "me";
repo = "myModule";
rev = "v1.0";
sha256 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
};
in
{
imports = [ "${myModuleSrc}/module.nix" ];
services.myModule.enable = true;
};
}
```
Presupposing that the remote package provides a nix build expression,
is it possible to directly import it in a similar way?
```
{
network.description = "Web server";
let
myPackageSrc = (import <nixpkgs> {}).fetchFromGitHub {
owner = "me";
repo = "myPackage";
rev = "v1.0";
sha256 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
};
in
{
environment.systemPackages = [
(import "${myPackageSrc}/release.nix")
];
};
}
```
(The above complains about coercing a function to a string.)
you can also just use builtins.fetchFromTarball.
for above you probably will want to do
(import "${myPackagesSrc}/release.nix" { ... })
--
Rok Garbas - https://.garbas.si
--
Eric Sagnes
サニエ エリック
Joachim Schiele
2017-06-18 14:44:24 UTC
Permalink
see also:
https://github.com/NixOS/nixops/issues/434#issuecomment-309281751
Post by Eric Sagnes
Thank you, it works perfectly with the `{}` at the end of the import!
Post by Rok Garbas
Hi,
Post by Eric Sagnes
```
{
network.description = "Web server";
let
myModuleSrc = (import <nixpkgs> {}).fetchFromGitHub {
owner = "me";
repo = "myModule";
rev = "v1.0";
sha256 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
};
in
{
imports = [ "${myModuleSrc}/module.nix" ];
services.myModule.enable = true;
};
}
```
Presupposing that the remote package provides a nix build expression,
is it possible to directly import it in a similar way?
```
{
network.description = "Web server";
let
myPackageSrc = (import <nixpkgs> {}).fetchFromGitHub {
owner = "me";
repo = "myPackage";
rev = "v1.0";
sha256 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
};
in
{
environment.systemPackages = [
(import "${myPackageSrc}/release.nix")
];
};
}
```
(The above complains about coercing a function to a string.)
you can also just use builtins.fetchFromTarball.
for above you probably will want to do
(import "${myPackagesSrc}/release.nix" { ... })
--
Rok Garbas - https://.garbas.si
Loading...