From 63d929c8e883c716b2388ff098118b9959a80d34 Mon Sep 17 00:00:00 2001 From: Jack O'Sullivan Date: Sun, 21 Jul 2024 12:37:32 +0100 Subject: [PATCH] nixos: Include mutable flake in every system --- nixos/default.nix | 2 +- nixos/modules/common.nix | 28 +++++++++++++++++++++++++++- nixos/modules/user.nix | 4 ++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/nixos/default.nix b/nixos/default.nix index 626eaa0..5f1a292 100644 --- a/nixos/default.nix +++ b/nixos/default.nix @@ -35,7 +35,7 @@ let system = null; # Put the inputs in specialArgs to avoid infinite recursion when modules try to do imports - specialArgs = { inherit inputs pkgsFlakes pkgsFlake allAssignments; inherit (cfg) systems; }; + specialArgs = { inherit self inputs pkgsFlakes pkgsFlake allAssignments; inherit (cfg) systems; }; # `baseModules` informs the manual which modules to document baseModules = diff --git a/nixos/modules/common.nix b/nixos/modules/common.nix index 50d8fb0..894e101 100644 --- a/nixos/modules/common.nix +++ b/nixos/modules/common.nix @@ -1,4 +1,4 @@ -{ lib, pkgsFlake, pkgs, pkgs', inputs, config, ... }: +{ lib, pkgsFlake, pkgs, pkgs', self, inputs, config, ... }: let inherit (lib) mkIf mkDefault mkMerge; inherit (lib.my) mkDefault'; @@ -127,6 +127,9 @@ in }; }; + environment.etc = { + "nixos/flake.nix".source = "/run/nixfiles/flake.nix"; + }; environment.systemPackages = with pkgs; mkMerge [ [ bash-completion @@ -209,6 +212,29 @@ in # python.d plugin script does #!/usr/bin/env bash path = with pkgs; [ bash ]; }; + + nixfiles-mutable = { + description = "Mutable nixfiles"; + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = true; + }; + + path = with pkgs; [ util-linux ]; + script = '' + nixfilesDir="${self}" + + mkdir -p /run/nixfiles{,/.rw,/.work} + mount -t overlay overlay -o lowerdir="$nixfilesDir",upperdir=/run/nixfiles/.rw,workdir=/run/nixfiles/.work /run/nixfiles + chmod -R u+w /run/nixfiles + ''; + preStop = '' + umount /run/nixfiles + rm -rf /run/nixfiles + ''; + + wantedBy = [ "multi-user.target" ]; + }; }; }; } diff --git a/nixos/modules/user.nix b/nixos/modules/user.nix index 5cc26b9..4c1d796 100644 --- a/nixos/modules/user.nix +++ b/nixos/modules/user.nix @@ -82,6 +82,10 @@ in # NOTE: As the "outermost" module is still being evaluated in NixOS land, special params (e.g. pkgs) won't be # passed to it home-manager.users.${user'.name} = mkAliasDefinitions options.my.user.homeConfig; + + systemd.services.nixfiles-mutable.script = '' + chown -R ${user'.name} /run/nixfiles + ''; } (mkIf (cfg.passwordSecret != null) { my = {