Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 0 additions & 33 deletions .config/filegen-manifest.json

This file was deleted.

1 change: 0 additions & 1 deletion .gitattributes

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions nix/general/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ importingFlake: {
config.perSystem =
{ config, ... }:
lib.mkMerge [
{
filegen.settings.clobber-by-default = true;
githubActions.enable = true;
}
{ githubActions.enable = true; }

(lib.mkIf (config.githubActions.workflows != { }) {
filegen.settings.files = lib.mapAttrsToList (workflow: source: {
Expand Down
115 changes: 25 additions & 90 deletions nix/modules/filegen.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{ flake-parts-lib, lib, ... }:
let
inherit (lib) types;
smfh.version = 3;
in
{
options.perSystem = flake-parts-lib.mkPerSystemOption (
Expand All @@ -21,10 +20,6 @@ in
To generate the files, an "app" named `filegen-activate` is created,
which can be executed with `nix run .#filegen-activate`.

The configuration is as expected by
[smfh](https://github.com/feel-co/smfh), which is used
to perform the actual file manipulations.

---

Note: This module does *not* attempt to protect against writes to or
Expand All @@ -50,13 +45,7 @@ in
Normally, this should be set to `copy`.
'';

type = types.enum [
"copy"
"symlink"
"modify"
"directory"
"delete"
];
type = types.enum [ "copy" ];
};

target = lib.mkOption {
Expand All @@ -80,21 +69,8 @@ in

clobber = lib.mkOption {
description = ''
Whether to overwrite files that already exist.
'';
type = types.nullOr types.bool;
};

ignore-modification = lib.mkOption {
description = ''
Whether to skip content integrity checks during activation.
'';
type = types.nullOr types.bool;
};

deactivate = lib.mkOption {
description = ''
If enabled, `filegen-deactivate` will ignore this file.
Whether to backup files that already exist. If true or unset, the files
will just be deleted.
'';
type = types.nullOr types.bool;
};
Expand All @@ -115,51 +91,19 @@ in
# default.
default = "600";
};

# Not implemented:
#
# - permissions/uid/gid, as these should not matter for a
# project repo.
# - follow_symlinks, since for a git repo we should never
# want to symlink to absolute paths.
};
}
)
);
};

clobber-by-default = lib.mkOption {
description = ''
Whether files should be overwritten by default.
'';
type = types.nullOr types.bool;
};
};

smfhPackage = lib.mkOption {
scripts.activate = lib.mkOption {
description = ''
The smfh package to use.
A script that applies the files configured with `filegen.files`.
'';
default = pkgs.smfh;
type = types.package;
};

scripts = {
activate = lib.mkOption {
description = ''
A script that applies the files configured with `filegen.files`.
'';
readOnly = true;
type = types.pathInStore;
};

deactivate = lib.mkOption {
description = ''
A script that removes configured by a previous invocation of the activate script.
'';
readOnly = true;
type = types.pathInStore;
};
readOnly = true;
type = types.pathInStore;
};
};
}
Expand All @@ -169,9 +113,7 @@ in
{ pkgs, config, ... }:
let
cfg = config.filegen;
new-manifest = pkgs.writers.writeJSON "filegen-manifest.json" (
config.filegen.settings // { inherit (smfh) version; }
);
new-manifest = pkgs.writers.writeJSON "filegen-manifest.json" config.filegen.settings;
in
{
filegen.settings.files = [
Expand All @@ -185,7 +127,7 @@ in
target = ".gitattributes";
source = pkgs.writeTextFile {
name = ".gitattributes";
text = lib.pipe (cfg.settings.files ++ [ { target = ".config/filegen-manifest.json"; } ]) [
text = lib.pipe cfg.settings.files [
(map (file: lib.removePrefix "./" file.target))
(map (target: "${target} linguist-generated"))
lib.concatLines
Expand All @@ -198,21 +140,22 @@ in
activate = pkgs.writers.writeNuBin "filegen-apply-script" ''
cd (git rev-parse --show-toplevel)

(${lib.getExe cfg.smfhPackage}
--impure
diff
--fallback
${new-manifest}
.config/filegen-manifest.json)

mkdir .config
cp --preserve [] ${new-manifest} .config/filegen-manifest.json
chmod 600 .config/filegen-manifest.json
'';

deactivate = pkgs.writers.writeNuBin "filegen-deactivate-script" ''
cd (git rev-parse --show-toplevel)
${lib.getExe cfg.smfhPackage} deactivate .config/filegen-manifest.json
for file in (open '${new-manifest}' | $in.files) {
match $file.type {
"copy" => {
(${lib.getExe' pkgs.coreutils "install"}
-D
--compare
$'--mode=($file.permissions)'
(if ($file.clobber | default true) { --backup=none } else { --backup=numbered })
$file.source $file.target)
Comment thread
tlater-famedly marked this conversation as resolved.
},
_ => {
print $"Type '($file.type)' for '($file.source)' is currently unsupported"
exit 1
}
}
}
'';
in
{
Expand All @@ -223,14 +166,6 @@ in
package = activate;
};
};

filegen-deactivate = {
program = lib.getExe deactivate;
meta = {
description = "Uninstall all files previously installed using `filegen-activate`";
package = deactivate;
};
};
};
};
}