Comments (5)
Some sort of find / scp / rsync combo is not good , because I also have some tests.nix
that is is not referenced through configuration.nix
. And then digital-ocean-image.nix
is also something that I don't need to copy (since it is already there).
from terraform-nixos.
The best option is to delete /etc/nixos on the target machine. You can do that by using the "remote-exec" provisioner, or by adding it in a systemd unit in the machine configuration.nix.
It would be nice if it was possible to copy all the nix files onto the server, so that it can be rebuilt manually, but that's quite difficult to achieve. To reproduce the config, deploy_nixos would have to capture not only the configuration.nix, but also be able to follow all the imported modules. And which version of nixpkgs is being used.
from terraform-nixos.
I came up with this "contraption" 🙂
{ pkgs ? import <nixpkgs> {}, ... }:
let
lib = pkgs.lib;
resolveOne = file: let p = pkgs.callPackage file {}; in lib.filter (x: !lib.hasPrefix "/nix" (builtins.toPath x)) (if lib.hasAttr "imports" p then p.imports else []);
oneStep = result: lib.unique (lib.foldl' (x: y: x ++ resolveOne y) result result);
resolve = input: let resolveRec = x: let y = oneStep x; in if lib.length x == lib.length y then y else resolveRec y; in resolveRec [ input ];
getPrefix = main: let file = builtins.toPath main; name = builtins.baseNameOf file; root = lib.replaceStrings [ "/${name}" ] [ ""] file; in root;
getRelativePaths = main: let prefix = getPrefix main; in map (x: lib.replaceStrings [ prefix ] [ "." ] (builtins.toPath x)) (resolve main);
getRelativePathsStr = main: builtins.concatStringsSep "\n" (getRelativePaths main);
in
pkgs.mkShell {
shellHook = ''
echo "ssh machine rm -rf /etc/nixos"
echo "${getRelativePathsStr ./configuration.nix}" | xargs -n 1 -I {} echo "ssh machine mkdir -p /etc/nixos/$(pathname {} 2>/dev/null) ; scp {} machine:/etc/nixos/{}"
'';
}
Obviously this is just an approximation, since nixpkgs might be different on remote machine.
from terraform-nixos.
🙈
Another thing you can do is set nix.nixPath = [ "nixpkgs=${pkgs}" ];
so nixpkgs also get pushed and set to NIX_PATH.
from terraform-nixos.
There is also https://search.nixos.org/options?channel=20.09&show=system.copySystemConfiguration&from=0&size=30&sort=relevance&query=copy , but that only works if the config is self-contained into a single file.
from terraform-nixos.
Related Issues (20)
- NixOS upgrades may break due to lack of stateVersion HOT 5
- Keep last N generations around HOT 1
- terraform-nixos doesn't work on Terraform Cloud HOT 20
- It is difficult to propagate key changes to other parts of a system
- nixos-instantiate.sh produces invalid output HOT 2
- error: unknown flag '--builders ''' HOT 1
- Pass arguments to nixos_config derivation HOT 1
- Error when using config and config_pwd option
- Google Cloud services fail to start
- deploy_nixos: flake deployment doesn't work in a sub-folder HOT 1
- Speed up the process of copying drv files to the remote host HOT 1
- Transfer request to nix-community HOT 15
- Random file provisioner error and SSH authentication failure with AWS EC2 HOT 3
- deploy_nixos leaks files from the working directory into the world-readable nix store
- deploy_nixos: hash changes when files change in the working directory, even .gitignored files with flakes
- Is this project still maintained?
- Google storage bucket md5hash changes on every run of Terraform apply in GitHub actions
- `ssh_key_file` bootstrap problem HOT 1
- Consider Terranix Integration HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from terraform-nixos.