OK, I’ve switched over to defining a container to make things a little easier for now. This is the default container flake template from nix flake init -t templates#simpleContainer
:
# cat <<'EOF'> flake.nix
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.05";
trivial-flake = {
url = "path:/home/karl/myhello";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, trivial-flake }: {
nixosConfigurations.container = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules =
[ ({ pkgs, ... }: {
boot.isContainer = true;
system.configurationRevision = nixpkgs.lib.mkIf (self ? rev) self.rev;
environment.systemPackages = with pkgs; [
];
})
];
};
};
}
EOF
I can create this fine with nixos-container create x --flake .
The _modules.args
approach doesn’t seem to work:
nixosConfigurations.container = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
_modules.args = { inherit trivial-flake; }; # New line here
modules =
[ ({ pkgs, ... }: {
# nixos-container create x --flake .
host IP is 10.233.1.1, container IP is 10.233.1.2
error: anonymous function at /nix/store/afvflyac1s5f1y9sr7pvyxz644jl04k8-source/nixos/lib/eval-config.nix:11:1 called with unexpected argument '_modules'
at /nix/store/afvflyac1s5f1y9sr7pvyxz644jl04k8-source/flake.nix:30:11:
29| nixosSystem = { modules, ... } @ args:
30| import ./nixos/lib/eval-config.nix (args // {
| ^
31| modules =
/run/current-system/sw/bin/nixos-container: failed to build container from flake '.'
The overlays approach also breaks:
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.05";
trivial-flake = {
url = "path:/home/karl/myhello";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, trivial-flake }:
let
overlays = [ (final: prev: { myhello = trivial-flake.defaultPackage; }) ];
in {
nixosConfigurations.container = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules =
[ ({ pkgs, ... }: {
boot.isContainer = true;
system.configurationRevision = nixpkgs.lib.mkIf (self ? rev) self.rev;
nixpkgs.overlays = overlays;
environment.systemPackages = with pkgs; [
myhello
];
})
];
};
};
}
# nixos-container create x --flake .
host IP is 10.233.1.1, container IP is 10.233.1.2
error: A definition for option `environment.systemPackages.[definition 1-entry 1]' is not of type `package'. Definition values:
- In `<unknown-file>':
{
aarch64-darwin = <derivation /nix/store/mpj01car6jwhfmclfj1sb276ky9cp8z0-myhello.drv>;
aarch64-linux = <derivation /nix/store/4biwbagrxq604r5dl8qfjyk4hafxyfrb-myhello.drv>;
i686-linux = <derivation /nix/store/q3sl4fg37mhrfsl8a97sp158vd232dwa-myhello.drv>;
x86_64-darwin = <derivation /nix/store/14bbynbsbjlzvg0jxxm9kavdiphd3l31-myhello.drv>;
...
(use '--show-trace' to show detailed location information)
/run/current-system/sw/bin/nixos-container: failed to build container from flake '.'
Also:
# nixos-container create x --flake . --show-trace
Unknown option: show-trace
However, if I do this, it works:
overlays = [ (final: prev: { myhello = trivial-flake.defaultPackage.x86_64-linux; }) ];
Full working container flake.nix:
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.05";
trivial-flake.url = "path:/home/karl/myhello";
};
outputs = { self, nixpkgs, trivial-flake }:
let
overlays = [ (final: prev: { myhello = trivial-flake.defaultPackage.x86_64-linux; }) ];
in {
nixosConfigurations.container = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules =
[ ({ pkgs, ... }: {
boot.isContainer = true;
system.configurationRevision = nixpkgs.lib.mkIf (self ? rev) self.rev;
nixpkgs.overlays = overlays;
environment.systemPackages = with pkgs; [
myhello
];
})
];
};
};
}
Is this the “best practice” way to do it?
Is there a way to avoid having to specify the arch?
Would this also be how it’s done with a flake that’s hosted on github somewhere?