2023-07-15 12:52:46 +00:00
|
|
|
{
|
2023-11-06 07:40:32 +00:00
|
|
|
description = "SelfPrivacy NixOS configuration flake";
|
2023-07-15 12:52:46 +00:00
|
|
|
|
|
|
|
inputs = {
|
2023-11-20 21:24:32 +00:00
|
|
|
nixpkgs.url = github:nixos/nixpkgs;
|
2023-11-06 08:18:08 +00:00
|
|
|
|
2023-11-16 02:31:31 +00:00
|
|
|
selfprivacy-api.url =
|
2023-11-20 21:24:32 +00:00
|
|
|
git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git;
|
2023-11-16 02:31:31 +00:00
|
|
|
# make selfprivacy-api use the same shared nixpkgs
|
|
|
|
selfprivacy-api.inputs.nixpkgs.follows = "nixpkgs";
|
2023-07-15 12:52:46 +00:00
|
|
|
};
|
|
|
|
|
2023-11-16 02:31:31 +00:00
|
|
|
outputs = { self, nixpkgs, selfprivacy-api }: {
|
2023-11-10 03:10:06 +00:00
|
|
|
nixosConfigurations-fun =
|
2023-12-05 03:36:26 +00:00
|
|
|
{ hardware-configuration
|
2023-12-05 00:41:35 +00:00
|
|
|
, deployment
|
2023-11-10 03:10:06 +00:00
|
|
|
, userdata
|
|
|
|
, top-level-flake
|
|
|
|
, sp-modules
|
|
|
|
}:
|
|
|
|
{
|
2023-11-13 22:47:01 +00:00
|
|
|
sp-nixos = nixpkgs.lib.nixosSystem {
|
2023-11-10 03:10:06 +00:00
|
|
|
modules = [
|
|
|
|
hardware-configuration
|
2023-12-05 00:41:35 +00:00
|
|
|
deployment
|
2023-11-10 03:10:06 +00:00
|
|
|
./configuration.nix
|
2023-11-16 02:31:31 +00:00
|
|
|
selfprivacy-api.nixosModules.default
|
2023-11-10 03:10:06 +00:00
|
|
|
{
|
2023-12-12 04:25:06 +00:00
|
|
|
# pass userdata (parsed from JSON) options to selfprivacy module
|
|
|
|
selfprivacy = userdata;
|
2023-12-16 05:39:22 +00:00
|
|
|
|
2023-11-10 03:10:06 +00:00
|
|
|
# embed top-level flake source folder into the build
|
2023-11-20 21:24:32 +00:00
|
|
|
environment.etc."selfprivacy/nixos-config-source".source =
|
2023-12-16 05:39:22 +00:00
|
|
|
top-level-flake;
|
|
|
|
|
2023-11-10 03:10:06 +00:00
|
|
|
# for running "nix search nixpkgs", etc
|
|
|
|
nix.registry.nixpkgs.flake = nixpkgs;
|
2023-12-16 05:39:22 +00:00
|
|
|
|
2023-11-14 01:23:10 +00: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 05:39:22 +00: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 03:10:06 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
++
|
2023-11-15 00:15:50 +00:00
|
|
|
# add SP modules, but contrain available config attributes for each
|
|
|
|
# (TODO revise evaluation performance of the code below)
|
2023-12-01 04:32:31 +00:00
|
|
|
nixpkgs.lib.attrsets.mapAttrsToList
|
|
|
|
(name: sp-module: args@{ config, pkgs, ... }:
|
2023-11-15 00:15:50 +00:00
|
|
|
let
|
|
|
|
lib = nixpkgs.lib;
|
2023-12-01 04:32:31 +00:00
|
|
|
configPathsNeeded = sp-module.configPathsNeeded or
|
|
|
|
(abort "allowed config paths not set for module \"${name}\"");
|
2023-11-15 00:15:50 +00: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 04:32:31 +00:00
|
|
|
configPathsNeeded
|
|
|
|
)
|
|
|
|
);
|
2023-11-15 00:15:50 +00:00
|
|
|
};
|
|
|
|
constrainImportsArgsRecursive = lib.attrsets.mapAttrsRecursive
|
|
|
|
(p: v:
|
2023-11-15 16:18:45 +00:00
|
|
|
# TODO traverse only imports and imports of imports, etc
|
|
|
|
# without traversing all attributes
|
2023-11-15 00:15:50 +00: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 04:56:48 +00:00
|
|
|
then m (constrainConfigArgs args')
|
2023-11-15 00:15:50 +00:00
|
|
|
else m))
|
|
|
|
)
|
|
|
|
v
|
|
|
|
else v);
|
|
|
|
in
|
|
|
|
constrainImportsArgsRecursive
|
|
|
|
(sp-module.nixosModules.default (constrainConfigArgs args))
|
2023-11-10 03:10:06 +00:00
|
|
|
)
|
2023-12-01 04:32:31 +00:00
|
|
|
sp-modules;
|
2023-07-15 12:52:46 +00:00
|
|
|
};
|
2023-11-10 03:10:06 +00:00
|
|
|
};
|
2023-11-13 22:47:01 +00:00
|
|
|
formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixpkgs-fmt;
|
2023-11-10 03:10:06 +00:00
|
|
|
};
|
2023-07-15 12:52:46 +00:00
|
|
|
}
|