2023-07-15 16:52:46 +04:00
|
|
|
{
|
2023-11-06 11:40:32 +04:00
|
|
|
description = "SelfPrivacy NixOS configuration flake";
|
2023-07-15 16:52:46 +04:00
|
|
|
|
|
|
|
inputs = {
|
2023-11-21 01:24:32 +04:00
|
|
|
nixpkgs.url = github:nixos/nixpkgs;
|
2023-11-06 12:18:08 +04:00
|
|
|
|
2023-11-16 06:31:31 +04:00
|
|
|
selfprivacy-api.url =
|
2023-11-21 01:24:32 +04:00
|
|
|
git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git;
|
2023-11-16 06:31:31 +04:00
|
|
|
# make selfprivacy-api use the same shared nixpkgs
|
|
|
|
selfprivacy-api.inputs.nixpkgs.follows = "nixpkgs";
|
2023-07-15 16:52:46 +04:00
|
|
|
};
|
|
|
|
|
2023-11-16 06:31:31 +04:00
|
|
|
outputs = { self, nixpkgs, selfprivacy-api }: {
|
2023-11-10 07:10:06 +04:00
|
|
|
nixosConfigurations-fun =
|
2023-12-05 07:36:26 +04:00
|
|
|
{ hardware-configuration
|
2023-12-05 04:41:35 +04:00
|
|
|
, deployment
|
2023-11-10 07:10:06 +04:00
|
|
|
, userdata
|
|
|
|
, top-level-flake
|
|
|
|
, sp-modules
|
|
|
|
}:
|
|
|
|
{
|
2023-12-27 14:02:27 +04:00
|
|
|
default = nixpkgs.lib.nixosSystem {
|
2023-11-10 07:10:06 +04:00
|
|
|
modules = [
|
|
|
|
hardware-configuration
|
2023-12-05 04:41:35 +04:00
|
|
|
deployment
|
2023-11-10 07:10:06 +04:00
|
|
|
./configuration.nix
|
2023-11-16 06:31:31 +04:00
|
|
|
selfprivacy-api.nixosModules.default
|
2023-11-10 07:10:06 +04:00
|
|
|
{
|
2023-12-12 08:25:06 +04:00
|
|
|
# pass userdata (parsed from JSON) options to selfprivacy module
|
|
|
|
selfprivacy = userdata;
|
2023-12-16 09:39:22 +04:00
|
|
|
|
2023-11-10 07:10:06 +04:00
|
|
|
# embed top-level flake source folder into the build
|
2023-11-21 01:24:32 +04:00
|
|
|
environment.etc."selfprivacy/nixos-config-source".source =
|
2023-12-16 09:39:22 +04:00
|
|
|
top-level-flake;
|
|
|
|
|
2023-11-10 07:10:06 +04:00
|
|
|
# for running "nix search nixpkgs", etc
|
|
|
|
nix.registry.nixpkgs.flake = nixpkgs;
|
2023-12-16 09:39:22 +04:00
|
|
|
|
2023-11-14 05:23:10 +04:00
|
|
|
# embed commit sha1 for `nixos-version --configuration-revision`
|
|
|
|
system.configurationRevision = self.rev
|
|
|
|
or "@${self.lastModifiedDate}"; # for development
|
|
|
|
# TODO assertion to forbid dirty builds caused by top-level-flake
|
2023-12-16 09:39:22 +04:00
|
|
|
|
|
|
|
# reset contents of /etc/nixos to match running NixOS generation
|
|
|
|
system.activationScripts.selfprivacy-nixos-config-source = ''
|
|
|
|
rm -rf /etc/nixos/{*,.[!.]*}
|
|
|
|
cp -r --no-preserve=all ${top-level-flake}/ -T /etc/nixos/
|
|
|
|
'';
|
2023-11-10 07:10:06 +04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
++
|
2023-11-15 04:15:50 +04:00
|
|
|
# add SP modules, but contrain available config attributes for each
|
|
|
|
# (TODO revise evaluation performance of the code below)
|
2023-12-01 08:32:31 +04:00
|
|
|
nixpkgs.lib.attrsets.mapAttrsToList
|
|
|
|
(name: sp-module: args@{ config, pkgs, ... }:
|
2023-11-15 04:15:50 +04:00
|
|
|
let
|
|
|
|
lib = nixpkgs.lib;
|
2023-12-01 08:32:31 +04:00
|
|
|
configPathsNeeded = sp-module.configPathsNeeded or
|
|
|
|
(abort "allowed config paths not set for module \"${name}\"");
|
2023-11-15 04:15:50 +04:00
|
|
|
constrainConfigArgs = args'@{ pkgs, ... }: args' // {
|
|
|
|
config =
|
|
|
|
# TODO use lib.attrsets.mergeAttrsList from nixpkgs 23.05
|
|
|
|
(builtins.foldl' lib.attrsets.recursiveUpdate { }
|
|
|
|
(map
|
|
|
|
(p: lib.attrsets.setAttrByPath p
|
|
|
|
(lib.attrsets.getAttrFromPath p config))
|
2023-12-01 08:32:31 +04:00
|
|
|
configPathsNeeded
|
|
|
|
)
|
|
|
|
);
|
2023-11-15 04:15:50 +04:00
|
|
|
};
|
|
|
|
constrainImportsArgsRecursive = lib.attrsets.mapAttrsRecursive
|
|
|
|
(p: v:
|
2023-11-15 20:18:45 +04:00
|
|
|
# TODO traverse only imports and imports of imports, etc
|
|
|
|
# without traversing all attributes
|
2023-11-15 04:15:50 +04:00
|
|
|
if lib.lists.last p == "imports"
|
|
|
|
then
|
|
|
|
map
|
|
|
|
(m:
|
|
|
|
(args'@{ pkgs, ... }: constrainImportsArgsRecursive
|
|
|
|
(if builtins.isPath m
|
|
|
|
then import m (constrainConfigArgs args')
|
|
|
|
else
|
|
|
|
if builtins.isFunction m
|
2023-11-26 08:56:48 +04:00
|
|
|
then m (constrainConfigArgs args')
|
2023-11-15 04:15:50 +04:00
|
|
|
else m))
|
|
|
|
)
|
|
|
|
v
|
|
|
|
else v);
|
|
|
|
in
|
|
|
|
constrainImportsArgsRecursive
|
|
|
|
(sp-module.nixosModules.default (constrainConfigArgs args))
|
2023-11-10 07:10:06 +04:00
|
|
|
)
|
2023-12-01 08:32:31 +04:00
|
|
|
sp-modules;
|
2023-07-15 16:52:46 +04:00
|
|
|
};
|
2023-11-10 07:10:06 +04:00
|
|
|
};
|
2023-11-14 02:47:01 +04:00
|
|
|
formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixpkgs-fmt;
|
2023-11-10 07:10:06 +04:00
|
|
|
};
|
2023-07-15 16:52:46 +04:00
|
|
|
}
|