Skip to content

Commit

Permalink
Build fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rsdy committed Dec 11, 2023
1 parent 2e30869 commit afb3d75
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 84 deletions.
11 changes: 8 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@
src = pkgs.lib.sources.cleanSource ./.;
filter = name: type:
let baseName = baseNameOf (toString name);
in !(".github" == baseName || ("nix" == baseName && type == "directory"));
in !(".github" == baseName
|| ("nix" == baseName && type == "directory"));
};

cargoLock = { lockFile = ./Cargo.lock; };
cargoLock = {
lockFile = ./Cargo.lock;
outputHashes = { "infinitree-0.10.4" = "sha256-3mAU4aQgC9RK9aQR9oGfBpycF4dOJogiAKr+6IpHiKM="; };
};

buildFeatures = features;
cargoCheckFeatures = features;
Expand All @@ -62,7 +66,8 @@
++ pkgs.lib.optionals pkgs.stdenv.isDarwin (macDeps pkgs);
buildInputs = with pkgs;
[ libusb ]
++ pkgs.lib.optionals pkgs.stdenv.isLinux (linuxDeps pkgs);
++ pkgs.lib.optionals pkgs.stdenv.isLinux (linuxDeps pkgs)
++ pkgs.lib.optionals pkgs.stdenv.isDarwin (macDeps pkgs);
} // pkgs.lib.optionalAttrs pkgs.stdenv.isLinux {
RUSTFLAGS =
"-L${pkgs.stdenv.cc.cc}/lib/gcc/${pkgs.stdenv.targetPlatform.config}/${pkgs.stdenv.cc.cc.version} -lc";
Expand Down
12 changes: 4 additions & 8 deletions nix/nixos-test.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@
pkgs.nixosTest ({ ... }: {
name = "zerostash";
nodes = {
zerostash = { ... }:
{
imports = [
nixosModule
./test-nixos-configuration.nix
];
virtualisation.graphics = false;
};
zerostash = { ... }: {
imports = [ nixosModule ./test-nixos-configuration.nix ];
virtualisation.graphics = false;
};
};

testScript = ''
Expand Down
3 changes: 1 addition & 2 deletions nix/test-nixos-configuration.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{ lib, pkgs, ... }:
{
{ lib, pkgs, ... }: {
# Easy debugging via console and ssh
# WARNING: root access with empty password
networking.firewall.enable = false;
Expand Down
124 changes: 57 additions & 67 deletions nix/zerostash-nixos-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ let
cfg = config.services.zerostash;

inherit (utils.systemdUtils.unitOptions) unitOption;
in
with lib; {
in with lib; {
options.services.zerostash = {
enable = mkEnableOption "Zerostash automated backups";
configFile = mkOption {
Expand All @@ -23,9 +22,9 @@ with lib; {
description = "zerostash package to use.";
};

backups =
mkOption {
type = with types; attrsOf (submodule ({ ... }: {
backups = mkOption {
type = with types;
attrsOf (submodule ({ ... }: {
options = {
paths = mkOption {
type = with types; listOf path;
Expand All @@ -48,9 +47,7 @@ with lib; {

timerConfig = mkOption {
type = types.attrsOf unitOption;
default = {
OnCalendar = "daily";
};
default = { OnCalendar = "daily"; };
description = ''
Each attribute in this set specifies an option in the
<literal>[Timer]</literal> section of the unit. See
Expand Down Expand Up @@ -110,71 +107,64 @@ with lib; {
};
}));

default = { };
example =
{
daily_root_backup = {
paths = [ "/" ];
options = [ "-x" ];
timerConfig = {
OnCalendar = "daily";
};
environmentFile = "/path/to/env/file";
stash = {
key = {
source = "file";
path = "/path/to/keyfile.toml";
};
backend = {
type = "s3";
bucket = "test_bucket";
region = { name = "us-east-1"; };
};
};
default = { };
example = {
daily_root_backup = {
paths = [ "/" ];
options = [ "-x" ];
timerConfig = { OnCalendar = "daily"; };
environmentFile = "/path/to/env/file";
stash = {
key = {
source = "file";
path = "/path/to/keyfile.toml";
};
backend = {
type = "s3";
bucket = "test_bucket";
region = { name = "us-east-1"; };
};
};
description = "Declarative backup configuration.";
};
};
description = "Declarative backup configuration.";
};
};
config = mkIf cfg.enable {
systemd.services =
mapAttrs'
(name: backup:
let
json = cfg: pkgs.writeText "config.json" (builtins.toJSON cfg);
toml = name: cfg: pkgs.runCommand name { } "${pkgs.remarshal}/bin/remarshal --of toml ${json cfg} > $out";
systemd.services = mapAttrs' (name: backup:
let
json = cfg: pkgs.writeText "config.json" (builtins.toJSON cfg);
toml = name: cfg:
pkgs.runCommand name { }
"${pkgs.remarshal}/bin/remarshal --of toml ${json cfg} > $out";

configFile =
if (backup.stashName != null && cfg.configFile != null) then cfg.configFile else
toml "${name}.toml" {
stash."${name}" = backup.stash;
};
options = concatStringsSep " " backup.options;
paths = concatStringsSep " " backup.paths;
command = "${cfg.package}/bin/0s --insecure-config -c ${configFile} commit ${options} ${name} ${paths}";
in
nameValuePair "zerostash-${name}" ({
restartIfChanged = false;
serviceConfig = {
Type = "oneshot";
ExecStart = command;
User = backup.user;
RuntimeDirectory = "zerostash-${name}";
CacheDirectory = "zerostash-${name}";
CacheDirectoryMode = "0700";
} // optionalAttrs (backup.environmentFile != null) {
EnvironmentFile = backup.environmentFile;
};
})
)
config.services.zerostash.backups;
configFile =
if (backup.stashName != null && cfg.configFile != null) then
cfg.configFile
else
toml "${name}.toml" { stash."${name}" = backup.stash; };
options = concatStringsSep " " backup.options;
paths = concatStringsSep " " backup.paths;
command =
"${cfg.package}/bin/0s --insecure-config -c ${configFile} commit ${options} ${name} ${paths}";
in nameValuePair "zerostash-${name}" ({
restartIfChanged = false;
serviceConfig = {
Type = "oneshot";
ExecStart = command;
User = backup.user;
RuntimeDirectory = "zerostash-${name}";
CacheDirectory = "zerostash-${name}";
CacheDirectoryMode = "0700";
} // optionalAttrs (backup.environmentFile != null) {
EnvironmentFile = backup.environmentFile;
};
})) config.services.zerostash.backups;

systemd.timers =
mapAttrs'
(name: backup: nameValuePair "zerostash-${name}" {
wantedBy = [ "timers.target" ];
timerConfig = backup.timerConfig;
})
config.services.zerostash.backups;
systemd.timers = mapAttrs' (name: backup:
nameValuePair "zerostash-${name}" {
wantedBy = [ "timers.target" ];
timerConfig = backup.timerConfig;
}) config.services.zerostash.backups;
};
}
8 changes: 4 additions & 4 deletions zerostash-files/src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ mod test {
UsernamePassword::with_credentials("bare_index_map".to_string(), "password".to_string())
.unwrap()
};
let storage = crate::backends::test::InMemoryBackend::shared();
let storage = infinitree::backends::test::InMemoryBackend::shared();
let file_path = "test/path/file.rs".to_string();
let random_file = "test/path/to/random.rs".to_string();
let new_file_path = "test/path/to/file.rs".to_string();
Expand Down Expand Up @@ -678,7 +678,7 @@ mod test {
UsernamePassword::with_credentials("bare_index_map".to_string(), "password".to_string())
.unwrap()
};
let storage = crate::backends::test::InMemoryBackend::shared();
let storage = infinitree::backends::test::InMemoryBackend::shared();
let file_path = "test/path/file.rs".to_string();
let entry = Entry {
name: String::from("file.rs"),
Expand Down Expand Up @@ -739,7 +739,7 @@ mod test {
UsernamePassword::with_credentials("bare_index_map".to_string(), "password".to_string())
.unwrap()
};
let storage = crate::backends::test::InMemoryBackend::shared();
let storage = infinitree::backends::test::InMemoryBackend::shared();

let file1 = "file1.rs".to_string();
let file2 = "file2.rs".to_string();
Expand Down Expand Up @@ -803,7 +803,7 @@ mod test {
UsernamePassword::with_credentials("bare_index_map".to_string(), "password".to_string())
.unwrap()
};
let storage = crate::backends::test::InMemoryBackend::shared();
let storage = infinitree::backends::test::InMemoryBackend::shared();
let file1 = "test/path/to/file.rs".to_string();
let file2 = "test/path/file.rs".to_string();
let file3 = "test/file.rs".to_string();
Expand Down

0 comments on commit afb3d75

Please sign in to comment.