Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"need" a file, but don't create its parent directory? #805

Open
saurabhnanda opened this issue Jun 9, 2021 · 2 comments
Open

"need" a file, but don't create its parent directory? #805

saurabhnanda opened this issue Jun 9, 2021 · 2 comments

Comments

@saurabhnanda
Copy link

If I say, need [ "a/b/c/d/foo"] does shake automatically create a/b/c/d/ directory? Is there any way to turn this behaviour off on a case-by-case basis?

Use-cases:

  1. I want to make sure that a user has been created on a system, and I'm using /home/<username>/.bashrc as a target file for this action. However, because shake seems to be automatically creating /home/<username> the useradd command refuses to initialize the user's home-dir and the .bashrc file doesn't get automatically created.
  2. I want to make sure that /usr/share/elasticsearch/bin/elasticsearch is available on a system. If not, it is "produced" by sudo dpkg -i elasticsearch.deb command. However, before this command can be run, shake tries to create /usr/share/elasticsearch/bin and runs into permission errors.
@ndmitchell
Copy link
Owner

It's not the need that automatically creates the file, but the rule itself, so when you give a rule for producing a/b/c/d/foo, that rule, before it runs any of the user-supplied code, will first create the containing directory. There is no way to turn that off. One way to deal with these things specially would be to use oracles or similar, so define an oracle rule for creating a user, and then have that do what you need. Also, generally Shake should be creating things in a defined output directory, so not sure it messing around in /home or /usr/share is going to be a good plan - although I don't think anything will actually go wrong because of that.

newtype User = User String deriving (Show,Typeable,Eq,Hashable,Binary,NFData)
type instance RuleResult User = (
rules = do
    addOracle $ \(User x) -> do
        cmd "adduser" x

If you really want to track the .bashrc in the users home directory, so that it will rerun if the user edits it, you can add the need inside the addOracle after the execution of adduser, which will ensure it always gets run first.

@saurabhnanda
Copy link
Author

Also, generally Shake should be creating things in a defined output directory, so not sure it messing around in /home or /usr/share is going to be a good plan - although I don't think anything will actually go wrong because of that.

I'm experimenting with using Shake as a replacement for server provisioning tools to consolidate the number of tools required in a large-ish project. Bad idea?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants