From 681ac0ab5d8ef47981e1cb21a5f9559c1f0afc4c Mon Sep 17 00:00:00 2001 From: Astro Date: Mon, 22 Mar 2021 23:47:19 +0100 Subject: [PATCH] move rootfs nixos-module to nix/pkgs --- flake.nix | 9 --------- nix/nixos-module/lxc-containers.nix | 11 +--------- nix/pkgs/default.nix | 31 +++++++++++++++++++---------- 3 files changed, 22 insertions(+), 29 deletions(-) diff --git a/flake.nix b/flake.nix index 6512ea7..a0872ff 100644 --- a/flake.nix +++ b/flake.nix @@ -43,14 +43,5 @@ builtins.elem role [ "server" "container" ] ) self.lib.config.site.hosts ); - - # nixosConfigurations.test_vm = - # nixpkgs.lib.nixosSystem { - # inherit system; - # modules = [ nixosModule ]; - # extraModules = [ ({ ... }: { - # networking.hostName = "test_vm"; - # }) ]; - # }; }; } diff --git a/nix/nixos-module/lxc-containers.nix b/nix/nixos-module/lxc-containers.nix index bb68c28..61ee2aa 100644 --- a/nix/nixos-module/lxc-containers.nix +++ b/nix/nixos-module/lxc-containers.nix @@ -16,15 +16,6 @@ let ); enabled = containers != {}; - mkRootfs = ctName: - pkgs.runCommandLocal "rootfs_${ctName}" { - src = self.nixosConfigurations.${ctName}.config.system.build.toplevel; - } '' - set -x - mkdir -p $out/{bin,dev,etc,home,mnt,nix/store,nix/var,proc,root,run,sys,tmp,var,usr} - ln -s $src/init $out/ - ln -s $src/etc $out/etc/static - ''; in { virtualisation.lxc = lib.mkIf enabled { @@ -42,7 +33,7 @@ in environment.etc = builtins.foldl' (etc: ctName: etc // { "lxc/containers/${ctName}/rootfs" = { - source = mkRootfs ctName; + source = self.packages.x86_64-linux."${ctName}-rootfs"; }; "lxc/containers/${ctName}/config" = { enable = true; diff --git a/nix/pkgs/default.nix b/nix/pkgs/default.nix index 29b8511..8b70915 100644 --- a/nix/pkgs/default.nix +++ b/nix/pkgs/default.nix @@ -23,20 +23,31 @@ let ) (builtins.attrNames config.site.hosts) ); - test_vm = nixpkgs.legacyPackages.${system}.runCommandLocal "test_vm" { - src = self.nixosConfigurations.test_vm.config.system.build.toplevel; - } '' - set -x - mkdir -p $out/{bin,dev,etc,home,mnt,nix/store,nix/var,proc,root,run,sys,tmp,var,usr} - ln -s $src/init $out/ - ln -s $src/etc $out/etc/static - ''; + mkRootfs = hostName: + nixpkgs.legacyPackages.${system}.runCommandLocal "rootfs_${hostName}" { + src = self.nixosConfigurations.${hostName}.config.system.build.toplevel; + } '' + set -x + mkdir -p $out/{bin,dev,etc,home,mnt,nix/store,nix/var,proc,root,run,sys,tmp,var,usr} + ln -s $src/init $out/ + ln -s $src/etc $out/etc/static + ''; + + rootfs = + builtins.foldl' (rootfs: hostName: rootfs // { + "${hostName}-rootfs" = mkRootfs hostName; + }) {} ( + builtins.attrNames ( + nixpkgs.lib.filterAttrs (_: { role, ... }: role == "container") + config.site.hosts + ) + ); device-templates = import ./device-templates.nix { inherit self nixpkgs system; }; in -salt-pillars // device-templates // { - inherit export-config test_vm; +salt-pillars // rootfs // device-templates // { + inherit export-config; }