aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Audron <audron@cocaine.farm>2023-08-11 16:51:35 +0200
committerMax Audron <audron@cocaine.farm>2023-08-11 16:51:35 +0200
commit75b417455361d776d8c92a35ba69854c0cc0bcee (patch)
treecacf2223821749e372c2968fc659248b26e43c59
parentadd custom nixinate impl (diff)
move nixinate to own flake
-rw-r--r--flake.lock74
-rw-r--r--flake.nix74
-rw-r--r--nixinate/default.nix18
-rw-r--r--nixinate/generate-apps.nix32
-rw-r--r--nixinate/make-deploy-script.nix45
5 files changed, 103 insertions, 140 deletions
diff --git a/flake.lock b/flake.lock
index 957f203..0c574ac 100644
--- a/flake.lock
+++ b/flake.lock
@@ -18,6 +18,43 @@
"type": "github"
}
},
+ "flake-parts_2": {
+ "inputs": {
+ "nixpkgs-lib": "nixpkgs-lib_2"
+ },
+ "locked": {
+ "lastModified": 1690933134,
+ "narHash": "sha256-ab989mN63fQZBFrkk4Q8bYxQCktuHmBIBqUG1jl6/FQ=",
+ "owner": "hercules-ci",
+ "repo": "flake-parts",
+ "rev": "59cf3f1447cfc75087e7273b04b31e689a8599fb",
+ "type": "github"
+ },
+ "original": {
+ "owner": "hercules-ci",
+ "repo": "flake-parts",
+ "type": "github"
+ }
+ },
+ "nixinate": {
+ "inputs": {
+ "flake-parts": "flake-parts_2",
+ "nixpkgs": "nixpkgs"
+ },
+ "locked": {
+ "lastModified": 1691577770,
+ "narHash": "sha256-fVY5VSbFJN9pXDTpBeOx6zeoeSnUGIMniY9jrsWCBaA=",
+ "owner": "maxaudron",
+ "repo": "nixinate",
+ "rev": "9a0fdbbbcd41c47ef9403794aafc35215dc1a224",
+ "type": "github"
+ },
+ "original": {
+ "owner": "maxaudron",
+ "repo": "nixinate",
+ "type": "github"
+ }
+ },
"nixpkgs": {
"locked": {
"lastModified": 1691421349,
@@ -52,10 +89,45 @@
"type": "github"
}
},
+ "nixpkgs-lib_2": {
+ "locked": {
+ "dir": "lib",
+ "lastModified": 1690881714,
+ "narHash": "sha256-h/nXluEqdiQHs1oSgkOOWF+j8gcJMWhwnZ9PFabN6q0=",
+ "owner": "NixOS",
+ "repo": "nixpkgs",
+ "rev": "9e1960bc196baf6881340d53dccb203a951745a2",
+ "type": "github"
+ },
+ "original": {
+ "dir": "lib",
+ "owner": "NixOS",
+ "ref": "nixos-unstable",
+ "repo": "nixpkgs",
+ "type": "github"
+ }
+ },
+ "nixpkgs_2": {
+ "locked": {
+ "lastModified": 1691421349,
+ "narHash": "sha256-RRJyX0CUrs4uW4gMhd/X4rcDG8PTgaaCQM5rXEJOx6g=",
+ "owner": "nixos",
+ "repo": "nixpkgs",
+ "rev": "011567f35433879aae5024fc6ec53f2a0568a6c4",
+ "type": "github"
+ },
+ "original": {
+ "owner": "nixos",
+ "ref": "nixos-23.05",
+ "repo": "nixpkgs",
+ "type": "github"
+ }
+ },
"root": {
"inputs": {
"flake-parts": "flake-parts",
- "nixpkgs": "nixpkgs"
+ "nixinate": "nixinate",
+ "nixpkgs": "nixpkgs_2"
}
}
},
diff --git a/flake.nix b/flake.nix
index 4746c2e..3418c82 100644
--- a/flake.nix
+++ b/flake.nix
@@ -2,53 +2,39 @@
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05";
flake-parts.url = "github:hercules-ci/flake-parts";
+ nixinate.url = "github:maxaudron/nixinate";
};
- outputs = inputs@{ self, nixpkgs, flake-parts, ... }:
- flake-parts.lib.mkFlake { inherit inputs; } ({ withSystem, flake-parts-lib, ... }:
- let
- inherit (flake-parts-lib) importApply;
- flakeModules.nixinate = importApply ./nixinate { inherit withSystem; };
- in
- {
- imports = [
- flakeModules.nixinate
- ];
- flake =
- let
- specialArgs = inputs // { inherit inputs; };
- system = "x86_64-linux";
- in
- {
- inherit flakeModules;
- nixosConfigurations = {
- nixos-test = nixpkgs.lib.nixosSystem {
- system = system;
- specialArgs = specialArgs // { inherit system; };
- modules = [
- (import ./machines/nixos-test)
+ outputs = inputs@{ self, nixpkgs, flake-parts, nixinate, ... }:
+ flake-parts.lib.mkFlake { inherit inputs; } {
+ imports = [ nixinate.flakeModule ];
+ flake =
+ let
+ system = "x86_64-linux";
+ specialArgs = inputs // { inherit system; };
+ in
+ {
+ nixosConfigurations = {
+ nixos-test = nixpkgs.lib.nixosSystem {
+ inherit specialArgs system;
+ modules = [
+ (import ./machines/nixos-test)
- (import ./modules)
- (import ./modules/users)
- {
- _module.args.nixinate = {
- host = "10.49.212.3";
- sshUser = "audron";
- buildOn = "remote";
- substituteOnTarget = true;
- hermetic = false;
- };
- }
- ];
- };
+ (import ./modules)
+ (import ./modules/users)
+ {
+ _module.args.nixinate = {
+ host = "10.49.212.3";
+ sshUser = "audron";
+ buildOn = "remote";
+ substituteOnTarget = true;
+ hermetic = false;
+ };
+ }
+ ];
};
};
- systems = [
- "x86_64-linux"
- "x86_64-darwin"
- "aarch64-linux"
- "aarch64-darwin"
- ];
- perSystem = { config, ... }: { };
- });
+ };
+ systems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
+ };
}
diff --git a/nixinate/default.nix b/nixinate/default.nix
deleted file mode 100644
index 26cd4d4..0000000
--- a/nixinate/default.nix
+++ /dev/null
@@ -1,18 +0,0 @@
-# The importApply argument. Use this to reference things defined locally,
-# as opposed to the flake where this is imported.
-localFlake:
-
-# Regular module arguments; self, inputs, etc all reference the final user flake,
-# where this module was imported.
-{ lib, config, self, inputs, ... }:
-let
- lib = inputs.nixpkgs.lib;
- generateApps = import ./generate-apps.nix inputs.nixpkgs;
-in
-{
- flake = {
- };
- perSystem = { system, pkgs, ... }: {
- apps = generateApps pkgs self;
- };
-}
diff --git a/nixinate/generate-apps.nix b/nixinate/generate-apps.nix
deleted file mode 100644
index 6871d04..0000000
--- a/nixinate/generate-apps.nix
+++ /dev/null
@@ -1,32 +0,0 @@
-nixpkgs: pkgs: flake:
-
-let
- machines = builtins.attrNames flake.nixosConfigurations;
- validMachines = nixpkgs.lib.remove ""
- (nixpkgs.lib.forEach machines
- (x: nixpkgs.lib.optionalString
- (flake.nixosConfigurations."${x}"._module.args ? nixinate) "${x}"));
- mkDeployScript = import ./make-deploy-script.nix { inherit nixpkgs pkgs flake; };
-in
-nixpkgs.lib.genAttrs
- validMachines
- (x:
- {
- type = "app";
- program = toString (mkDeployScript {
- machine = x;
- dryRun = false;
- });
- }
- )
- // nixpkgs.lib.genAttrs
- (map (a: a + "-dry-run") validMachines)
- (x:
- {
- type = "app";
- program = toString (mkDeployScript {
- machine = nixpkgs.lib.removeSuffix "-dry-run" x;
- dryRun = true;
- });
- }
- )
diff --git a/nixinate/make-deploy-script.nix b/nixinate/make-deploy-script.nix
deleted file mode 100644
index ab128b3..0000000
--- a/nixinate/make-deploy-script.nix
+++ /dev/null
@@ -1,45 +0,0 @@
-{ nixpkgs, pkgs, flake, ... }:
-{ machine, dryRun }:
-let
- inherit (builtins) abort;
- inherit (pkgs.lib) getExe optionalString concatStringsSep;
-
- nix = "${getExe pkgs.nix}";
- nixos-rebuild = "${getExe pkgs.nixos-rebuild}";
- openssh = "${getExe pkgs.openssh}";
- flock = "${getExe pkgs.flock}";
-
- n = flake.nixosConfigurations.${machine}._module.args.nixinate;
- hermetic = n.hermetic or true;
- user = n.sshUser or "root";
- host = n.host;
- where = n.buildOn or "remote";
- remote = if where == "remote" then true else if where == "local" then false else abort "_module.args.nixinate.buildOn is not set to a valid value of 'local' or 'remote'";
- substituteOnTarget = n.substituteOnTarget or false;
- switch = if dryRun then "dry-activate" else "switch";
- nixOptions = concatStringsSep " " (n.nixOptions or [ ]);
-
- script =
- ''
- set -e
- echo "🚀 Deploying nixosConfigurations.${machine} from ${flake}"
- echo "👤 SSH User: ${user}"
- echo "🌐 SSH Host: ${host}"
- '' + (if remote then ''
- echo "🚀 Sending flake to ${machine} via nix copy:"
- ( set -x; ${nix} ${nixOptions} copy ${flake} --to ssh://${user}@${host} )
- '' + (if hermetic then ''
- echo "🤞 Activating configuration hermetically on ${machine} via ssh:"
- ( set -x; ${nix} ${nixOptions} copy --derivation ${nixos-rebuild} ${flock} --to ssh://${user}@${host} )
- ( set -x; ${openssh} -t ${user}@${host} "sudo nix-store --realise ${nixos-rebuild} ${flock} && sudo ${flock} -w 60 /dev/shm/nixinate-${machine} ${nixos-rebuild} ${nixOptions} ${switch} --flake ${flake}#${machine}" )
- '' else ''
- echo "🤞 Activating configuration non-hermetically on ${machine} via ssh:"
- ( set -x; ${openssh} -t ${user}@${host} "sudo flock -w 60 /dev/shm/nixinate-${machine} nixos-rebuild ${switch} --flake ${flake}#${machine}" )
- '')
- else ''
- echo "🔨 Building system closure locally, copying it to remote store and activating it:"
- ( set -x; NIX_SSHOPTS="-t" ${flock} -w 60 /dev/shm/nixinate-${machine} ${nixos-rebuild} ${nixOptions} ${switch} --flake ${flake}#${machine} --target-host ${user}@${host} --use-remote-sudo ${optionalString substituteOnTarget "-s"} )
-
- '');
-in
-pkgs.writeScript "deploy-${machine}.sh" script