From 210e46e25004debaf31e08271f81d136d5fcc3f7 Mon Sep 17 00:00:00 2001
From: Jens Nolte <git@queezle.net>
Date: Wed, 14 Apr 2021 17:40:30 +0200
Subject: [PATCH] Move some flake inputs from machines repository here

---
 bin/deploy          |  10 ++++
 configuration.nix   |   5 ++
 flake.lock          | 121 ++++++++++++++++++++++++++++++++++++++++++++
 flake.nix           |  35 ++++++++-----
 machine-manager.nix |  22 ++++----
 5 files changed, 172 insertions(+), 21 deletions(-)
 create mode 100644 flake.lock

diff --git a/bin/deploy b/bin/deploy
index e6f9db2..3763f7a 100755
--- a/bin/deploy
+++ b/bin/deploy
@@ -94,6 +94,10 @@ else
 fi
 
 
+# Update nar-hash of dotfiles repository
+nix flake lock --update-input dotfiles "path:$MACHINES_PATH"
+
+
 if [[ "$operation" = "iso" ]]
 then
   print_info "Building iso image"
@@ -109,6 +113,12 @@ readonly system_installable="path:$MACHINES_PATH#nixosConfigurations.$hostname.c
 readonly nixos_config_path=$(nix path-info $common_nix_flags --json "$system_installable" | jq --raw-output ".[0].path")
 print >&2 "$nixos_config_path"
 
+if [[ -z "$nixos_config_path" ]]
+then
+  print_error "No path was generated"
+  exit 3
+fi
+
 
 print_info "Deploying target system configuration"
 if [[ "$is_target_host" || "$operation" = "build" ]]
diff --git a/configuration.nix b/configuration.nix
index 082d7a4..a062d8c 100644
--- a/configuration.nix
+++ b/configuration.nix
@@ -2,6 +2,7 @@
 { name, path, channel, isIso, extraLayersDir, flakeInputs, flakeOutputs, system, extraOverlays }:
 { lib, config, pkgs, ... }:
 
+
 let
   installResult = builtins.fromJSON (builtins.readFile (path + "/install-result.json"));
   dotfilesConfig = import (path + "/dotfiles.nix");
@@ -68,6 +69,10 @@ in
   # Make nixpkgs path available inside of the configuration
   #_module.args.nixpkgsPath = channel;
 
+  # Let 'nixos-version --json' know about the Git revision
+  # of this flake.
+  system.configurationRevision = lib.mkIf (flakeInputs.self ? rev) flakeInputs.self.rev;
+
   environment.shellAliases = {
     # nixos-option won't run without a configuration. With an empty config it does not show configured values, but can at least be used to search options and show default values.
     nixos-option = "nixos-option -I nixos-config=${pkgs.writeText "empty-configuration.nix" "{...}:{}"}";
diff --git a/flake.lock b/flake.lock
new file mode 100644
index 0000000..bb11d79
--- /dev/null
+++ b/flake.lock
@@ -0,0 +1,121 @@
+{
+  "nodes": {
+    "homemanager": {
+      "inputs": {
+        "nixpkgs": [
+          "nixpkgs"
+        ]
+      },
+      "locked": {
+        "lastModified": 1617220862,
+        "narHash": "sha256-nLka+S6Vww8hTF3ZkzK/BezvgAo1Z433/L6TR1SiXyM=",
+        "owner": "nix-community",
+        "repo": "home-manager",
+        "rev": "ad04237d5142f53dcba258942b78e2d2bbf210c8",
+        "type": "github"
+      },
+      "original": {
+        "owner": "nix-community",
+        "repo": "home-manager",
+        "type": "github"
+      }
+    },
+    "nixpkgs": {
+      "locked": {
+        "lastModified": 1617082367,
+        "narHash": "sha256-W0cQPGjc4IVzryaGycuoS8KZkXafS1P23w/fcKLoD5Y=",
+        "owner": "nixos",
+        "repo": "nixpkgs",
+        "rev": "04a2b269d8921505a2969fc9ec25c1f517f2b307",
+        "type": "github"
+      },
+      "original": {
+        "owner": "nixos",
+        "ref": "nixos-unstable",
+        "repo": "nixpkgs",
+        "type": "github"
+      }
+    },
+    "q": {
+      "inputs": {
+        "nixpkgs": [
+          "qd",
+          "nixpkgs"
+        ],
+        "qd": [
+          "qd"
+        ]
+      },
+      "locked": {
+        "host": "git.c3pb.de",
+        "lastModified": 1614196923,
+        "narHash": "sha256-Yjnd3hSW1XpZ9BQJCUeC0ES3KrWe6kubh22wkxEp9xE=",
+        "owner": "jens",
+        "repo": "q",
+        "rev": "1002c6c644bb377a22a8ac5a8ac9e54bcb055874",
+        "type": "gitlab"
+      },
+      "original": {
+        "host": "git.c3pb.de",
+        "owner": "jens",
+        "repo": "q",
+        "type": "gitlab"
+      }
+    },
+    "qauth": {
+      "inputs": {
+        "nixpkgs": [
+          "nixpkgs"
+        ]
+      },
+      "locked": {
+        "host": "git.c3pb.de",
+        "lastModified": 1611110209,
+        "narHash": "sha256-PGJWsILu0NO8ERv8+fgKFf6idkDuZgFlJGtGWdJsV8A=",
+        "owner": "jens",
+        "repo": "qauth",
+        "rev": "72d18c270a256434c18b1fadd68755413dd8fdb6",
+        "type": "gitlab"
+      },
+      "original": {
+        "host": "git.c3pb.de",
+        "owner": "jens",
+        "repo": "qauth",
+        "type": "gitlab"
+      }
+    },
+    "qd": {
+      "inputs": {
+        "nixpkgs": [
+          "nixpkgs"
+        ]
+      },
+      "locked": {
+        "host": "git.c3pb.de",
+        "lastModified": 1615431166,
+        "narHash": "sha256-ZwR9s18dGMrPJ+SLFOTL2BCsd4eZ6dd86v+Z7M2LSZc=",
+        "owner": "jens",
+        "repo": "qd",
+        "rev": "49571704277e7f59712622dc2c87ee18b226da31",
+        "type": "gitlab"
+      },
+      "original": {
+        "host": "git.c3pb.de",
+        "owner": "jens",
+        "repo": "qd",
+        "type": "gitlab"
+      }
+    },
+    "root": {
+      "inputs": {
+        "homemanager": "homemanager",
+        "nixpkgs": "nixpkgs",
+        "q": "q",
+        "qauth": "qauth",
+        "qd": "qd"
+      }
+    }
+  },
+  "root": "root",
+  "version": 7
+}
diff --git a/flake.nix b/flake.nix
index 49eebc8..a939c06 100644
--- a/flake.nix
+++ b/flake.nix
@@ -1,20 +1,31 @@
 {
   inputs = {
     nixpkgs.url = github:nixos/nixpkgs/nixos-unstable;
-    #homemanager = {
-    #  url = github:nix-community/home-manager;
-    #  inputs.nixpkgs.follows = "nixpkgs";
-    #};
-    #qauth = {
-    #  url = gitlab:jens/qauth?host=git.c3pb.de;
-    #  inputs.nixpkgs.follows = "nixpkgs";
-    #};
+
+    homemanager = {
+      url = github:nix-community/home-manager;
+      inputs.nixpkgs.follows = "nixpkgs";
+    };
+    qauth = {
+      url = gitlab:jens/qauth?host=git.c3pb.de;
+      inputs.nixpkgs.follows = "nixpkgs";
+    };
+    qd = {
+      url = gitlab:jens/qd?host=git.c3pb.de;
+      inputs.nixpkgs.follows = "nixpkgs";
+    };
+    q = {
+      url = gitlab:jens/q?host=git.c3pb.de;
+      inputs.qd.follows = "qd";
+      inputs.nixpkgs.follows = "qd/nixpkgs";
+    };
   };
-  outputs = { ... }: {
-    overlay = import ./pkgs;
 
-    nixosModules = {
-      greetd = import ./modules/greetd.nix;
+  outputs = inputs_@{ self, nixpkgs, ... }: {
+    machine-manager = (import ./machine-manager.nix) {
+      flakeInputs = inputs_;
+      flakeOutputs = self;
     };
+    overlay = import ./pkgs;
   };
 }
diff --git a/machine-manager.nix b/machine-manager.nix
index 431b901..aac55fa 100644
--- a/machine-manager.nix
+++ b/machine-manager.nix
@@ -1,11 +1,13 @@
-# entry point for machine configurations:
-# (import <repo-path> { machinesDir=./machines }).<netname>.configurations.<hostname>
-
-{ flakeInputs, flakeOutputs, machinesDir, extraLayersDir, extraOverlays ? [] }:
+# applied by this repositories flake
+{ flakeInputs, flakeOutputs }:
+# applied by outer flake
+{ extraFlakeInputs, extraFlakeOutputs, machinesDir, extraLayersDir, extraOverlays ? [] }:
 
 with builtins;
 with flakeInputs.nixpkgs.lib;
 let
+  finalFlakeInputs = flakeInputs // extraFlakeInputs;
+  finalFlakeOutputs = flakeOutputs // extraFlakeOutputs;
   # defaultChannel :: path (channel)
   #defaultChannel = loadChannel "nixos-unstable";
 
@@ -19,7 +21,7 @@ let
   # allChannels :: { *: path (channel) }
   #allChannels = with helpers; keysToAttrs loadChannel (readFilterDir (filterAnd [(not filterDirHidden) filterDirDirs]) channelsDir);
   # getMachineChannel :: string -> path
-  getMachineChannel = _: flakeInputs.nixpkgs;
+  getMachineChannel = _: finalFlakeInputs.nixpkgs;
   #getMachineChannel = { name, path }:
   #  let
   #    channelFile = path + "/channel.nix";
@@ -36,17 +38,19 @@ let
   evaluateConfig = pkgs: args: (import "${pkgs}/nixos/lib/eval-config.nix" args).config;
   mkNixosSystemDerivations = { name, path }:
     let
-      channel = flakeInputs.nixpkgs;
+      channel = finalFlakeInputs.nixpkgs;
       system = "x86_64-linux";
       mkMachineConfig = { name, path, isIso }: {
         imports = [
           (import ./configuration.nix {
-            inherit name path isIso extraLayersDir flakeInputs flakeOutputs system extraOverlays;
+            inherit name path isIso extraLayersDir system extraOverlays;
+            flakeInputs = finalFlakeInputs;
+            flakeOutputs = finalFlakeOutputs;
             channel = machineChannels.${name};
           })
         ];
-        _module.args.flakeInputs = flakeInputs;
-        _module.args.flakeOutputs = flakeOutputs;
+        _module.args.flakeInputs = finalFlakeInputs;
+        _module.args.flakeOutputs = finalFlakeOutputs;
         _module.args.system = system;
       };
       configuration = mkMachineConfig { inherit name path; isIso = false; };
-- 
GitLab