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-07-17 00:58:26 +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-06 08:18:08 +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 =
|
|
|
|
{ system
|
|
|
|
, hardware-configuration
|
|
|
|
, 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
|
|
|
specialArgs = { inherit system; };
|
|
|
|
modules = [
|
|
|
|
hardware-configuration
|
|
|
|
./configuration.nix
|
|
|
|
(import ./userdata-variables.nix userdata)
|
2023-11-16 02:31:31 +00:00
|
|
|
selfprivacy-api.nixosModules.default
|
2023-11-10 03:10:06 +00:00
|
|
|
{
|
|
|
|
# embed top-level flake source folder into the build
|
2023-11-13 22:47:01 +00:00
|
|
|
environment.etc."selfprivacy/current-config-source".source =
|
2023-11-10 03:10:06 +00:00
|
|
|
top-level-flake.outPath;
|
|
|
|
# for running "nix search nixpkgs", etc
|
|
|
|
nix.registry.nixpkgs.flake = nixpkgs;
|
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-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-11-10 03:10:06 +00:00
|
|
|
map
|
2023-11-15 00:15:50 +00:00
|
|
|
(sp-module: args@{ config, pkgs, ... }:
|
|
|
|
let
|
|
|
|
lib = nixpkgs.lib;
|
|
|
|
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))
|
|
|
|
sp-module.configPathsNeeded));
|
|
|
|
};
|
|
|
|
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
|
|
|
|
then constrainConfigArgs args'
|
|
|
|
else m))
|
|
|
|
)
|
|
|
|
v
|
|
|
|
else v);
|
|
|
|
in
|
|
|
|
constrainImportsArgsRecursive
|
|
|
|
(sp-module.nixosModules.default (constrainConfigArgs args))
|
2023-11-10 03:10:06 +00:00
|
|
|
)
|
2023-11-15 00:15:50 +00:00
|
|
|
(nixpkgs.lib.attrsets.attrValues 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
|
|
|
}
|