Tmplt
February 14, 2020, 4:54pm
1
All my systems are configured and deployed via nixops(1); my laptop configuration is in ~/nixops/systems/laptop.nix
and contains
{
laptop = { config, lib, pkgs, ... }:
{
deployment.targetHost = "localhost";
# ...
}
}
but for hands-on systems (deployment.targetHost = "localhost"
) I would prefer to use nixos-rebuild
(for the build
subcommand, mostly). Is it possible to use a configuration file other than /etc/nixos/configuration.nix
? Alternatively, how can I import the expression correctly? Using
# /etc/nixos/configuration.nix
{ config, lib, pkgs, ... }:
(import /home/tmplt/nixops/systems/laptop.nix).laptop { inherit config lib pkgs; }
yields an error because the deployment
option does not exist for local systems.
1 Like
ryantm
February 15, 2020, 5:54am
2
Can you use the --build-only
flag with nixops deploy
instead?
How about using removeAttrs
to remove the “deployment”?
ckampka
February 15, 2020, 11:30am
4
This should do it.
{ lib, ... } @args:
let
deployment-path = /home/tmplt/nixops/systems/laptop.nix;
server-name = "laptop";
in lib.filterAttrs (n: v: n != "deployment") ((import deployment-path).${server-name} args)
Tmplt
February 17, 2020, 9:42am
5
Close, couldn’t get @args
to work. The below works, though.
{ lib, pkgs, config, ... } @args:
let
deployment-path = /home/tmplt/nixops/systems/laptop.nix;
server-name = "laptop";
in lib.filterAttrs (n: v: n != "deployment") ((import deployment-path).${server-name} { inherit args pkgs config lib; } )
ckampka
February 18, 2020, 11:38am
6
Close, couldn’t get @args
to work.
I can’t really see why it wouldn’t, but at least at the moment, you are not using it as intended.
The purpose of the @<name>
notation is basically to provide a shortcut for 'provide everything passed as an argument to the function as a set named <name>
', so
{ config, lib, pkgs } @args: foo args
is equivalent to
{ config, lib, pkgs } :
let
args = { config = config; lib = lib; pkgs = pkgs};
in foo args
with the main difference being that @<name>
also contains any args you abbreviated with ...
inherit
is a shortcut providing { a = a }
, so
foo { inherit config lib pkgs; }
is equivalent to
foo {
config = config;
lib = lib;
pkgs = pkgs;
}
So in summary
{ lib, pkgs, config, ... } @args: foo { inherit args pkgs config lib; }
boils down to
{ lib, pkgs, config, ... } @args:
foo {
args = { lib, pkgs, config, ... };
pkgs = pkgs;
config = config;
lib = lib;
}
which is probably not what you intended.